Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
16c9de9
Rename core.BlockContext to core.SysContractCallCtx
37ng Sep 20, 2021
6b24416
Add SCCC to miner/blockState
37ng Sep 20, 2021
ce1a32f
Add SCCC to stateProcessor.Process() & ApplyTransaction()
37ng Sep 20, 2021
007d4bc
Rename core.BlockContext to core.SysContractCallCtx(continued)
37ng Sep 20, 2021
ead3191
Put placeholders in tests
37ng Sep 20, 2021
4de200c
Remove redundant params in applyTransaction
37ng Sep 20, 2021
7d7ee88
Address comments
37ng Sep 22, 2021
f3e05ea
Add sccc to statePrefetcher
37ng Sep 23, 2021
b0976bf
Add sccc to state_accessor.go
37ng Sep 23, 2021
db5cb7f
bug: fix nil map
37ng Sep 24, 2021
a42e3de
No nil map at initialization
37ng Sep 24, 2021
58073ce
Fix TestEIP2718Transition
37ng Sep 27, 2021
d6cba0e
Fix TestEIP1559Transition
37ng Sep 28, 2021
bdc977a
Remove fmt.Println()
37ng Sep 28, 2021
4c8f29a
Remove nil check for whitelistedCurrencies
37ng Sep 29, 2021
58d6877
Fix TestStateProcessorErrors
37ng Oct 1, 2021
d50bff1
Fix bug in precheck()
37ng Oct 4, 2021
64a0768
Make TestStateProcessorErrors more strict
37ng Oct 5, 2021
dd930e3
fix fee comparison
37ng Oct 5, 2021
c2fea08
Fix lint
37ng Oct 5, 2021
00b39f2
Slippery lint
37ng Oct 5, 2021
25af966
Fix TestEIP2718Transition
37ng Oct 6, 2021
d1f395e
Fix ExampleGenerateChain
37ng Oct 6, 2021
067d38d
Put Faker check inside espresso check
37ng Oct 7, 2021
2e25ec4
Fix TestOverriddenTraceCall: Test 1
37ng Oct 7, 2021
6635f75
Fix TestGraphQLBlockSerializationEIP2718
37ng Oct 7, 2021
014067c
Make mockSysContractCallCtx() public
37ng Oct 7, 2021
c37de4c
one giant leap for mankind
37ng Oct 7, 2021
5ca6069
Fix ExampleGenerateChain
37ng Oct 7, 2021
d04fd84
Fix TestEIP1559Transition
37ng Oct 7, 2021
f812cfc
Change GetGasPriceMinimum signature: remove err in return
37ng Oct 7, 2021
f5f1b8a
nits
37ng Oct 8, 2021
98466cd
Fix SCCC
37ng Oct 12, 2021
789907c
Provide sysCtx in tracer/api.go
37ng Oct 12, 2021
522b075
lint
37ng Oct 12, 2021
c06e1cc
make calls at initialization
37ng Oct 12, 2021
fdb7d4a
Merge branch 'trianglesphere/work' into tong/sccc
37ng Oct 12, 2021
5d6164c
Remove vmRunner from SysContractCallCtx
37ng Oct 13, 2021
1c87509
Populate sysCtx in DoCall
37ng Oct 14, 2021
b01cad2
Populate sysCtx in (leth *LightEthereum) stateAtTransaction
37ng Oct 14, 2021
d1e1e1c
Remove redundant stateDB.Copy()
37ng Oct 14, 2021
9650668
Remove: nolint will fix in 1559 activation
37ng Oct 14, 2021
1447a78
Update cip-0045
37ng Oct 14, 2021
34e1031
header.Number
37ng Oct 14, 2021
f0709a9
Fix TestStateProcessorErrors
37ng Oct 15, 2021
a8d7731
Remove eHardfork from distributeTxFees()
37ng Oct 15, 2021
bca75e8
Refactor canPayFee
37ng Oct 19, 2021
6875f85
Fix TestOverriddenTraceCall
37ng Oct 19, 2021
a82eeb5
Refactor canPayFee
37ng Oct 19, 2021
85f0482
Revert "Refactor canPayFee"
37ng Oct 19, 2021
b896eb5
Align comment with code structure
37ng Oct 19, 2021
4095d4d
Update comment
37ng Oct 19, 2021
a201f10
Check GatewayFeeRecipient, and refactor
37ng Oct 19, 2021
c53c6bf
wip
37ng Oct 27, 2021
0527886
Libraries
37ng Oct 27, 2021
6c7f770
Fix TestEIP1559Transition
37ng Oct 27, 2021
4838c78
Merge commit '6c7f770cc' into tong/sccc
37ng Oct 27, 2021
31129ec
Clean up
37ng Oct 27, 2021
7daf5a0
nits
37ng Oct 27, 2021
c01718b
nit
37ng Oct 27, 2021
903891d
Remove genesis.json
37ng Oct 27, 2021
3656f66
Make tx_pool consistent with state_transition
37ng Oct 27, 2021
5a550be
Renaming in ValidateTransactorBalanceCoversTx
37ng Oct 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,16 +607,24 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
// Execute the call.
msg := callMsg{call}

txContext := core.NewEVMTxContext(msg)
evmContext := core.NewEVMBlockContext(block.Header(), b.blockchain, nil)
// Create a new environment which holds all relevant information
// about the transaction and calling mechanisms.
txContext := core.NewEVMTxContext(msg)
evmContext := core.NewEVMBlockContext(block.Header(), b.blockchain, nil)
vmEnv := vm.NewEVM(evmContext, txContext, stateDB, b.config, vm.Config{NoBaseFee: true})
gasPool := new(core.GasPool).AddGas(math.MaxUint64)

vmRunner := b.blockchain.NewEVMRunner(block.Header(), stateDB)

return core.NewStateTransition(vmEnv, msg, gasPool, vmRunner).TransitionDb()
var sysCtx *core.SysContractCallCtx
if b.config.IsEHardfork(block.Number()) {
parent := b.blockchain.GetBlockByNumber(block.NumberU64() - 1)
sysStateDB, err := b.blockchain.StateAt(parent.Root())
if err != nil {
return nil, err
}
sysVmRunner := b.blockchain.NewEVMRunner(block.Header(), sysStateDB)
sysCtx = core.NewSysContractCallCtx(sysVmRunner)
}
return core.NewStateTransition(vmEnv, msg, gasPool, vmRunner, sysCtx).TransitionDb()
}

// SendTransaction updates the pending block to include the given transaction.
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,

// FIXME this is broken
// (ret []byte, usedGas uint64, failed bool, err error)
msgResult, err := core.ApplyMessage(evm, msg, gaspool, nil)
msgResult, err := core.ApplyMessage(evm, msg, gaspool, nil, &core.SysContractCallCtx{})
if err != nil {
statedb.RevertToSnapshot(snapshot)
log.Info("rejected tx", "index", i, "hash", tx.Hash(), "from", msg.From(), "error", err)
Expand Down
2 changes: 2 additions & 0 deletions contracts/gasprice_minimum/gasprice_minimum.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/celo-org/celo-blockchain/params"
)

// Gas price minimum serves as baseFee(EIP1559) after Espresso HF.

var (
FallbackGasPriceMinimum *big.Int = big.NewInt(0) // gas price minimum to return if unable to fetch from contract
suggestionMultiplier *big.Int = big.NewInt(5) // The multiplier that we apply to the minimum when suggesting gas price
Expand Down
53 changes: 0 additions & 53 deletions core/block_context.go

This file was deleted.

45 changes: 31 additions & 14 deletions core/blockchain_test.go

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,23 @@ func (b *BlockGen) AddTxWithChain(bc ChainContext, tx *types.Transaction) {
b.statedb.Prepare(tx.Hash(), len(b.txs))

celoMock := testutil.NewCeloMock()
receipt, err := ApplyTransaction(b.config, bc, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, &b.header.GasUsed, vm.Config{}, celoMock.Runner)

receipt, err := ApplyTransaction(b.config, bc, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, &b.header.GasUsed, vm.Config{}, celoMock.Runner, MockSysContractCallCtx())
if err != nil {
panic(err)
}
b.txs = append(b.txs, tx)
b.receipts = append(b.receipts, receipt)
}

// MockSysContractCallCtx returns a SysContractCallCtx mock.
func MockSysContractCallCtx() *SysContractCallCtx {
return &SysContractCallCtx{
// Set common.ZeroAddress to non-zero value to test on proper base fee distribution
gasPriceMinimums: map[common.Address]*big.Int{common.ZeroAddress: common.Big3},
}
}

// GetBalance returns the balance of the given address at the generated block.
func (b *BlockGen) GetBalance(addr common.Address) *big.Int {
return b.statedb.GetBalance(addr)
Expand Down
4 changes: 0 additions & 4 deletions core/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ var (
// minimum specified by the GasPriceMinimum contract.
ErrGasPriceDoesNotExceedMinimum = errors.New("gasprice is less than gas price minimum")

// ErrInsufficientFundsForFees is returned if the account does have enough funds (in the
// fee currency used for the transaction) to pay for the gas.
ErrInsufficientFundsForFees = errors.New("insufficient funds to pay for fees")

// ErrNonWhitelistedFeeCurrency is returned if the currency specified to use for the fees
// isn't one of the currencies whitelisted for that purpose.
ErrNonWhitelistedFeeCurrency = errors.New("non-whitelisted fee currency address")
Expand Down
17 changes: 15 additions & 2 deletions core/state_prefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,25 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
header = block.Header()
vmRunner = p.bc.NewEVMRunner(header, statedb)
gaspool = new(GasPool).AddGas(blockchain_parameters.GetBlockGasLimitOrDefault(vmRunner))
baseFee *big.Int // TODO: gas price minimum
baseFee *big.Int
sysCtx *SysContractCallCtx
)
// Iterate over and process the individual transactions
byzantium := p.config.IsByzantium(block.Number())
espresso := p.bc.chainConfig.IsEHardfork(block.Number())
if espresso {
sysCtx = NewSysContractCallCtx(p.bc.NewEVMRunner(header, statedb))
}
for i, tx := range block.Transactions() {
// If block precaching was interrupted, abort
if interrupt != nil && atomic.LoadUint32(interrupt) == 1 {
return
}
// Block precaching permitted to continue, execute the transaction
statedb.Prepare(tx.Hash(), i)
if espresso {
baseFee = sysCtx.GetGasPriceMinimum(tx.FeeCurrency())
}
if err := precacheTransaction(p.config, p.bc, nil, gaspool, statedb, header, tx, cfg, baseFee); err != nil {
return // Ugh, something went horribly wrong, bail out
}
Expand Down Expand Up @@ -94,6 +102,11 @@ func precacheTransaction(config *params.ChainConfig, bc *BlockChain, author *com
txContext := NewEVMTxContext(msg)
vm := vm.NewEVM(context, txContext, statedb, config, cfg)

_, err = ApplyMessage(vm, msg, gaspool, bc.NewEVMRunner(header, statedb))
var sysCtx *SysContractCallCtx
if config.IsEHardfork(header.Number) {
sysVmRunner := bc.NewEVMRunner(header, statedb)
sysCtx = NewSysContractCallCtx(sysVmRunner)
}
_, err = ApplyMessage(vm, msg, gaspool, bc.NewEVMRunner(header, statedb), sysCtx)
return err
}
34 changes: 25 additions & 9 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,30 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
statedb.IntermediateRoot(true)
}

var (
baseFee *big.Int
sysCtx *SysContractCallCtx
)
if p.bc.Config().IsEHardfork(blockNumber) {
sysVmRunner := p.bc.NewEVMRunner(header, statedb)
sysCtx = NewSysContractCallCtx(sysVmRunner)
if p.bc.Config().Faker {
sysCtx = MockSysContractCallCtx()
}
}
blockContext := NewEVMBlockContext(header, p.bc, nil)
var gpm *big.Int // collect basefee from blockContext or somewhere else
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg)
// Iterate over and process the individual transactions
for i, tx := range block.Transactions() {
msg, err := tx.AsMessage(types.MakeSigner(p.config, header.Number), gpm)
if p.bc.chainConfig.IsEHardfork(header.Number) {
baseFee = sysCtx.GetGasPriceMinimum(tx.FeeCurrency())
}
msg, err := tx.AsMessage(types.MakeSigner(p.config, header.Number), baseFee)
if err != nil {
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
}
statedb.Prepare(tx.Hash(), i)
receipt, err := applyTransaction(msg, p.config, p.bc, nil, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv, vmRunner)
receipt, err := applyTransaction(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv, vmRunner, sysCtx)
if err != nil {
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
}
Expand All @@ -107,7 +120,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
return receipts, allLogs, *usedGas, nil
}

func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainContext, txFeeRecipient *common.Address, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM, vmRunner vm.EVMRunner) (*types.Receipt, error) {
func applyTransaction(msg types.Message, config *params.ChainConfig, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM, vmRunner vm.EVMRunner, sysCtx *SysContractCallCtx) (*types.Receipt, error) {
if config.IsDonut(blockNumber) && !tx.Protected() {
return nil, ErrUnprotectedTransaction
}
Expand All @@ -117,7 +130,7 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
evm.Reset(txContext, statedb)

// Apply the transaction to the current state (included in the env).
result, err := ApplyMessage(evm, msg, gp, vmRunner)
result, err := ApplyMessage(evm, msg, gp, vmRunner, sysCtx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -160,14 +173,17 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
// and uses the input parameters for its environment. It returns the receipt
// for the transaction, gas used and an error if the transaction failed,
// indicating the block was invalid.
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, txFeeRecipient *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config, vmRunner vm.EVMRunner) (*types.Receipt, error) {
// TODO(Joshua): Set appropriate GPM/basefee here
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number), nil)
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, txFeeRecipient *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config, vmRunner vm.EVMRunner, sysCtx *SysContractCallCtx) (*types.Receipt, error) {
var baseFee *big.Int
if config.IsEHardfork(header.Number) {
baseFee = sysCtx.GetGasPriceMinimum(tx.FeeCurrency())
}
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number), baseFee)
if err != nil {
return nil, err
}
// Create a new context to be used in the EVM environment
blockContext := NewEVMBlockContext(header, bc, txFeeRecipient)
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg)
return applyTransaction(msg, config, bc, txFeeRecipient, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv, vmRunner)
return applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv, vmRunner, sysCtx)
}
Loading