Skip to content

Commit

Permalink
chore: refactor out secondary nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-wright committed May 31, 2024
1 parent ed8766a commit 672edde
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 137 deletions.
1 change: 0 additions & 1 deletion core/application/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ impl From<&GenesisNode> for NodeInfo {
stake: value.stake.clone(),
participation: Participation::True,
nonce: 0,
secondary_nonce: 0,
ports: value.ports.clone(),
}
}
Expand Down
11 changes: 2 additions & 9 deletions core/application/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@ impl<B: Backend> State<B> {
ports,
participation: Participation::False,
nonce: 0,
secondary_nonce: 0,
};
self.create_node(node);
} else {
Expand Down Expand Up @@ -1615,9 +1614,7 @@ impl<B: Backend> State<B> {
TransactionSender::NodeMain(node) => {
if let Some(index) = self.pub_key_to_index.get(&node) {
if let Some(info) = self.node_info.get(&index) {
if txn.payload.nonce != info.nonce + 1
|| txn.payload.secondary_nonce <= info.secondary_nonce
{
if txn.payload.nonce != info.nonce + 1 {
return Err(ExecutionError::InvalidNonce);
}
} else {
Expand All @@ -1630,9 +1627,7 @@ impl<B: Backend> State<B> {
TransactionSender::NodeConsensus(node) => {
if let Some(index) = self.consensus_key_to_index.get(&node) {
if let Some(info) = self.node_info.get(&index) {
if txn.payload.nonce != info.nonce + 1
|| txn.payload.secondary_nonce <= info.secondary_nonce
{
if txn.payload.nonce != info.nonce + 1 {
return Err(ExecutionError::InvalidNonce);
}
}
Expand Down Expand Up @@ -1753,14 +1748,12 @@ impl<B: Backend> State<B> {
let index = self.pub_key_to_index.get(&node).unwrap();
let mut node_info = self.node_info.get(&index).unwrap();
node_info.nonce += 1;
node_info.secondary_nonce += 1;
self.node_info.set(index, node_info);
},
TransactionSender::NodeConsensus(node) => {
let index = self.consensus_key_to_index.get(&node).unwrap();
let mut node_info = self.node_info.get(&index).unwrap();
node_info.nonce += 1;
node_info.secondary_nonce += 1;
self.node_info.set(index, node_info);
},
TransactionSender::AccountOwner(account) => {
Expand Down
Loading

0 comments on commit 672edde

Please sign in to comment.