1.结构体
SendTxArgs

TxPool

2.SendTransaction
go-ethereum/internal/ethapi/api.go

2.1 signTransaction
go-ethereum/internal/ethapi/api.go


2.1.1 toTransaction
go-ethereum/internal/ethapi/api.go

2.1.1.1 newTransaction
go-ethereum/core/types/transaction.go

2.1.2 SignTxWithPassphrase
最终调用go-ethereum/core/types/transaction.go的WithSignature

2.2 submitTransaction
go-ethereum/internal/ethapi/api.go

2.2.1 SendTx
最终会执行ethereum/go-ethereum/core/tx_pool.go的addTx

2.2.1.1 add
go-ethereum/core/tx_pool.go
(1)如果交易已经存在,直接返回

(2)validateTx


(3)如果pool.all的size达到上限,则需要根据tx的gasPrice来决定是否能够放入pool

(4)如果已经有相同nonce的tx,则需要将old tx替换成new tx,发送NewTxsEvent事件

(5)如果不存在相同nonce,则放入pool

网友评论