Skip to content

Commit

Permalink
fix(rpc): use node nonce for mint tx
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-wright committed Oct 16, 2023
1 parent 4b43e58 commit 5f81efe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 10 additions & 0 deletions core/application/src/query_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,16 @@ impl SyncQueryRunnerInterface for QueryRunner {
})
}

fn get_node_nonce(&self, node_index: &NodeIndex) -> u64 {
self.inner.run(|ctx| {
self.node_table
.get(ctx)
.get(node_index)
.map(|node| node.nonce)
.unwrap_or_default()
})
}

fn get_chain_id(&self) -> u32 {
self.inner.run(
|ctx| match self.metadata_table.get(ctx).get(&Metadata::ChainId) {
Expand Down
5 changes: 4 additions & 1 deletion core/interfaces/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,12 @@ pub trait SyncQueryRunnerInterface: Clone + Send + Sync + 'static {
/// Returns last executed block hash. [0;32] is genesis
fn get_last_block(&self) -> [u8; 32];

/// Returns an accounts current nonce
/// Returns an account's current nonce
fn get_account_nonce(&self, public_key: &EthAddress) -> u64;

/// Returns a node's current nonce
fn get_node_nonce(&self, node_index: &NodeIndex) -> u64;

/// Returns the chain id
fn get_chain_id(&self) -> u32;

Expand Down
6 changes: 5 additions & 1 deletion core/rpc/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ pub async fn mint_handler<C: Collection>(
if balance > 1010 {
return Ok("already minted".to_string());
}
let nonce = data.query_runner.get_account_nonce(&params.public_key) + 1;
let node_pk = data.node_secret_key.to_pk();
let Some(node_index) = data.query_runner.pubkey_to_index(node_pk) else {
return Ok("rpc node is not staked".to_string());
};
let nonce = data.query_runner.get_node_nonce(&node_index) + 1;
let method = UpdateMethod::Mint {
recipient: params.public_key,
};
Expand Down

0 comments on commit 5f81efe

Please sign in to comment.