mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
git_一些备注
This commit is contained in:
parent
933972d139
commit
0ef3035c1f
3 changed files with 20 additions and 16 deletions
|
|
@ -59,7 +59,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
||||||
usedGas = new(uint64)
|
usedGas = new(uint64)
|
||||||
header = block.Header()
|
header = block.Header()
|
||||||
allLogs []*types.Log
|
allLogs []*types.Log
|
||||||
gp = new(GasPool).AddGas(block.GasLimit())
|
gp = new(GasPool).AddGas(block.GasLimit()) //gaspool初始值均为0,通过block_gaslimit完成初始化
|
||||||
)
|
)
|
||||||
// Mutate the the block and state according to any hard-fork specs
|
// Mutate the the block and state according to any hard-fork specs
|
||||||
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
|
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
|
||||||
|
|
@ -90,13 +90,14 @@ func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, author *common
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new context to be used in the EVM environment
|
// Create a new context to be used in the EVM environment
|
||||||
context := NewEVMContext(msg, header, bc, author)
|
context := NewEVMContext(msg, header, bc, author)
|
||||||
// Create a new environment which holds all relevant information
|
// Create a new environment which holds all relevant information
|
||||||
// about the transaction and calling mechanisms.
|
// about the transaction and calling mechanisms.
|
||||||
vmenv := vm.NewEVM(context, statedb, config, cfg)
|
vmenv := vm.NewEVM(context, statedb, config, cfg) // core/evm.go 包括interpretor的建立
|
||||||
// Apply the transaction to the current state (included in the env)
|
// Apply the transaction to the current state (included in the env)
|
||||||
_, gas, failed, err := ApplyMessage(vmenv, msg, gp)
|
_, gas, failed, err := ApplyMessage(vmenv, msg, gp) //TransitionDb() 执行交易 transition state
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +108,7 @@ func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, author *common
|
||||||
} else {
|
} else {
|
||||||
root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes()
|
root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes()
|
||||||
}
|
}
|
||||||
*usedGas += gas
|
*usedGas += gas //将单笔交易的gas累计
|
||||||
|
|
||||||
// Create a new receipt for the transaction, storing the intermediate root and gas used by the tx
|
// Create a new receipt for the transaction, storing the intermediate root and gas used by the tx
|
||||||
// based on the eip phase, we're passing wether the root touch-delete accounts.
|
// based on the eip phase, we're passing wether the root touch-delete accounts.
|
||||||
|
|
|
||||||
|
|
@ -320,7 +320,7 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
|
||||||
if evm.depth > int(params.CallCreateDepth) {
|
if evm.depth > int(params.CallCreateDepth) {
|
||||||
return nil, common.Address{}, gas, ErrDepth
|
return nil, common.Address{}, gas, ErrDepth
|
||||||
}
|
}
|
||||||
if !evm.CanTransfer(evm.StateDB, caller.Address(), value) {
|
if !evm.CanTransfer(evm.StateDB, caller.Address(), value) { //检测账户余额
|
||||||
return nil, common.Address{}, gas, ErrInsufficientBalance
|
return nil, common.Address{}, gas, ErrInsufficientBalance
|
||||||
}
|
}
|
||||||
// Ensure there's no existing contract already at the designated address
|
// Ensure there's no existing contract already at the designated address
|
||||||
|
|
@ -334,12 +334,14 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
|
||||||
}
|
}
|
||||||
// Create a new account on the state
|
// Create a new account on the state
|
||||||
snapshot := evm.StateDB.Snapshot()
|
snapshot := evm.StateDB.Snapshot()
|
||||||
evm.StateDB.CreateAccount(contractAddr)
|
evm.StateDB.CreateAccount(contractAddr) //合约账户
|
||||||
if evm.ChainConfig().IsEIP158(evm.BlockNumber) {
|
if evm.ChainConfig().IsEIP158(evm.BlockNumber) {
|
||||||
evm.StateDB.SetNonce(contractAddr, 1)
|
evm.StateDB.SetNonce(contractAddr, 1)
|
||||||
}
|
}
|
||||||
evm.Transfer(evm.StateDB, caller.Address(), contractAddr, value)
|
evm.Transfer(evm.StateDB, caller.Address(), contractAddr, value)
|
||||||
|
//向合约账户转账,但transfer()具体实现未找到
|
||||||
|
// 还有一个core/evm.go 包含静态方法
|
||||||
|
//value即为amount
|
||||||
// initialise a new contract and set the code that is to be used by the
|
// initialise a new contract and set the code that is to be used by the
|
||||||
// E The contract is a scoped evmironment for this execution context
|
// E The contract is a scoped evmironment for this execution context
|
||||||
// only.
|
// only.
|
||||||
|
|
@ -351,11 +353,11 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
|
||||||
}
|
}
|
||||||
|
|
||||||
if evm.vmConfig.Debug && evm.depth == 0 {
|
if evm.vmConfig.Debug && evm.depth == 0 {
|
||||||
evm.vmConfig.Tracer.CaptureStart(caller.Address(), contractAddr, true, code, gas, value)
|
evm.vmConfig.Tracer.CaptureStart(caller.Address(), contractAddr, true, code, gas, value) // contract.code为caller.Address?
|
||||||
}
|
}
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
ret, err = run(evm, contract, nil)
|
ret, err = run(evm, contract, nil) //开始执行code
|
||||||
|
|
||||||
// check whether the max code size has been exceeded
|
// check whether the max code size has been exceeded
|
||||||
maxCodeSizeExceeded := evm.ChainConfig().IsEIP158(evm.BlockNumber) && len(ret) > params.MaxCodeSize
|
maxCodeSizeExceeded := evm.ChainConfig().IsEIP158(evm.BlockNumber) && len(ret) > params.MaxCodeSize
|
||||||
|
|
|
||||||
|
|
@ -1087,7 +1087,7 @@ func (s *PublicTransactionPoolAPI) sign(addr common.Address, tx *types.Transacti
|
||||||
// Look up the wallet containing the requested signer
|
// Look up the wallet containing the requested signer
|
||||||
account := accounts.Account{Address: addr}
|
account := accounts.Account{Address: addr}
|
||||||
|
|
||||||
wallet, err := s.b.AccountManager().Find(account)
|
wallet, err := s.b.AccountManager().Find(account) //manage.go Find attempts to locate the wallet corresponding to a specific account
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1193,7 +1193,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
|
||||||
// Look up the wallet containing the requested signer
|
// Look up the wallet containing the requested signer
|
||||||
account := accounts.Account{Address: args.From}
|
account := accounts.Account{Address: args.From}
|
||||||
|
|
||||||
wallet, err := s.b.AccountManager().Find(account)
|
wallet, err := s.b.AccountManager().Find(account) // accounts/manage.go Find attempts to locate the wallet corresponding to a specific account
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
@ -1201,7 +1201,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
|
||||||
if args.Nonce == nil {
|
if args.Nonce == nil {
|
||||||
// Hold the addresse's mutex around signing to prevent concurrent assignment of
|
// Hold the addresse's mutex around signing to prevent concurrent assignment of
|
||||||
// the same nonce to multiple accounts.
|
// the same nonce to multiple accounts.
|
||||||
s.nonceLock.LockAddr(args.From)
|
s.nonceLock.LockAddr(args.From)
|
||||||
defer s.nonceLock.UnlockAddr(args.From)
|
defer s.nonceLock.UnlockAddr(args.From)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1213,11 +1213,10 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
|
||||||
tx := args.toTransaction()
|
tx := args.toTransaction()
|
||||||
|
|
||||||
var chainID *big.Int
|
var chainID *big.Int
|
||||||
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) {
|
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) { // param/config.go type/Block.go
|
||||||
chainID = config.ChainId
|
chainID = config.ChainId //Choose fork
|
||||||
}
|
}
|
||||||
signed, err := wallet.SignTx(account, tx, chainID)
|
signed, err := wallet.SignTx(account, tx, chainID) // accounts/acount.go wallet.go
|
||||||
if err != nil {
|
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
return submitTransaction(ctx, s.b, signed)
|
return submitTransaction(ctx, s.b, signed)
|
||||||
|
|
@ -1267,6 +1266,8 @@ type SignTransactionResult struct {
|
||||||
// SignTransaction will sign the given transaction with the from account.
|
// SignTransaction will sign the given transaction with the from account.
|
||||||
// The node needs to have the private key of the account corresponding with
|
// The node needs to have the private key of the account corresponding with
|
||||||
// the given from address and it needs to be unlocked.
|
// the given from address and it needs to be unlocked.
|
||||||
|
|
||||||
|
//对发送来的交易进行签名
|
||||||
func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) {
|
func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) {
|
||||||
if args.Gas == nil {
|
if args.Gas == nil {
|
||||||
return nil, fmt.Errorf("gas not specified")
|
return nil, fmt.Errorf("gas not specified")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue