Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuRa system calls to Certifier should be const #5929

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions cmd/state/exec3/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ func (rw *Worker22) RunTxTask(txTask *state.TxTask) {
systemcontracts.UpgradeBuildInSystemContract(rw.chainConfig, header.Number, ibs)
}
syscall := func(contract common.Address, data []byte) ([]byte, error) {
return core.SysCallContract(contract, data, *rw.chainConfig, ibs, header, rw.engine)
return core.SysCallContract(contract, data, *rw.chainConfig, ibs, header, rw.engine, false /* constCall */)
}
rw.engine.Initialize(rw.chainConfig, rw.chain, rw.epoch, header, txTask.Txs, txTask.Uncles, syscall)
} else if txTask.Final {
if txTask.BlockNum > 0 {
//fmt.Printf("txNum=%d, blockNum=%d, finalisation of the block\n", txTask.TxNum, txTask.BlockNum)
// End of block transaction in a block
syscall := func(contract common.Address, data []byte) ([]byte, error) {
return core.SysCallContract(contract, data, *rw.chainConfig, ibs, header, rw.engine)
return core.SysCallContract(contract, data, *rw.chainConfig, ibs, header, rw.engine, false /* constCall */)
}
if _, _, err := rw.engine.Finalize(rw.chainConfig, header, ibs, txTask.Txs, txTask.Uncles, nil /* receipts */, rw.epoch, rw.chain, syscall); err != nil {
//fmt.Printf("error=%v\n", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/state/exec3/state_recon.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (rw *ReconWorker) runTxTask(txTask *state2.TxTask) {
//fmt.Printf("txNum=%d, blockNum=%d, finalisation of the block\n", txNum, blockNum)
// End of block transaction in a block
syscall := func(contract common.Address, data []byte) ([]byte, error) {
return core.SysCallContract(contract, data, *rw.chainConfig, ibs, txTask.Header, rw.engine)
return core.SysCallContract(contract, data, *rw.chainConfig, ibs, txTask.Header, rw.engine, false /* constCall */)
}
if _, _, err := rw.engine.Finalize(rw.chainConfig, txTask.Header, ibs, txTask.Txs, txTask.Uncles, nil /* receipts */, rw.epoch, rw.chain, syscall); err != nil {
panic(fmt.Errorf("finalize of block %d failed: %w", txTask.BlockNum, err))
Expand All @@ -327,7 +327,7 @@ func (rw *ReconWorker) runTxTask(txTask *state2.TxTask) {
systemcontracts.UpgradeBuildInSystemContract(rw.chainConfig, txTask.Header.Number, ibs)
}
syscall := func(contract common.Address, data []byte) ([]byte, error) {
return core.SysCallContract(contract, data, *rw.chainConfig, ibs, txTask.Header, rw.engine)
return core.SysCallContract(contract, data, *rw.chainConfig, ibs, txTask.Header, rw.engine, false /* constCall */)
}

rw.engine.Initialize(rw.chainConfig, rw.chain, rw.epoch, txTask.Header, txTask.Txs, txTask.Uncles, syscall)
Expand Down
10 changes: 5 additions & 5 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func ExecuteBlockEphemerallyForBSC(
// otherwise it causes block verification error.
header.GasUsed = *usedGas
syscall := func(contract common.Address, data []byte) ([]byte, error) {
return SysCallContract(contract, data, *chainConfig, ibs, header, engine)
return SysCallContract(contract, data, *chainConfig, ibs, header, engine, false /* constCall */)
}
outTxs, outReceipts, err := engine.Finalize(chainConfig, header, ibs, block.Transactions(), block.Uncles(), receipts, epochReader, chainReader, syscall)
if err != nil {
Expand Down Expand Up @@ -464,7 +464,7 @@ func rlpHash(x interface{}) (h common.Hash) {
return h
}

func SysCallContract(contract common.Address, data []byte, chainConfig params.ChainConfig, ibs *state.IntraBlockState, header *types.Header, engine consensus.Engine) (result []byte, err error) {
func SysCallContract(contract common.Address, data []byte, chainConfig params.ChainConfig, ibs *state.IntraBlockState, header *types.Header, engine consensus.Engine, constCall bool) (result []byte, err error) {
if chainConfig.DAOForkSupport && chainConfig.DAOForkBlock != nil && chainConfig.DAOForkBlock.Cmp(header.Number) == 0 {
misc.ApplyDAOHardFork(ibs)
}
Expand All @@ -478,7 +478,7 @@ func SysCallContract(contract common.Address, data []byte, chainConfig params.Ch
data, nil, false,
true, // isFree
)
vmConfig := vm.Config{NoReceipts: true}
vmConfig := vm.Config{NoReceipts: true, RestoreState: constCall}
// Create a new context to be used in the EVM environment
isBor := chainConfig.Bor != nil
var txContext vm.TxContext
Expand Down Expand Up @@ -548,7 +548,7 @@ func FinalizeBlockExecution(engine consensus.Engine, stateReader state.StateRead
receipts types.Receipts, e consensus.EpochReader, headerReader consensus.ChainHeaderReader, isMining bool,
) (newBlock *types.Block, newTxs types.Transactions, newReceipt types.Receipts, err error) {
syscall := func(contract common.Address, data []byte) ([]byte, error) {
return SysCallContract(contract, data, *cc, ibs, header, engine)
return SysCallContract(contract, data, *cc, ibs, header, engine, false /* constCall */)
}
if isMining {
newBlock, newTxs, newReceipt, err = engine.FinalizeAndAssemble(cc, header, ibs, txs, uncles, receipts, e, headerReader, syscall, nil)
Expand All @@ -571,7 +571,7 @@ func FinalizeBlockExecution(engine consensus.Engine, stateReader state.StateRead

func InitializeBlockExecution(engine consensus.Engine, chain consensus.ChainHeaderReader, epochReader consensus.EpochReader, header *types.Header, txs types.Transactions, uncles []*types.Header, cc *params.ChainConfig, ibs *state.IntraBlockState) error {
engine.Initialize(cc, chain, epochReader, header, txs, uncles, func(contract common.Address, data []byte) ([]byte, error) {
return SysCallContract(contract, data, *cc, ibs, header, engine)
return SysCallContract(contract, data, *cc, ibs, header, engine, false /* constCall */)
})
noop := state.NewNoopWriter()
ibs.FinalizeTx(cc.Rules(header.Number.Uint64()), noop)
Expand Down
2 changes: 1 addition & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func applyTransaction(config *params.ChainConfig, engine consensus.Engine, gp *G

if engine != nil {
syscall := func(contract common.Address, data []byte) ([]byte, error) {
return SysCallContract(contract, data, *config, ibs, header, engine)
return SysCallContract(contract, data, *config, ibs, header, engine, true /* constCall */)
}
msg.SetIsFree(engine.IsServiceTransaction(msg.From(), syscall))
}
Expand Down
8 changes: 4 additions & 4 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
// When an error was returned by the EVM or when setting the creation code
// above we revert to the snapshot and consume any gas remaining. Additionally
// when we're in homestead this also counts for code storage gas errors.
if err != nil {
if err != nil || evm.config.RestoreState {
evm.intraBlockState.RevertToSnapshot(snapshot)
if err != ErrExecutionReverted {
gas = 0
Expand Down Expand Up @@ -311,7 +311,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
gas = contract.Gas
}
}
if err != nil {
if err != nil || evm.config.RestoreState {
evm.intraBlockState.RevertToSnapshot(snapshot)
if err != ErrExecutionReverted {
gas = 0
Expand Down Expand Up @@ -362,7 +362,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
gas = contract.Gas
}
}
if err != nil {
if err != nil || evm.config.RestoreState {
evm.intraBlockState.RevertToSnapshot(snapshot)
if err != ErrExecutionReverted {
gas = 0
Expand Down Expand Up @@ -429,7 +429,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
gas = contract.Gas
}
}
if err != nil {
if err != nil || evm.config.RestoreState {
evm.intraBlockState.RevertToSnapshot(snapshot)
if err != ErrExecutionReverted {
gas = 0
Expand Down
1 change: 1 addition & 0 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Config struct {
NoReceipts bool // Do not calculate receipts
ReadOnly bool // Do no perform any block finalisation
StatelessExec bool // true is certain conditions (like state trie root hash matching) need to be relaxed for stateless EVM execution
RestoreState bool // Revert all changes made to the state (useful for constant system calls)

ExtraEips []int // Additional EIPS that are to be enabled
}
Expand Down