Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Oct 2, 2024
1 parent df98c4e commit 8e223b9
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 32 deletions.
4 changes: 2 additions & 2 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (b *BlockGen) addTx(bc *BlockChain, vmConfig vm.Config, tx *types.Transacti
// instruction will panic during execution if it attempts to access a block number outside
// of the range created by GenerateChain.
func (b *BlockGen) AddTx(tx *types.Transaction) {
b.addTx(&BlockChain{chainConfig: params.TestChainConfig}, vm.Config{}, tx)
b.addTx(nil, vm.Config{}, tx)
}

// AddTxWithChain adds a transaction to the generated block. If no coinbase has
Expand All @@ -164,7 +164,7 @@ func (b *BlockGen) AddTxWithChain(bc *BlockChain, tx *types.Transaction) {
// been set, the block's coinbase is set to the zero address.
// The evm interpreter can be customized with the provided vm config.
func (b *BlockGen) AddTxWithVMConfig(tx *types.Transaction, config vm.Config) {
b.addTx(&BlockChain{chainConfig: params.TestChainConfig}, config, tx)
b.addTx(nil, config, tx)
}

// GetBalance returns the balance of the given address at the generated block.
Expand Down
2 changes: 0 additions & 2 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ type ChainContext interface {

// GetHeader returns the header corresponding to the hash/number argument pair.
GetHeader(common.Hash, uint64) *types.Header

Config() *params.ChainConfig
}

// NewEVMBlockContext creates a new context for use in the EVM.
Expand Down
3 changes: 2 additions & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ func (st *StateTransition) buyGas() error {
return nil
}

// XXX: Probably should be its own hook
// TODO: Probably can be removed -- extremely unlikely someone has private keys
// to known hashes.
// IsProhibited returns true if [addr] is in the prohibited list of addresses which should
// not be allowed as an EOA or newly created contract address.
func IsProhibited(addr common.Address) bool {
Expand Down
5 changes: 0 additions & 5 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,6 @@ func (diff *BlockOverrides) Apply(blockCtx *vm.BlockContext) {
type ChainContextBackend interface {
Engine() consensus.Engine
HeaderByNumber(context.Context, rpc.BlockNumber) (*types.Header, error)
ChainConfig() *params.ChainConfig
}

// ChainContext is an implementation of core.ChainContext. It's main use-case
Expand All @@ -1063,10 +1062,6 @@ func NewChainContext(ctx context.Context, backend ChainContextBackend) *ChainCon
return &ChainContext{ctx: ctx, b: backend}
}

func (context *ChainContext) Config() *params.ChainConfig {
return context.b.ChainConfig()
}

func (context *ChainContext) Engine() consensus.Engine {
return context.b.Engine()
}
Expand Down
2 changes: 0 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,4 @@ type RulesExtra struct {
// AccepterPrecompiles map addresses to stateful precompile accepter functions
// that are enabled for this rule set.
AccepterPrecompiles map[common.Address]precompileconfig.Accepter

gethparams.NOOPHooks // XXX: Embedded to ensure that Rules implements params.RulesHooks
}
4 changes: 2 additions & 2 deletions params/config_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
const (
maxJSONLen = 64 * 1024 * 1024 // 64MB

// XXX: Value to pass to geth's Rules by default where the appropriate
// TODO: Value to pass to geth's Rules by default where the appropriate
// context is not available in the avalanche code. (similar to context.TODO())
IsMergeTODO = true
)
Expand Down Expand Up @@ -91,7 +91,7 @@ type ChainConfigWithUpgradesJSON struct {
// ChainConfig struct.
func (cu ChainConfigWithUpgradesJSON) MarshalJSON() ([]byte, error) {
// embed the ChainConfig struct into the response
chainConfigJSON, err := json.Marshal(&cu.ChainConfig) // XXX: Marshal should be defined on value receiver?
chainConfigJSON, err := json.Marshal(&cu.ChainConfig)
if err != nil {
return nil, err
}
Expand Down
29 changes: 12 additions & 17 deletions params/hooks_libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ var PredicateParser = func(extra []byte) (PredicateResults, error) {
return nil, nil
}

func (r RulesExtra) JumpTable() interface{} {
// XXX: This does not account for the any possible differences in EIP-3529
// Do not merge without verifying.
return nil
}

func (r RulesExtra) CanCreateContract(ac *libevm.AddressContext, gas uint64, state libevm.StateReader) (uint64, error) {
// IsProhibited
if ac.Self == constants.BlackholeAddr || modules.ReservedAddress(ac.Self) {
Expand All @@ -40,6 +34,10 @@ func (r RulesExtra) CanCreateContract(ac *libevm.AddressContext, gas uint64, sta
return gas, nil
}

func (r RulesExtra) CanExecuteTransaction(_ common.Address, _ *common.Address, _ libevm.StateReader) error {
return nil
}

var PrecompiledContractsApricotPhase2 = map[common.Address]contract.StatefulPrecompiledContract{
nativeasset.GenesisContractAddr: &nativeasset.DeprecatedContract{},
nativeasset.NativeAssetBalanceAddr: &nativeasset.NativeAssetBalance{GasCost: AssetBalanceApricot},
Expand Down Expand Up @@ -117,15 +115,7 @@ func makePrecompile(contract contract.StatefulPrecompiledContract) libevm.Precom
if err != nil {
panic(err) // Should never happen, because predicates are parsed in NewEVMBlockContext.
}
// XXX: this should be moved to the precompiles
var state libevm.StateReader
if env.ReadOnly() {
state = env.ReadOnlyState()
} else {
state = env.StateDB()
}
accessableState := accessableState{
StateReader: state,
env: env,
chainConfig: GetRulesExtra(env.Rules()).chainConfig,
blockContext: &BlockContext{
Expand Down Expand Up @@ -155,15 +145,20 @@ func (r RulesExtra) PrecompileOverride(addr common.Address) (libevm.PrecompiledC
}

type accessableState struct {
libevm.StateReader
env vm.PrecompileEnvironment
chainConfig *gethparams.ChainConfig
blockContext *BlockContext
}

func (a accessableState) GetStateDB() contract.StateDB {
// XXX: Whoa, this is a hack
return a.StateReader.(contract.StateDB)
// XXX: this should be moved to the precompiles
var state libevm.StateReader
if a.env.ReadOnly() {
state = a.env.ReadOnlyState()
} else {
state = a.env.StateDB()
}
return state.(contract.StateDB)
}

func (a accessableState) GetBlockContext() contract.BlockContext {
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests.e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ git checkout -B "test-${AVALANCHE_VERSION}" "${AVALANCHE_VERSION}"

echo "updating coreth dependency to point to ${CORETH_PATH}"
go mod edit -replace "github.com/ava-labs/coreth=${CORETH_PATH}"
go mod edit -replace "github.com/ethereum/go-ethereum=github.com/ava-labs/[email protected]20240927183738-d8757174b3f0"
go mod edit -replace "github.com/ethereum/go-ethereum=github.com/ava-labs/[email protected]20241001233245-6e652ebfd8b6"
go mod tidy

echo "building avalanchego"
Expand Down

0 comments on commit 8e223b9

Please sign in to comment.