diff --git a/rollup/src/block.rs b/rollup/src/block.rs index 56689c3..4bf4b33 100644 --- a/rollup/src/block.rs +++ b/rollup/src/block.rs @@ -8,11 +8,17 @@ use crate::{Signature, SignedTransaction, Signer}; /// A block header containing metadata about the block. #[derive(Serialize, Deserialize, Debug, Clone)] pub struct BlockHeader { + /// The address of the sequencer that sealed the block. pub sequencer: Address, + /// The number of the block. pub number: u64, + /// The timestamp at the time the block was sealed. pub timestamp: u64, + /// The hash of the parent block. None if this is the genesis block. pub parent_digest: Option, + /// The root digest of the withdrawals Merkle tree. pub withdrawals_root: String, + /// The root digest of the transactions Merkle tree. pub transactions_root: String, } diff --git a/rollup/src/blockchain.rs b/rollup/src/blockchain.rs index ce5e181..1c25c06 100644 --- a/rollup/src/blockchain.rs +++ b/rollup/src/blockchain.rs @@ -2,8 +2,11 @@ use crate::{transaction::DynamicTxData, Block, WithdrawalTxData}; /// A blockchain containing a list of blocks and an incremental Merkle tree of withdrawals. pub(crate) struct Blockchain { + /// The chain of blocks in the blockchain. pub(crate) blocks: Vec, + /// The incremental Merkle tree of withdrawals. pub(crate) withdrawals_tree: imt::Tree, + /// The incremental Merkle tree of transactions. pub(crate) transactions_tree: imt::Tree, } diff --git a/rollup/src/sequencer.rs b/rollup/src/sequencer.rs index 9ece5a6..ffb0c4d 100644 --- a/rollup/src/sequencer.rs +++ b/rollup/src/sequencer.rs @@ -5,10 +5,14 @@ use crate::{ /// Permissioned entity responsible for maintaining the canonical [Blockchain]. /// Receives transactions directly and seals them into blocks. pub struct Sequencer { + /// The sequencer's signer used to sign blocks. signer: Signer, + /// The blockchain maintained by the sequencer. blockchain: Blockchain, - pool: Vec, - withdrawals: Vec, + /// The pool of transactions to be included in the next block. + transactions_pool: Vec, + /// The pool of withdrawal transactions to be included in the next block. + withdrawals_pool: Vec, } impl Sequencer { @@ -17,8 +21,8 @@ impl Sequencer { Sequencer { signer: signer.into(), blockchain: Blockchain::default(), - pool: vec![], - withdrawals: vec![], + transactions_pool: vec![], + withdrawals_pool: vec![], } } @@ -27,11 +31,11 @@ impl Sequencer { match &transaction.transaction { Transaction::Withdrawal(tx) => { self.blockchain.withdraw(tx); - self.withdrawals.push(transaction); + self.withdrawals_pool.push(transaction); } Transaction::Dynamic(tx) => { self.blockchain.transact(tx); - self.pool.push(transaction); + self.transactions_pool.push(transaction); } } } @@ -51,9 +55,9 @@ impl Sequencer { // Drain the transaction pools and construct the block. let block = Block::new( SignedBlockHeader::new(header, &self.signer), - self.pool + self.transactions_pool .drain(..) - .chain(self.withdrawals.drain(..)) + .chain(self.withdrawals_pool.drain(..)) .collect(), ); self.blockchain.push(block.clone()); diff --git a/rollup/src/signer.rs b/rollup/src/signer.rs index a665ec9..fcac587 100644 --- a/rollup/src/signer.rs +++ b/rollup/src/signer.rs @@ -10,8 +10,11 @@ use std::str::FromStr; /// A recoverable seckp256k1 signature. #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Signature { + /// The r component of the signature. pub r: U256, + /// The s component of the signature. pub s: U256, + /// The recovery id of the signature. pub recovery_id: i32, } diff --git a/rollup/src/transaction.rs b/rollup/src/transaction.rs index a56bcca..dfab71d 100644 --- a/rollup/src/transaction.rs +++ b/rollup/src/transaction.rs @@ -7,17 +7,22 @@ use crate::signer::{Signature, Signer}; /// A transaction header containing metadata about the transaction. #[derive(Serialize, Deserialize, Debug, Clone)] pub struct TransactionHeader { - chain_id: u64, + /// The address of the sender of the transaction. sender: Address, + /// The address of the recipient of the transaction. recipient: Address, + /// The amount of value transferred by the transaction. amount: u64, } /// A dynamic transaction containing a transaction header and dynamic fee data. #[derive(Serialize, Deserialize, Debug, Clone)] pub struct DynamicTxData { + /// The transaction header. header: TransactionHeader, + /// The maximum fee per gas that the sender is willing to pay. max_fee_per_gas: u64, + /// The maximum priority fee per gas that the sender is willing to pay. max_priority_fee_per_gas: u64, } @@ -32,7 +37,9 @@ impl DynamicTxData { /// A withdrawal transaction containing a transaction header and destination. #[derive(Serialize, Deserialize, Debug, Clone)] pub struct WithdrawalTxData { + /// The transaction header. header: TransactionHeader, + /// The destination chain of the withdrawal. dest_chain: u64, } @@ -58,7 +65,6 @@ impl Transaction { pub fn dynamic(sender: Address, amount: u64) -> Self { Transaction::Dynamic(DynamicTxData { header: TransactionHeader { - chain_id: 1, sender, recipient: Address::random(), amount, @@ -72,7 +78,6 @@ impl Transaction { pub fn withdrawal(sender: Address, amount: u64, dest_chain: u64) -> Self { Transaction::Withdrawal(WithdrawalTxData { header: TransactionHeader { - chain_id: 1, sender, recipient: sender, amount,