Skip to content

Commit

Permalink
feat(pd)!: migrate to cometbft v0.37
Browse files Browse the repository at this point in the history
Bumps the rust imports for tendermint-rs and tower-abci to use the v037,
rather than v034, modules. The substantive change is the addition of two
new ABCI event types [0]:

  * PrepareProposal
  * ProcessProposal

This code as written compiles. Still to come:

* verify the logic actually conforms to spec
* refactor new consensus logic into self methods
* update docs/deployment to use new version

Refs #2263.

[0] https://github.com/tendermint/tendermint/blob/v0.37.x/spec/abci/abci%2B%2B_tmint_expected_behavior.md#adapting-existing-applications-that-use-abci
  • Loading branch information
conorsch committed Sep 28, 2023
1 parent b1ce102 commit 9e8f2f7
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 24 deletions.
25 changes: 24 additions & 1 deletion crates/bin/pd/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::Result;
use penumbra_chain::genesis;
use penumbra_storage::Storage;
use tendermint::abci::Event;
use tendermint::v0_34::abci::{
use tendermint::v0_37::abci::{
request, response, ConsensusRequest as Request, ConsensusResponse as Response,
};
use tokio::sync::mpsc;
Expand Down Expand Up @@ -81,6 +81,29 @@ impl Consensus {
.await
.expect("commit must succeed"),
),
// TODO: figure out how to handle these events, otherwise pd panics
Request::PrepareProposal(proposal) => {
tracing::warn!(?proposal, "Encountered PrepareProposal request");
let mut txs: Vec<bytes::Bytes> = Vec::new();
let num_candidate_txs = proposal.txs.len();
// Ensure that list of transactions doesn't exceed max tx bytes.
// https://github.com/tendermint/tendermint/blob/v0.37.x/spec/abci/abci%2B%2B_tmint_expected_behavior.md#adapting-existing-applications-that-use-abci
tracing::debug!("Processing PrepareProposal, found {} candidate transactions", proposal.txs.len());
for tx in proposal.txs {
if (tx.len() + txs.len()) <= proposal.max_tx_bytes.try_into()? {
txs.push(tx);
} else {
break
}
}
tracing::debug!("Finished processing PrepareProposal, including {}/{} candidate transactions",
txs.len(), num_candidate_txs);
Response::PrepareProposal(tendermint::abci::response::PrepareProposal { txs: txs })
},
Request::ProcessProposal(proposal) => {
tracing::warn!(?proposal, "Encountered ProcessProposal request");
Response::ProcessProposal(tendermint::abci::response::ProcessProposal::Accept)
}
}));
}
Ok(())
Expand Down
4 changes: 3 additions & 1 deletion crates/bin/pd/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::Result;
use futures::FutureExt;
use regex::RegexSet;
use tendermint::abci::Event;
use tendermint::v0_34::abci::{ConsensusRequest as Request, ConsensusResponse as Response};
use tendermint::v0_37::abci::{ConsensusRequest as Request, ConsensusResponse as Response};
use tower::{Layer, Service};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -102,6 +102,8 @@ where
// No events.
Response::InitChain(_) => {}
Response::Commit(_) => {}
Response::PrepareProposal(_) => {},
Response::ProcessProposal(_) => {},
// These responses have events.
Response::BeginBlock(ref mut msg) => config.adjust_events(&mut msg.events),
Response::DeliverTx(ref mut msg) => config.adjust_events(&mut msg.events),
Expand Down
5 changes: 2 additions & 3 deletions crates/bin/pd/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ use penumbra_ibc::component::ConnectionStateReadExt as _;
use penumbra_storage::Storage;
use prost::Message;
use std::str::FromStr;
use tendermint::v0_34::abci::{
use tendermint::v0_37::abci::{
request,
response::{self, Echo},
InfoRequest, InfoResponse,
};
use tower_abci::BoxError;
use tracing::Instrument;

use penumbra_tower_trace::v034::RequestExt;
use penumbra_tower_trace::v037::RequestExt;

const ABCI_INFO_VERSION: &str = env!("VERGEN_GIT_SEMVER");

Expand Down Expand Up @@ -609,7 +609,6 @@ impl tower_service::Service<InfoRequest> for Info {
InfoRequest::Echo(echo) => Ok(InfoResponse::Echo(Echo {
message: echo.message,
})),
InfoRequest::SetOption(_) => todo!(),
}
}
.instrument(span)
Expand Down
6 changes: 3 additions & 3 deletions crates/bin/pd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use tonic::transport::Server;
use tracing_subscriber::{prelude::*, EnvFilter};
use url::Url;

use penumbra_tower_trace::v034::RequestExt;
use tendermint::v0_34::abci::{ConsensusRequest, MempoolRequest};
use penumbra_tower_trace::v037::RequestExt;
use tendermint::v0_37::abci::{ConsensusRequest, MempoolRequest};

#[derive(Debug, Parser)]
#[clap(
Expand Down Expand Up @@ -318,7 +318,7 @@ async fn main() -> anyhow::Result<()> {
let abci_server = tokio::task::Builder::new()
.name("abci_server")
.spawn(
tower_abci::v034::Server::builder()
tower_abci::v037::Server::builder()
.consensus(consensus)
.snapshot(snapshot)
.mempool(mempool)
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/pd/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;

use penumbra_storage::{Snapshot, Storage};

use tendermint::v0_34::abci::{
use tendermint::v0_37::abci::{
request::CheckTx as CheckTxReq, request::CheckTxKind, response::CheckTx as CheckTxRsp,
MempoolRequest as Request, MempoolResponse as Response,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/pd/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use futures::FutureExt;
use tendermint::v0_34::abci::{SnapshotRequest, SnapshotResponse};
use tendermint::v0_37::abci::{SnapshotRequest, SnapshotResponse};
use tower_abci::BoxError;

#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/component/dex/src/component/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use penumbra_chain::component::StateReadExt as _;
use penumbra_component::Component;
use penumbra_proto::{StateReadProto, StateWriteProto};
use penumbra_storage::{StateRead, StateWrite};
use tendermint::v0_34::abci;
use tendermint::v0_37::abci;
use tracing::instrument;

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion crates/core/component/governance/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use anyhow::{Context, Result};
use async_trait::async_trait;
use penumbra_storage::StateWrite;
use tendermint::v0_34::abci;
use tendermint::v0_37::abci;
use tracing::instrument;

use penumbra_component::Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use penumbra_proto::StateReadProto;
use penumbra_sct::Nullifier;
use penumbra_storage::StateRead;
use penumbra_storage::StateWrite;
use tendermint::v0_34::abci;
use tendermint::v0_37::abci;
use tracing::instrument;

use crate::state_key;
Expand Down
6 changes: 3 additions & 3 deletions crates/narsil/narsil/src/bin/narsild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use console_subscriber::ConsoleLayer;
use metrics_tracing_context::{MetricsLayer, TracingContextLayer};
use metrics_util::layers::Stack;
use penumbra_tendermint_proxy::TendermintProxy;
use penumbra_tower_trace::v034::RequestExt;
use tendermint::v0_34::abci::{ConsensusRequest, MempoolRequest};
use penumbra_tower_trace::v037::RequestExt;
use tendermint::v0_37::abci::{ConsensusRequest, MempoolRequest};

use narsil::{
ledger::{consensus::Consensus, mempool::Mempool, snapshot::Snapshot, Info},
Expand Down Expand Up @@ -159,7 +159,7 @@ async fn main() -> anyhow::Result<()> {
let abci_server = tokio::task::Builder::new()
.name("abci_server")
.spawn(
tower_abci::v034::Server::builder()
tower_abci::v037::Server::builder()
.consensus(consensus)
.snapshot(snapshot)
.mempool(mempool)
Expand Down
6 changes: 5 additions & 1 deletion crates/narsil/narsil/src/ledger/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::Result;
use penumbra_chain::genesis;
use penumbra_storage::Storage;
use tendermint::abci::Event;
use tendermint::v0_34::abci::{
use tendermint::v0_37::abci::{
request, response, ConsensusRequest as Request, ConsensusResponse as Response,
};
use tokio::sync::mpsc;
Expand Down Expand Up @@ -81,6 +81,10 @@ impl Consensus {
.await
.expect("commit must succeed"),
),
// The proposal types were added in CometBFT v0.37.x.
// How should they be handled in narsil?
Request::PrepareProposal(_proposal) => todo!(),
Request::ProcessProposal(_proposal) => todo!(),
}));
}
Ok(())
Expand Down
5 changes: 2 additions & 3 deletions crates/narsil/narsil/src/ledger/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::{
use futures::FutureExt;
use penumbra_chain::component::{AppHashRead, StateReadExt};
use penumbra_storage::Storage;
use penumbra_tower_trace::v034::RequestExt;
use tendermint::v0_34::abci::{self, response::Echo, InfoRequest, InfoResponse};
use penumbra_tower_trace::v037::RequestExt;
use tendermint::v0_37::abci::{self, response::Echo, InfoRequest, InfoResponse};
use tower_abci::BoxError;
use tracing::Instrument;

Expand Down Expand Up @@ -78,7 +78,6 @@ impl tower_service::Service<InfoRequest> for Info {
InfoRequest::Echo(echo) => Ok(InfoResponse::Echo(Echo {
message: echo.message,
})),
InfoRequest::SetOption(_) => todo!(),
}
}
.instrument(span)
Expand Down
6 changes: 3 additions & 3 deletions crates/narsil/narsil/src/ledger/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use anyhow::Result;

use penumbra_storage::{Snapshot, Storage};

use tendermint::v0_34::abci::request::{CheckTx as CheckTxReq, CheckTxKind};
use tendermint::v0_34::abci::response::CheckTx as CheckTxRsp;
use tendermint::v0_34::abci::{MempoolRequest as Request, MempoolResponse as Response};
use tendermint::v0_37::abci::request::{CheckTx as CheckTxReq, CheckTxKind};
use tendermint::v0_37::abci::response::CheckTx as CheckTxRsp;
use tendermint::v0_37::abci::{MempoolRequest as Request, MempoolResponse as Response};

use tokio::sync::{mpsc, watch};
use tower_actor::Message;
Expand Down
2 changes: 1 addition & 1 deletion crates/narsil/narsil/src/ledger/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use futures::FutureExt;
use tendermint::v0_34::abci::{SnapshotRequest, SnapshotResponse};
use tendermint::v0_37::abci::{SnapshotRequest, SnapshotResponse};
use tower_abci::BoxError;

#[derive(Clone, Debug)]
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
3 changes: 3 additions & 0 deletions deployments/scripts/smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ TESTNET_RUNTIME="${TESTNET_RUNTIME:-120}"
# Duration that the network will run before integration tests are run.
TESTNET_BOOTTIME="${TESTNET_BOOTTIME:-20}"

echo "Building latest version of pd from source..."
cargo build --quiet --release --bin pd

echo "Generating testnet config..."
EPOCH_DURATION="${EPOCH_DURATION:-100}"
cargo run --quiet --release --bin pd -- testnet generate --epoch-duration "$EPOCH_DURATION" --timeout-commit 500ms
Expand Down
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
devnet:
# removing previous state for penumbra networks
rm -rf ~/.penumbra/testnet_data
# generate local devnet config
cargo run --release --bin pd -- testnet generate

0 comments on commit 9e8f2f7

Please sign in to comment.