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

remove unnecessary function #478

Merged
merged 1 commit into from
Feb 14, 2023
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
17 changes: 12 additions & 5 deletions params/precompile_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ func (c *ChainConfig) ConfigurePrecompiles(parentTimestamp *big.Int, blockContex
// so that the state is deterministic.
for _, module := range precompile.RegisteredModules() {
key := module.Key()
for _, config := range c.getActivatingPrecompileConfigs(module.Address(), parentTimestamp, blockTimestamp, c.PrecompileUpgrades) {
for _, precompileConfig := range c.getActivatingPrecompileConfigs(module.Address(), parentTimestamp, blockTimestamp, c.PrecompileUpgrades) {
// If this transition activates the upgrade, configure the stateful precompile.
// (or deconfigure it if it is being disabled.)
if config.IsDisabled() {
if precompileConfig.IsDisabled() {
log.Info("Disabling precompile", "name", key)
statedb.Suicide(module.Address())
// Calling Finalise here effectively commits Suicide call and wipes the contract state.
Expand All @@ -285,9 +285,16 @@ func (c *ChainConfig) ConfigurePrecompiles(parentTimestamp *big.Int, blockContex
// since Suicide will be committed after the reconfiguration.
statedb.Finalise(true)
} else {
log.Info("Activating new precompile", "name", key, "config", config)
if err := precompile.Configure(c, blockContext, config, statedb); err != nil {
return fmt.Errorf("could not configure precompile, name: %s, reason: %w", key, err)
log.Info("Activating new precompile", "name", key, "config", precompileConfig)
// Set the nonce of the precompile's address (as is done when a contract is created) to ensure
// that it is marked as non-empty and will not be cleaned up when the statedb is finalized.
statedb.SetNonce(precompileConfig.Address(), 1)
// Set the code of the precompile's address to a non-zero length byte slice to ensure that the precompile
// can be called from within Solidity contracts. Solidity adds a check before invoking a contract to ensure
// that it does not attempt to invoke a non-existent contract.
statedb.SetCode(precompileConfig.Address(), []byte{0x1})
if err := precompileConfig.Configure(c, statedb, blockContext); err != nil {
return fmt.Errorf("could not configure precompile, key: %s, reason: %w", key, err)
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions precompile/stateful_precompile_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,3 @@ type StatefulPrecompileConfig interface {
// its own address space.
Configure(ChainConfig, StateDB, BlockContext) error
}

// Configure sets the nonce and code to non-empty values then calls Configure on [precompileConfig] to make the necessary
// state update to enable the StatefulPrecompile.
// Assumes that [precompileConfig] is non-nil.
func Configure(chainConfig ChainConfig, blockContext BlockContext, precompileConfig StatefulPrecompileConfig, state StateDB) error {
// Set the nonce of the precompile's address (as is done when a contract is created) to ensure
// that it is marked as non-empty and will not be cleaned up when the statedb is finalized.
state.SetNonce(precompileConfig.Address(), 1)
// Set the code of the precompile's address to a non-zero length byte slice to ensure that the precompile
// can be called from within Solidity contracts. Solidity adds a check before invoking a contract to ensure
// that it does not attempt to invoke a non-existent contract.
state.SetCode(precompileConfig.Address(), []byte{0x1})
return precompileConfig.Configure(chainConfig, state, blockContext)
}