Skip to content

Commit

Permalink
Added doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed May 6, 2024
1 parent 1ba1bd1 commit 6fc8c91
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions x/evm/keeper/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type InitializationConfig struct {
Uninitialize []common.Address
}

// SyncEnabledPrecompiles is a keeper wrapper over the SyncEnabledPrecompiles function, which does most of the work.
func (k *Keeper) SyncEnabledPrecompiles(ctx sdk.Context, enabledPrecompiles []common.Address) error {
txConfig := statedb.TxConfig{
BlockHash: common.Hash{},
Expand All @@ -51,11 +52,19 @@ func (k *Keeper) SyncEnabledPrecompiles(ctx sdk.Context, enabledPrecompiles []co
return nil
}

// SyncEnabledPrecompiles takes enabled precompiles from old state and new state and performs following steps:
// - determines a list of contracts that must be validated and validates their state
// - determines a list of contracts that must be initialized and initializes them
// - determines a list of contracts that must be uninitialized and uninitializes them
func SyncEnabledPrecompiles(stateDB StateDB, old []common.Address, new []common.Address) error {
cfg := DetermineInitializationConfig(old, new)
return ApplyInitializationConfig(stateDB, cfg)
}

// DetermineInitializationConfig takes enabled precompiles from old state and new state and performs following steps:
// - determines a list of contracts that must be validated
// - determines a list of contracts that must be initialized
// - determines a list of contracts that must be uninitialized
func DetermineInitializationConfig(old []common.Address, new []common.Address) *InitializationConfig {
return &InitializationConfig{
ValidateInitialized: old,
Expand All @@ -65,6 +74,7 @@ func DetermineInitializationConfig(old []common.Address, new []common.Address) *
}
}

// ApplyInitializationConfig performs precompile initialization based on InitializationConfig.
func ApplyInitializationConfig(stateDB StateDB, cfg *InitializationConfig) error {
if err := ValidatePrecompilesInitialized(stateDB, cfg.ValidateInitialized); err != nil {
return err
Expand Down

0 comments on commit 6fc8c91

Please sign in to comment.