nonce_manager

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const CName = "any-ns.nonce-manager"

Variables

This section is empty.

Functions

func New

func New() app.Component

Types

type NonceDbItem

type NonceDbItem struct {
	Address string `bson:"address"`
	Nonce   int64  `bson:"nonce"`
}

TODO: index it

type NonceService

type NonceService interface {
	// try to determine nonce by looking in DB first, then use network as a fallback
	GetCurrentNonce(addr ethcommon.Address) (uint64, error)

	// try to determine nonce by looking at current TX count plus pending TXs in the mem pool
	// (not reliable, but can be used as a fallback)
	GetCurrentNonceFromNetwork(addr ethcommon.Address) (uint64, error)

	// save nonce to DB
	SaveNonce(addr ethcommon.Address, newValue uint64) (uint64, error)

	app.Component
}

Nonce policy: 1. if nonce is specified in the config file: - read it from config and override the value from DB/network

2. if nonce is in DB: - get nonce from DB

3. if nonce is not in DB: - get nonce from network - mined + pending txs count

if tx is sent and mined succesfully: - save last nonce to DB

if we got "nonce is too low" error the tx is immediately rejected. to fix it: - get nonce from network - send this tx again with +1 nonce

if nonce is higher than needed - tx will be rejected by the network with "not found" error immediately in this case we: - wait for N minutes for all TXs to settle - get new nonce from network - retry sending this tx with new nonce

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL