Skip to content

Commit

Permalink
Use fee from builder
Browse files Browse the repository at this point in the history
  • Loading branch information
jbearer committed Apr 24, 2024
1 parent 270393c commit 6361845
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 241 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ ESPRESSO_STATE_RELAY_SERVER_URL=http://state-relay-server:${ESPRESSO_STATE_RELAY
# Ethereum accounts (note 11-15 are used by the sequencer nodes)
ESPRESSO_SEQUENCER_HOTSHOT_ACCOUNT_INDEX=5
ESPRESSO_SEQUENCER_STATE_PROVER_ACCOUNT_INDEX=7
ESPRESSO_BUILDER_ETH_ACCOUNT_INDEX=8
ESPRESSO_DEPLOYER_ACCOUNT_INDEX=9

# Contracts
Expand Down
2 changes: 0 additions & 2 deletions builder/src/bin/permissioned-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@ async fn main() -> anyhow::Result<()> {
let builder_key_pair = EthKeyPair::from_mnemonic(&opt.eth_mnemonic, opt.eth_account_index)?;

let builder_params = BuilderParams {
mnemonic: opt.eth_mnemonic,
prefunded_accounts: vec![],
eth_account_index: opt.eth_account_index,
};

// Parse supplied Libp2p addresses to their socket form
Expand Down
18 changes: 3 additions & 15 deletions builder/src/bin/permissionless-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use es_version::SEQUENCER_VERSION;
use hotshot_types::data::ViewNumber;
use hotshot_types::traits::node_implementation::ConsensusTime;
use sequencer::eth_signature_key::EthKeyPair;
use sequencer::{BuilderParams, L1Params};
use sequencer::L1Params;
use snafu::Snafu;
use std::num::NonZeroUsize;
use std::{str::FromStr, time::Duration};
Expand Down Expand Up @@ -101,24 +101,12 @@ async fn main() -> anyhow::Result<()> {
};

let builder_key_pair = EthKeyPair::from_mnemonic(&opt.eth_mnemonic, opt.eth_account_index)?;

let builder_params = BuilderParams {
mnemonic: opt.eth_mnemonic,
prefunded_accounts: vec![],
eth_account_index: opt.eth_account_index,
};

let bootstrapped_view = ViewNumber::new(opt.view_number);

let builder_server_url: Url = format!("http://0.0.0.0:{}", opt.port).parse().unwrap();

let instance_state = build_instance_state(
l1_params,
builder_params,
opt.state_peers,
sequencer_version,
)
.unwrap();
let instance_state =
build_instance_state(l1_params, opt.state_peers, sequencer_version).unwrap();

let api_response_timeout_duration = opt.max_api_timeout_duration;

Expand Down
25 changes: 0 additions & 25 deletions builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,9 @@ pub mod testing {
_pd: Default::default(),
};

let key = Self::builder_key(i);
tracing::info!("node {i} is builder {:x}", key.address());
let node_state = NodeState::new(
ChainConfig::default(),
L1Client::new(self.anvil.endpoint().parse().unwrap(), Address::default()),
key,
MockStateCatchup::default(),
)
.with_genesis(ValidatedState::default());
Expand All @@ -419,14 +416,6 @@ pub mod testing {
handle
}

pub fn builder_key(i: usize) -> EthKeyPair {
EthKeyPair::from_mnemonic(
"test test test test test test test test test test test junk",
i as u32,
)
.unwrap()
}

// url for the hotshot event streaming api
pub fn hotshot_event_streaming_api_url() -> Url {
// spawn the event streaming api
Expand Down Expand Up @@ -538,19 +527,12 @@ pub mod testing {
hotshot_builder_api_url: Url,
) -> Self {
// setup the instance state
let key = HotShotTestConfig::builder_key(Self::SUBSCRIBED_DA_NODE_ID);
tracing::info!(
"node {} is builder {:x}",
Self::SUBSCRIBED_DA_NODE_ID,
key.address()
);
let node_state = NodeState::new(
ChainConfig::default(),
L1Client::new(
hotshot_test_config.get_anvil().endpoint().parse().unwrap(),
Address::default(),
),
key,
MockStateCatchup::default(),
)
.with_genesis(ValidatedState::default());
Expand Down Expand Up @@ -604,19 +586,12 @@ pub mod testing {
hotshot_builder_api_url: Url,
) -> Self {
// setup the instance state
let key = HotShotTestConfig::builder_key(HotShotTestConfig::NUM_STAKED_NODES);
tracing::info!(
"node {} is builder {:x}",
HotShotTestConfig::NUM_STAKED_NODES,
key.address()
);
let node_state = NodeState::new(
ChainConfig::default(),
L1Client::new(
hotshot_test_config.get_anvil().endpoint().parse().unwrap(),
Address::default(),
),
key,
MockStateCatchup::default(),
)
.with_genesis(ValidatedState::default());
Expand Down
9 changes: 0 additions & 9 deletions builder/src/non_permissioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,13 @@ pub struct BuilderConfig {

pub fn build_instance_state<Ver: StaticVersionType + 'static>(
l1_params: L1Params,
builder_params: BuilderParams,
state_peers: Vec<Url>,
_: Ver,
) -> anyhow::Result<NodeState> {
// creating the instance state without any builder mnemonic
let builder_key =
EthKeyPair::from_mnemonic(&builder_params.mnemonic, builder_params.eth_account_index)?;

tracing::info!("Builder account address {:?}", builder_key.address());

let l1_client = L1Client::new(l1_params.url, Address::default());

let instance_state = NodeState::new(
ChainConfig::default(),
l1_client,
builder_key,
Arc::new(StatePeers::<Ver>::from_urls(state_peers)),
);
Ok(instance_state)
Expand Down
6 changes: 0 additions & 6 deletions builder/src/permissioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ pub async fn init_node<P: SequencerPersistence, Ver: StaticVersionType + 'static
// crash horribly just because we're not using the P2P network yet.
let _ = NetworkingMetricsValue::new(metrics);

// creating the instance state without any builder mnemonic
let builder_key =
EthKeyPair::from_mnemonic(&builder_params.mnemonic, builder_params.eth_account_index)?;
tracing::info!("Builder account address {:?}", builder_key.address());

let mut genesis_state = ValidatedState::default();
for address in builder_params.prefunded_accounts {
tracing::warn!("Prefunding account {:?} for demo", address);
Expand All @@ -256,7 +251,6 @@ pub async fn init_node<P: SequencerPersistence, Ver: StaticVersionType + 'static
let instance_state = NodeState::new(
ChainConfig::default(),
l1_client,
builder_key,
Arc::new(StatePeers::<Ver>::from_urls(network_params.state_peers)),
);

Expand Down
10 changes: 0 additions & 10 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ services:
- ESPRESSO_SEQUENCER_PRIVATE_STATE_KEY=$ESPRESSO_DEMO_SEQUENCER_STATE_PRIVATE_KEY_0
- ESPRESSO_SEQUENCER_LIBP2P_BIND_ADDRESS=0.0.0.0:$ESPRESSO_DEMO_SEQUENCER_LIBP2P_PORT_0
- ESPRESSO_SEQUENCER_LIBP2P_ADVERTISE_ADDRESS=sequencer0:$ESPRESSO_DEMO_SEQUENCER_LIBP2P_PORT_0
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=10
- ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS
- ESPRESSO_SEQUENCER_MAX_BLOCK_SIZE
- ESPRESSO_SEQUENCER_BASE_FEE
Expand Down Expand Up @@ -238,8 +236,6 @@ services:
- ESPRESSO_SEQUENCER_PRIVATE_STATE_KEY=$ESPRESSO_DEMO_SEQUENCER_STATE_PRIVATE_KEY_1
- ESPRESSO_SEQUENCER_LIBP2P_BIND_ADDRESS=0.0.0.0:$ESPRESSO_DEMO_SEQUENCER_LIBP2P_PORT_1
- ESPRESSO_SEQUENCER_LIBP2P_ADVERTISE_ADDRESS=sequencer1:$ESPRESSO_DEMO_SEQUENCER_LIBP2P_PORT_1
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=11
- ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS
- ESPRESSO_SEQUENCER_MAX_BLOCK_SIZE
- ESPRESSO_SEQUENCER_BASE_FEE
Expand Down Expand Up @@ -277,8 +273,6 @@ services:
- ESPRESSO_SEQUENCER_PRIVATE_STATE_KEY=$ESPRESSO_DEMO_SEQUENCER_STATE_PRIVATE_KEY_2
- ESPRESSO_SEQUENCER_LIBP2P_BIND_ADDRESS=0.0.0.0:$ESPRESSO_DEMO_SEQUENCER_LIBP2P_PORT_2
- ESPRESSO_SEQUENCER_LIBP2P_ADVERTISE_ADDRESS=sequencer2:$ESPRESSO_DEMO_SEQUENCER_LIBP2P_PORT_2
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=12
- ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS
- ESPRESSO_SEQUENCER_MAX_BLOCK_SIZE
- ESPRESSO_SEQUENCER_BASE_FEE
Expand Down Expand Up @@ -315,8 +309,6 @@ services:
- ESPRESSO_SEQUENCER_PRIVATE_STATE_KEY=$ESPRESSO_DEMO_SEQUENCER_STATE_PRIVATE_KEY_3
- ESPRESSO_SEQUENCER_LIBP2P_BIND_ADDRESS=0.0.0.0:$ESPRESSO_DEMO_SEQUENCER_LIBP2P_PORT_3
- ESPRESSO_SEQUENCER_LIBP2P_ADVERTISE_ADDRESS=sequencer3:$ESPRESSO_DEMO_SEQUENCER_LIBP2P_PORT_3
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=13
- ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS
- ESPRESSO_SEQUENCER_MAX_BLOCK_SIZE
- ESPRESSO_SEQUENCER_BASE_FEE
Expand Down Expand Up @@ -353,8 +345,6 @@ services:
- ESPRESSO_SEQUENCER_PRIVATE_STATE_KEY=$ESPRESSO_DEMO_SEQUENCER_STATE_PRIVATE_KEY_4
- ESPRESSO_SEQUENCER_LIBP2P_BIND_ADDRESS=0.0.0.0:$ESPRESSO_DEMO_SEQUENCER_LIBP2P_PORT_4
- ESPRESSO_SEQUENCER_LIBP2P_ADVERTISE_ADDRESS=sequencer4:$ESPRESSO_DEMO_SEQUENCER_LIBP2P_PORT_4
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=14
- ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS
- ESPRESSO_SEQUENCER_MAX_BLOCK_SIZE
- ESPRESSO_SEQUENCER_BASE_FEE
Expand Down
5 changes: 0 additions & 5 deletions process-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ processes:
- ESPRESSO_SEQUENCER_STORAGE_PATH=$ESPRESSO_BASE_STORAGE_PATH/seq0
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_0
- ESPRESSO_SEQUENCER_PRIVATE_STATE_KEY=$ESPRESSO_DEMO_SEQUENCER_STATE_PRIVATE_KEY_0
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=10
- ESPRESSO_SEQUENCER_STAKE_TABLE_CAPACITY=10
depends_on:
orchestrator:
Expand Down Expand Up @@ -128,7 +127,6 @@ processes:
- ESPRESSO_SEQUENCER_POSTGRES_PASSWORD=password
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_1
- ESPRESSO_SEQUENCER_PRIVATE_STATE_KEY=$ESPRESSO_DEMO_SEQUENCER_STATE_PRIVATE_KEY_1
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=11
- ESPRESSO_SEQUENCER_STAKE_TABLE_CAPACITY=10
depends_on:
orchestrator:
Expand Down Expand Up @@ -165,7 +163,6 @@ processes:
- ESPRESSO_SEQUENCER_STORAGE_PATH=$ESPRESSO_BASE_STORAGE_PATH/seq2
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_2
- ESPRESSO_SEQUENCER_PRIVATE_STATE_KEY=$ESPRESSO_DEMO_SEQUENCER_STATE_PRIVATE_KEY_2
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=12
- ESPRESSO_SEQUENCER_STAKE_TABLE_CAPACITY=10
depends_on:
orchestrator:
Expand Down Expand Up @@ -200,7 +197,6 @@ processes:
- ESPRESSO_SEQUENCER_STORAGE_PATH=$ESPRESSO_BASE_STORAGE_PATH/seq3
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_3
- ESPRESSO_SEQUENCER_PRIVATE_STATE_KEY=$ESPRESSO_DEMO_SEQUENCER_STATE_PRIVATE_KEY_3
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=13
- ESPRESSO_SEQUENCER_STAKE_TABLE_CAPACITY=10
depends_on:
orchestrator:
Expand Down Expand Up @@ -233,7 +229,6 @@ processes:
- ESPRESSO_SEQUENCER_STORAGE_PATH=$ESPRESSO_BASE_STORAGE_PATH/seq4
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_4
- ESPRESSO_SEQUENCER_PRIVATE_STATE_KEY=$ESPRESSO_DEMO_SEQUENCER_STATE_PRIVATE_KEY_4
- ESPRESSO_SEQUENCER_ETH_ACCOUNT_INDEX=14
- ESPRESSO_SEQUENCER_STAKE_TABLE_CAPACITY=10
depends_on:
orchestrator:
Expand Down
63 changes: 38 additions & 25 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,6 @@ mod api_tests {

#[cfg(test)]
mod test {

use self::{
data_source::testing::TestableSequencerDataSource, sql::DataSource as SqlDataSource,
};
Expand Down Expand Up @@ -772,7 +771,9 @@ mod test {
};
use hotshot_types::{
event::LeafInfo,
traits::{block_contents::BlockHeader, metrics::NoMetrics},
traits::{
block_contents::BlockHeader, metrics::NoMetrics, node_implementation::ConsensusTime,
},
};
use jf_primitives::merkle_tree::{
prelude::{MerkleProof, Sha3Node},
Expand Down Expand Up @@ -838,9 +839,8 @@ mod test {
.status(Default::default()),
);

// Populate one account so we have something to look up later. Leave the other accounts
// unpopulated, which proves we can handle state updates even with missing accounts.
let account = TestConfig::builder_key(0).fee_account();
// Populate the builder account so we have something to look up later.
let account = TestConfig::builder_key().fee_account();
let mut state = ValidatedState::default();
state.prefund_account(account, 1.into());
let mut network = TestNetwork::with_state(
Expand Down Expand Up @@ -947,23 +947,30 @@ mod test {
.await;
let mut events = network.server.get_event_stream();

// Wait for a (non-genesis) block proposed by the lagging node, to prove that it has caught
// up.
let builder = TestConfig::builder_key(TestConfig::NUM_NODES - 1).fee_account();
'outer: loop {
// Wait for a (non-genesis) block proposed by each node, to prove that the lagging node has
// caught up and all nodes are in sync.
let mut proposers = [false; TestConfig::NUM_NODES];
loop {
let event = events.next().await.unwrap();
let EventType::Decide { leaf_chain, .. } = event.event else {
continue;
};
for LeafInfo { leaf, .. } in leaf_chain.iter().rev() {
let height = leaf.get_block_header().height;
let leaf_builder = leaf.get_block_header().fee_info.account();
let height = leaf.get_height();
let leaf_builder =
(leaf.get_view_number().get_u64() as usize) % TestConfig::NUM_NODES;
if height == 0 {
continue;
}

tracing::info!(
"waiting for block from {builder}, block {height} is from {leaf_builder}",
"waiting for blocks from {proposers:?}, block {height} is from {leaf_builder}",
);
if height > 1 && leaf_builder == builder {
break 'outer;
}
proposers[leaf_builder] = true;
}

if proposers.iter().all(|has_proposed| *has_proposed) {
break;
}
}
}
Expand Down Expand Up @@ -1037,24 +1044,30 @@ mod test {
.await;
let mut events = node.get_event_stream();

// Wait for a (non-genesis) block proposed by the lagging node, to prove that it has caught
// up.
let builder = TestConfig::builder_key(1).fee_account();
'outer: loop {
// Wait for a (non-genesis) block proposed by each node, to prove that the lagging node has
// caught up and all nodes are in sync.
let mut proposers = [false; TestConfig::NUM_NODES];
loop {
let event = events.next().await.unwrap();
tracing::info!(?event, "restarted node got event");
let EventType::Decide { leaf_chain, .. } = event.event else {
continue;
};
for LeafInfo { leaf, .. } in leaf_chain.iter().rev() {
let height = leaf.get_height();
let leaf_builder = leaf.get_block_header().fee_info.account();
let leaf_builder =
(leaf.get_view_number().get_u64() as usize) % TestConfig::NUM_NODES;
if height == 0 {
continue;
}

tracing::info!(
"waiting for block from {builder}, block {height} is from {leaf_builder}",
"waiting for blocks from {proposers:?}, block {height} is from {leaf_builder}",
);
if height > 1 && leaf_builder == builder {
break 'outer;
}
proposers[leaf_builder] = true;
}

if proposers.iter().all(|has_proposed| *has_proposed) {
break;
}
}
}
Expand Down
Loading

0 comments on commit 6361845

Please sign in to comment.