diff --git a/sequencer_core/src/block_settlement_client.rs b/sequencer_core/src/block_settlement_client.rs index 8a53892d..04a3740c 100644 --- a/sequencer_core/src/block_settlement_client.rs +++ b/sequencer_core/src/block_settlement_client.rs @@ -28,7 +28,11 @@ pub trait BlockSettlementClientTrait: Clone { /// Create and sign a transaction for inscribing data. fn create_inscribe_tx(&self, block: &Block) -> Result<(SignedMantleTx, MsgId)> { let inscription_data = borsh::to_vec(block)?; - log::info!("The size of the block {} is {} bytes", block.header.block_id, inscription_data.len()); + log::info!( + "The size of the block {} is {} bytes", + block.header.block_id, + inscription_data.len() + ); let verifying_key_bytes = self.bedrock_signing_key().public_key().to_bytes(); let verifying_key = Ed25519PublicKey::from_bytes(&verifying_key_bytes).expect("valid ed25519 public key"); @@ -91,6 +95,15 @@ impl BlockSettlementClientTrait for BlockSettlementClient { } async fn submit_inscribe_tx_to_bedrock(&self, tx: SignedMantleTx) -> Result<()> { + let (parent_id, msg_id) = match tx.mantle_tx.ops.first() { + Some(Op::ChannelInscribe(inscribe)) => (inscribe.parent, inscribe.id()), + _ => panic!("Expected ChannelInscribe op"), + }; + log::info!(">>>>>>>>>>>>>>>>>>>>>>"); + log::info!("Posted block to Bedrock"); + log::info!(">>>>>> parent id: {parent_id:?}"); + log::info!(">>>>>> msg id: {msg_id:?}"); + log::info!(">>>>>>>>>>>>>>>>>>>>>>"); self.bedrock_client .post_transaction(tx) .await diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 9a2ca2b1..f9f6ebd5 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -174,9 +174,19 @@ impl SequencerCore Result { - let (_tx, _msg_id) = self + let (tx, _msg_id) = self .produce_new_block_with_mempool_transactions() .context("Failed to produce new block with mempool transactions")?; + match self + .block_settlement_client + .submit_inscribe_tx_to_bedrock(tx) + .await + { + Ok(()) => {} + Err(err) => { + error!("Failed to post block data to Bedrock with error: {err:#}"); + } + } Ok(self.chain_height) } diff --git a/sequencer_runner/configs/debug/sequencer_config.json b/sequencer_runner/configs/debug/sequencer_config.json index 8974790c..8e8275b9 100644 --- a/sequencer_runner/configs/debug/sequencer_config.json +++ b/sequencer_runner/configs/debug/sequencer_config.json @@ -5,8 +5,8 @@ "is_genesis_random": true, "max_num_tx_in_block": 20, "mempool_max_size": 1000, - "block_create_timeout_millis": 15000, - "retry_pending_blocks_timeout_millis": 500, + "block_create_timeout_millis": 2000, + "retry_pending_blocks_timeout_millis": 200000, "port": 3040, "bedrock_config": { "backoff": { diff --git a/sequencer_runner/src/lib.rs b/sequencer_runner/src/lib.rs index 2ea5f422..603ab23b 100644 --- a/sequencer_runner/src/lib.rs +++ b/sequencer_runner/src/lib.rs @@ -121,6 +121,11 @@ pub async fn startup_sequencer(app_config: SequencerConfig) -> Result>, block_timeout: Duration) } } +async fn retry_pending_blocks(seq_core: &Arc>) -> Result<()> { + let (mut pending_blocks, block_settlement_client) = { + let sequencer_core = seq_core.lock().await; + let client = sequencer_core.block_settlement_client(); + let pending_blocks = sequencer_core + .get_pending_blocks() + .expect("Sequencer should be able to retrieve pending blocks"); + (pending_blocks, client) + }; + + let k = 25; + if pending_blocks.len() > k { + pending_blocks.select_nth_unstable_by_key(k, |b| b.header.block_id); + } + for block in pending_blocks.iter().take(k) { + info!( + "Resubmitting pending block with id {}", + block.header.block_id + ); + // TODO: We could cache the inscribe tx for each pending block to avoid re-creating it + // on every retry. + let now = Instant::now(); + let (tx, _msg_id) = block_settlement_client + .create_inscribe_tx(block) + .context("Failed to create inscribe tx for pending block")?; + + debug!(">>>> Create inscribe: {:?}", now.elapsed()); + + let now = Instant::now(); + if let Err(e) = block_settlement_client + .submit_inscribe_tx_to_bedrock(tx) + .await + { + warn!( + "Failed to resubmit block with id {} with error {e:#}", + block.header.block_id + ); + } + debug!(">>>> Post: {:?}", now.elapsed()); + } + Ok(()) +} + async fn retry_pending_blocks_loop( seq_core: Arc>, retry_pending_blocks_timeout: Duration, ) -> Result { loop { tokio::time::sleep(retry_pending_blocks_timeout).await; - - let (mut pending_blocks, block_settlement_client) = { - let sequencer_core = seq_core.lock().await; - let client = sequencer_core.block_settlement_client(); - let pending_blocks = sequencer_core - .get_pending_blocks() - .expect("Sequencer should be able to retrieve pending blocks"); - (pending_blocks, client) - }; - - let k = 50; - if pending_blocks.len() > k { - pending_blocks.select_nth_unstable_by_key(k, |b| b.header.block_id); - } - for block in pending_blocks.iter().take(k) { - info!( - "Resubmitting pending block with id {}", - block.header.block_id - ); - // TODO: We could cache the inscribe tx for each pending block to avoid re-creating it - // on every retry. - let now = Instant::now(); - let (tx, _msg_id) = block_settlement_client - .create_inscribe_tx(block) - .context("Failed to create inscribe tx for pending block")?; - - debug!(">>>> Create inscribe: {:?}", now.elapsed()); - - let now = Instant::now(); - if let Err(e) = block_settlement_client - .submit_inscribe_tx_to_bedrock(tx) - .await - { - warn!( - "Failed to resubmit block with id {} with error {e:#}", - block.header.block_id - ); - } - debug!(">>>> Post: {:?}", now.elapsed()); - } + retry_pending_blocks(&seq_core).await?; } }