-
Notifications
You must be signed in to change notification settings - Fork 225
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
wip: use libevm (params, core/vm) #1335
base: master
Are you sure you want to change the base?
Conversation
95ce588
to
8574ab3
Compare
simplify nit: spelling
cc7d5e6
to
932967d
Compare
|
||
// Durango enables the Shanghai upgrade of eth, which takes place after the | ||
// Merge upgrade. | ||
isDurango := params.GetExtra(chain.Config()).IsDurango(header.Time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upstream avoids this dependency here (on chain config/rules) by checking if Difficulty is 0,
but we cannot rely on that because we already made blocks with difficulty set to 1.
chainConfig *gethparams.ChainConfig | ||
blockContext *BlockContext | ||
} | ||
|
||
func (a accessableState) GetStateDB() contract.StateDB { | ||
// XXX: Whoa, this is a hack | ||
return a.StateDB.(contract.StateDB) | ||
return a.StateReader.(contract.StateDB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just to make it compliant with an existing interface?
To guarantee that it's safe, without using the , ok
idiom you could:
var (
sr libevm.StateReader = a.StateReader
_ contract.StateDB = (libevm.StateReader)(nil) // prove that the next line won't panic
)
return sr.(contract.StateDB)
It's gross, but at least it's temporary!
@@ -695,6 +695,11 @@ func TestPrecompileBind(t *testing.T) { | |||
if out, err := replacer.CombinedOutput(); err != nil { | |||
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out) | |||
} | |||
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/[email protected]", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/[email protected]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason why we not directly use ava-labs/go-ethereum as directy dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module renaming is not ready yet, we will use it directly once it is ready.
@@ -205,7 +205,7 @@ func Transition(ctx *cli.Context) error { | |||
|
|||
func applyLondonChecks(env *stEnv, chainConfig *params.ChainConfig) error { | |||
// NOTE: IsLondon replaced with IsSubnetEVM here | |||
if !chainConfig.IsSubnetEVM(env.Timestamp) { | |||
if !params.GetExtra(chainConfig).IsSubnetEVM(env.Timestamp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should just use London here
@@ -80,7 +80,7 @@ func ReadChainConfig(db ethdb.KeyValueReader, hash common.Hash) *params.ChainCon | |||
if len(data) == 0 { | |||
return &config // return early if no upgrade config is found | |||
} | |||
if err := json.Unmarshal(data, &config.UpgradeConfig); err != nil { | |||
if err := json.Unmarshal(data, ¶ms.GetExtra(&config).UpgradeConfig); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we instead treat UpgradeConfig as a seperate struct and then set to configExtra? I assume config.UpgradeConfig initially should be empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean handling it entirely separately? I tried something like this here: #1351
@@ -75,17 +75,17 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types | |||
return fmt.Errorf("%w: transaction size %v, limit %v", ErrOversizedData, tx.Size(), opts.MaxSize) | |||
} | |||
// Ensure only transactions that have been enabled are accepted | |||
if !opts.Config.IsSubnetEVM(head.Time) && tx.Type() != types.LegacyTxType { | |||
if !params.GetExtra(opts.Config).IsSubnetEVM(head.Time) && tx.Type() != types.LegacyTxType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we rather use equivalent geth forks like london here?
} | ||
return sum | ||
} | ||
type AccessTuple = gethtypes.AccessTuple | ||
|
||
// AccessListTx is the data of EIP-2930 access list transactions. | ||
type AccessListTx struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we keep this as a seperate struct here?
} | ||
|
||
func (r *Rules) PredicatersExist() bool { | ||
func (r *RulesExtra) PredicatersExist() bool { | ||
// Methods on *RulesExtra handle nil receiver so params.Rules is an initialized struct. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in what case we call function on a nil pointer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is needed, removed it for now
func WithExtra(c *ChainConfig, extra *ChainConfigExtra) *ChainConfig { | ||
// XXX: Hack to initialize the ChainConfigExtra pointer in the ChainConfig. | ||
jsonBytes, err := json.Marshal(c) | ||
if err != nil { | ||
panic(err) | ||
} | ||
var newCfg ChainConfig | ||
if err := json.Unmarshal(jsonBytes, &newCfg); err != nil { | ||
panic(err) | ||
} | ||
|
||
*GetExtra(&newCfg) = *extra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit lost here. Why do we need to do marshal+unmarshaling? Also that setting double pointer with GetExtra seems too hacky. can we rather have a setter in libevm if we cannot initialize chainconfig without this? Maybe the whole WithExtra
thing can be moved to libevm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The marshal / unmarshal is no longer needed and we can use the SetOnChainConfig method here.
blockContext: &BlockContext{ | ||
number: env.BlockNumber(), | ||
time: env.BlockTime(), | ||
predicateResults: predicateResults, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems we have removed predicateResults from vm.BlockContext (in core), should we rather pass them with header.extra and let the consumer parse it?
var PredicateParser = func(extra []byte) (PredicateResults, error) { | ||
return nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a bit hard to follow this and weird to expect some other pkg to set this to the actual implementation.
@@ -27,7 +27,7 @@ func NewBlockValidator() BlockValidator { | |||
return &blockValidator{} | |||
} | |||
|
|||
func (v blockValidator) SyntacticVerify(b *Block, rules params.Rules) error { | |||
func (v blockValidator) SyntacticVerify(b *Block, rules_ params.Rules) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we rename rules_
to rules
and then below rules
to rulesExtra
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we also use this or create another as a base branch for libevm work? IMHO we should test these as a whole before merging to master. We can even constantly run a node with the libevm base branch.
initial attempt to use libevm params extensions