美文网首页
eth_sendRawTransaction流程分析

eth_sendRawTransaction流程分析

作者: debuggor | 来源:发表于2020-09-19 18:48 被阅读0次

前言

通过eth_sendRawTransaction发送一笔交易,(internal/ethapi/api.go)SendRawTransaction方法作为入口。

SendRawTransaction

  • rlp.DecodeBytes(encodedTx, tx) 将hex交易decode得到交易详情,
  • SubmitTransaction(ctx, s.b, tx)
SendRawTransaction

SubmitTransaction

checkTxFee

检查交易手续费,最大fee不能超过设定的值

SendTx(ctx, tx)

tx.to地址

如果交易to地址为null,表示是创建合约的交易。合约地址是由from和交易nonce决定。
addr := crypto.CreateAddress(from, tx.Nonce())

image.png

pool.addTxs

SendTx—>eth.txPool.AddLocal—>pool.AddLocals—>pool.addTxs

检查交易是否在pool中

types.Sender(pool.signer, tx)

hex交易中不包含from地址,从签名结果中恢复出from地址。同时也验证了交易签名,后面不再对签名做校验。

pool.addTxsLocked

pool.validateTx(tx, local)

校验交易大小、金额、gas、nonce

判断pool中交易数量是否达最大值

pool.pending[from]

从pool中根据from地址查询,如果这笔交易的nonce已在pool,是否替换掉old交易。

pool.enqueueTx(hash, tx)

将交易放入队列中,等待其他进程处理

addTxs
add

eth tx error

// ErrAlreadyKnown is returned if the transactions is already contained
// within the pool.
ErrAlreadyKnown = errors.New("already known")

// ErrInvalidSender is returned if the transaction contains an invalid signature.
ErrInvalidSender = errors.New("invalid sender")

// ErrUnderpriced is returned if a transaction's gas price is below the minimum
// configured for the transaction pool.
ErrUnderpriced = errors.New("transaction underpriced")

// ErrReplaceUnderpriced is returned if a transaction is attempted to be replaced
// with a different one without the required price bump.
ErrReplaceUnderpriced = errors.New("replacement transaction underpriced")

// ErrGasLimit is returned if a transaction's requested gas limit exceeds the
// maximum allowance of the current block.
ErrGasLimit = errors.New("exceeds block gas limit")

// ErrNegativeValue is a sanity error to ensure no one is able to specify a
// transaction with a negative value.
ErrNegativeValue = errors.New("negative value")

// ErrOversizedData is returned if the input data of a transaction is greater
// than some meaningful limit a user might use. This is not a consensus error
// making the transaction invalid, rather a DOS protection.
ErrOversizedData = errors.New("oversized data")

相关文章

网友评论

      本文标题:eth_sendRawTransaction流程分析

      本文链接:https://www.haomeiwen.com/subject/xlxyyktx.html