Skip to content

Commit f480b1e

Browse files
committed
Adding protocol_version to intrinsic tx verification
1 parent 8ec152e commit f480b1e

28 files changed

Lines changed: 427 additions & 105 deletions

File tree

blockchain-interface/src/abstract_blockchain.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub trait AbstractBlockchain {
4646
self.election_head().hash()
4747
}
4848

49+
fn protocol_version(&self) -> u16;
50+
4951
/// Returns the block number at the head of the main chain.
5052
fn block_number(&self) -> u32 {
5153
self.head().block_number()

blockchain-proxy/src/blockchain_proxy.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ impl AbstractBlockchain for BlockchainReadProxy<'_> {
115115
gen_blockchain_match!(self, BlockchainReadProxy, election_head)
116116
}
117117

118+
fn protocol_version(&self) -> u16 {
119+
gen_blockchain_match!(self, BlockchainReadProxy, protocol_version)
120+
}
121+
118122
fn accounts_complete(&self) -> bool {
119123
gen_blockchain_match!(self, BlockchainReadProxy, accounts_complete)
120124
}

blockchain/src/blockchain/abstract_blockchain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ impl AbstractBlockchain for Blockchain {
5050
self.state.accounts.is_complete(None)
5151
}
5252

53+
fn protocol_version(&self) -> u16 {
54+
self.state.current_version()
55+
}
56+
5357
fn can_enforce_validity_window(&self) -> bool {
5458
// If we are at the genesis block, we can enforce the validity window
5559
if self.block_number() == Policy::genesis_block_number() {

blockchain/src/blockchain/verify.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ impl Blockchain {
102102
}
103103

104104
fn verify_transactions(&self, block: &Block) -> Result<(), BlockError> {
105+
let version = block.version();
105106
if let Some(transactions) = block.transactions() {
106107
for transaction in transactions {
107108
let transaction = transaction.get_raw_transaction();
108109
if !self.tx_verification_cache.is_known(&transaction.hash()) {
109-
transaction.verify(self.network_id)?;
110+
transaction.verify(self.network_id, version)?;
110111
}
111112
}
112113
}

lib/src/client.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,11 @@ impl Client {
738738
self.inner.blockchain.read().head().clone()
739739
}
740740

741+
/// Returns the blockchain protocol version
742+
pub fn protocol_version(&self) -> u16 {
743+
self.inner.blockchain.read().protocol_version()
744+
}
745+
741746
#[cfg(feature = "wallet")]
742747
pub fn wallet_store(&self) -> Arc<WalletStore> {
743748
Arc::clone(&self.inner.wallet_store)

light-blockchain/src/abstract_blockchain.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ impl AbstractBlockchain for LightBlockchain {
3939
fn accounts_complete(&self) -> bool {
4040
false
4141
}
42+
fn protocol_version(&self) -> u16 {
43+
self.head.version()
44+
}
4245

4346
fn current_validators(&self) -> Option<&Validators> {
4447
self.current_validators.as_ref()

mempool/src/verify.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ pub(crate) fn verify_tx(
3939
filter: Arc<RwLock<MempoolFilter>>,
4040
priority: TxPriority,
4141
) -> Result<(), VerifyErr> {
42-
// 1. Verify transaction signature (and other stuff)
43-
transaction.verify_mut(network_id)?;
44-
45-
// 2. Acquire blockchain read lock
42+
// 1. Acquire blockchain read lock
4643
let blockchain = blockchain.read();
4744

45+
// 2. Verify transaction signature (and other stuff)
46+
transaction.verify_mut(network_id, blockchain.state.current_version())?;
47+
4848
// 3. Check validity window and already included
4949
let block_number = blockchain.block_number() + 1;
5050
if !transaction.is_valid_at(block_number) {

pow-migration/src/history.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ mod test {
666666

667667
let web_transaction: WebTransaction = pos_transaction.into();
668668
// Convert with the genesis block number and timestamp of mainnet.
669-
web_transaction.to_plain_transaction(Some(3456000), Some(1732034720000));
669+
web_transaction.to_plain_transaction(Some(3456000), Some(1732034720000), 0);
670670
}
671671
}
672672
}

primitives/account/tests/accounts.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,11 @@ fn can_revert_transactions() {
987987
fail_recipient,
988988
"Testing transaction"
989989
);
990-
assert_eq!(tx.verify(NetworkId::UnitAlbatross), Ok(()));
990+
assert_eq!(tx.verify(NetworkId::UnitAlbatross, 0), Ok(()));
991+
assert_eq!(
992+
tx.verify(NetworkId::UnitAlbatross, Policy::max_supported_version()),
993+
Ok(())
994+
);
991995

992996
let receipts = accounts.test(&[tx], &[], &block_state);
993997
if fail_sender || fail_recipient {

primitives/account/tests/staking_contract/add_stake_policy.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,9 @@ fn add_stake_enforces_minimum_stake_works() {
590590
Policy::MINIMUM_STAKE - 1,
591591
&staker_keypair,
592592
);
593+
assert_eq!(tx.verify(NetworkId::UnitAlbatross, 0), Ok(()));
593594
assert_eq!(
594-
tx.verify(NetworkId::UnitAlbatross),
595+
tx.verify(NetworkId::UnitAlbatross, Policy::max_supported_version()),
595596
Err(TransactionError::InvalidValue)
596597
);
597598

@@ -835,8 +836,9 @@ fn add_stake_enforces_minimum_stake_legacy_works() {
835836
Policy::MINIMUM_STAKE - 1,
836837
&staker_keypair,
837838
);
839+
assert_eq!(tx.verify(NetworkId::UnitAlbatross, 0), Ok(()));
838840
assert_eq!(
839-
tx.verify(NetworkId::UnitAlbatross),
841+
tx.verify(NetworkId::UnitAlbatross, Policy::max_supported_version()),
840842
Err(TransactionError::InvalidValue)
841843
);
842844

0 commit comments

Comments
 (0)