gakonst / ethers-rs

Complete Ethereum & Celo library and wallet implementation in Rust. https://docs.rs/ethers
Apache License 2.0
2.5k stars 796 forks source link

NonceManagerMiddleware always return zero nonce #2077

Open zt-9 opened 1 year ago

zt-9 commented 1 year ago

Version

├── ethers v1.0.2
│   ├── ethers-addressbook v1.0.2
│   │   ├── ethers-core v1.0.2
│   ├── ethers-contract v1.0.2
│   │   ├── ethers-contract-abigen v1.0.2
│   │   │   ├── ethers-core v1.0.2 (*)
│   │   ├── ethers-contract-derive v1.0.2 (proc-macro)
│   │   │   ├── ethers-contract-abigen v1.0.2
│   │   │   │   ├── ethers-core v1.0.2
│   │   │   ├── ethers-core v1.0.2 (*)
│   │   ├── ethers-core v1.0.2 (*)
│   │   ├── ethers-providers v1.0.2
│   │   │   ├── ethers-core v1.0.2 (*)
│   ├── ethers-core v1.0.2 (*)
│   ├── ethers-etherscan v1.0.2
│   │   ├── ethers-core v1.0.2 (*)
│   ├── ethers-middleware v1.0.2
│   │   ├── ethers-contract v1.0.2 (*)
│   │   ├── ethers-core v1.0.2 (*)
│   │   ├── ethers-etherscan v1.0.2 (*)
│   │   ├── ethers-providers v1.0.2 (*)
│   │   ├── ethers-signers v1.0.2
│   │   │   ├── ethers-core v1.0.2 (*)
│   ├── ethers-providers v1.0.2 (*)
│   ├── ethers-signers v1.0.2 (*)
│   └── ethers-solc v1.0.2
│       ├── ethers-core v1.0.2 (*)
├── ethers-flashbots v0.12.1
│   ├── ethers v1.0.2 (*)

Platform MacOS 13.1 (22C65) M1

Description NonceManagerMiddleware always returns zero nonce.

  // always 0. tested with different addresses
  let nonce_nm = NonceManagerMiddleware::new(provider, tx_signer_address).next(); 

However, I can only get the correct nonce with the get_transaction_count from ethers

  let block_number = client.get_block_number().await?;
  let block_id = BlockId::Number(BlockNumber::Number(block_number));
  let nonce = provider.get_transaction_count(tx_signer_address, Some(block_id)).await?; // returns the correct nonce
mattsse commented 1 year ago

let nonce_nm = NonceManagerMiddleware::new(provider, tx_signer_address).next();

at this point, the nonce is not initialized yet. See fn initialize_nonce

The docs are not great here...

mattsse commented 1 year ago

imo next should be made private

zt-9 commented 1 year ago

maybe the fill_transaction() does not fill correct nonce to tx bc of this. this is the code from the ethers_flashbots example https://github.com/onbjerg/ethers-flashbots/blob/57bd555f7533581c09b363a5b4c19bb130d7dd9d/examples/advanced.rs#L32-L35

mattsse commented 1 year ago

sorry, I don't understand how this is related

zt-9 commented 1 year ago

sorry, I don't understand how this is related

ohh probably some unrelated issue here.fill_transaction() can now fill the correct nonce for me suddenly