fix: adjust the timing of initializing Feynman system contracts (#2203)
* fix: adjust the timing of initializing Feynman system contracts * fix test case
This commit is contained in:
parent
e7cd04b38e
commit
fd0ee7d3e9
@ -360,7 +360,7 @@ func doLint(cmdline []string) {
|
||||
|
||||
// downloadLinter downloads and unpacks golangci-lint.
|
||||
func downloadLinter(cachedir string) string {
|
||||
const version = "1.52.2"
|
||||
const version = "1.55.2"
|
||||
|
||||
csdb := build.MustLoadChecksums("build/checksums.txt")
|
||||
arch := runtime.GOARCH
|
||||
|
@ -633,29 +633,19 @@ func blsAccountDelete(ctx *cli.Context) error {
|
||||
|
||||
// blsAccountGenerateProof generate ownership proof for a selected BLS account.
|
||||
func blsAccountGenerateProof(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 0 {
|
||||
utils.Fatalf("No BLS account specified.")
|
||||
pubkeyString := ctx.Args().First()
|
||||
if pubkeyString == "" {
|
||||
utils.Fatalf("BLS account must be given as argument.")
|
||||
}
|
||||
var filteredPubKeys []bls.PublicKey
|
||||
for _, str := range ctx.Args().Slice() {
|
||||
pkString := str
|
||||
if strings.Contains(pkString, "0x") {
|
||||
pkString = pkString[2:]
|
||||
}
|
||||
pubKeyBytes, err := hex.DecodeString(pkString)
|
||||
if err != nil {
|
||||
utils.Fatalf("Could not decode string %s as hex.", pkString)
|
||||
}
|
||||
blsPublicKey, err := bls.PublicKeyFromBytes(pubKeyBytes)
|
||||
if err != nil {
|
||||
utils.Fatalf("%#x is not a valid BLS public key.", pubKeyBytes)
|
||||
}
|
||||
filteredPubKeys = append(filteredPubKeys, blsPublicKey)
|
||||
pubkeyBz, err := hex.DecodeString(strings.TrimPrefix(pubkeyString, "0x"))
|
||||
if err != nil {
|
||||
utils.Fatalf("Could not decode string %s as hex.", pubkeyString)
|
||||
}
|
||||
if len(filteredPubKeys) > 1 {
|
||||
utils.Fatalf("Only support one BLS account specified.")
|
||||
blsPublicKey, err := bls.PublicKeyFromBytes(pubkeyBz)
|
||||
if err != nil {
|
||||
utils.Fatalf("%#x is not a valid BLS public key.", pubkeyBz)
|
||||
}
|
||||
pubkeyBz := filteredPubKeys[0].Marshal()
|
||||
blsPublicKeyBz := blsPublicKey.Marshal()
|
||||
|
||||
cfg := gethConfig{Node: defaultNodeConfig()}
|
||||
// Load config file.
|
||||
@ -692,10 +682,10 @@ func blsAccountGenerateProof(ctx *cli.Context) error {
|
||||
chainId := new(big.Int).SetInt64(chainIdInt64)
|
||||
paddedChainIdBytes := make([]byte, 32)
|
||||
copy(paddedChainIdBytes[32-len(chainId.Bytes()):], chainId.Bytes())
|
||||
msgHash := crypto.Keccak256(append(pubkeyBz, paddedChainIdBytes...))
|
||||
msgHash := crypto.Keccak256(append(blsPublicKeyBz, paddedChainIdBytes...))
|
||||
|
||||
req := &validatorpb.SignRequest{
|
||||
PublicKey: pubkeyBz,
|
||||
PublicKey: blsPublicKeyBz,
|
||||
SigningRoot: msgHash,
|
||||
}
|
||||
sig, err := km.Sign(context.Background(), req)
|
||||
|
@ -1136,6 +1136,13 @@ func (p *Parlia) Finalize(chain consensus.ChainHeaderReader, header *types.Heade
|
||||
systemcontracts.UpgradeBuildInSystemContract(p.chainConfig, header.Number, parent.Time, header.Time, state)
|
||||
}
|
||||
|
||||
if p.chainConfig.IsOnFeynman(header.Number, parent.Time, header.Time) {
|
||||
err := p.initializeFeynmanContract(state, header, cx, txs, receipts, systemTxs, usedGas, false)
|
||||
if err != nil {
|
||||
log.Error("init feynman contract failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
||||
if header.Number.Cmp(common.Big1) == 0 {
|
||||
err := p.initContract(state, header, cx, txs, receipts, systemTxs, usedGas, false)
|
||||
@ -1178,13 +1185,6 @@ func (p *Parlia) Finalize(chain consensus.ChainHeaderReader, header *types.Heade
|
||||
}
|
||||
}
|
||||
|
||||
if p.chainConfig.IsOnFeynman(header.Number, parent.Time, header.Time) {
|
||||
err := p.initializeFeynmanContract(state, header, cx, txs, receipts, systemTxs, usedGas, false)
|
||||
if err != nil {
|
||||
log.Error("init feynman contract failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
// update validators every day
|
||||
if p.chainConfig.IsFeynman(header.Number, header.Time) && isBreatheBlock(parent.Time, header.Time) {
|
||||
// we should avoid update validators in the Feynman upgrade block
|
||||
@ -1223,6 +1223,13 @@ func (p *Parlia) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *
|
||||
systemcontracts.UpgradeBuildInSystemContract(p.chainConfig, header.Number, parent.Time, header.Time, state)
|
||||
}
|
||||
|
||||
if p.chainConfig.IsOnFeynman(header.Number, parent.Time, header.Time) {
|
||||
err := p.initializeFeynmanContract(state, header, cx, &txs, &receipts, nil, &header.GasUsed, true)
|
||||
if err != nil {
|
||||
log.Error("init feynman contract failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
if header.Number.Cmp(common.Big1) == 0 {
|
||||
err := p.initContract(state, header, cx, &txs, &receipts, nil, &header.GasUsed, true)
|
||||
if err != nil {
|
||||
@ -1267,13 +1274,6 @@ func (p *Parlia) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *
|
||||
}
|
||||
}
|
||||
|
||||
if p.chainConfig.IsOnFeynman(header.Number, parent.Time, header.Time) {
|
||||
err := p.initializeFeynmanContract(state, header, cx, &txs, &receipts, nil, &header.GasUsed, true)
|
||||
if err != nil {
|
||||
log.Error("init feynman contract failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
// update validators every day
|
||||
if p.chainConfig.IsFeynman(header.Number, header.Time) && isBreatheBlock(parent.Time, header.Time) {
|
||||
// we should avoid update validators in the Feynman upgrade block
|
||||
|
@ -28,12 +28,12 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/eth/tracers"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts"
|
||||
)
|
||||
|
||||
// noopReleaser is returned in case there is no operation expected
|
||||
|
@ -1038,12 +1038,14 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
|
||||
defer release()
|
||||
|
||||
// upgrade build-in system contract before tracing if Feynman is not enabled
|
||||
parent, err := api.blockByNumberAndHash(ctx, rpc.BlockNumber(block.NumberU64()-1), block.ParentHash())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !api.backend.ChainConfig().IsFeynman(block.Number(), block.Time()) {
|
||||
systemcontracts.UpgradeBuildInSystemContract(api.backend.ChainConfig(), block.Number(), parent.Time(), block.Time(), statedb)
|
||||
if block.NumberU64() > 0 {
|
||||
parent, err := api.blockByNumberAndHash(ctx, rpc.BlockNumber(block.NumberU64()-1), block.ParentHash())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !api.backend.ChainConfig().IsFeynman(block.Number(), block.Time()) {
|
||||
systemcontracts.UpgradeBuildInSystemContract(api.backend.ChainConfig(), block.Number(), parent.Time(), block.Time(), statedb)
|
||||
}
|
||||
}
|
||||
|
||||
vmctx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
|
||||
|
@ -251,7 +251,7 @@ func TestTraceCall(t *testing.T) {
|
||||
},
|
||||
config: nil,
|
||||
expectErr: fmt.Errorf("block #%d not found", genBlocks+1),
|
||||
//expect: nil,
|
||||
// expect: nil,
|
||||
},
|
||||
// Standard JSON trace upon the latest block
|
||||
{
|
||||
@ -547,7 +547,7 @@ func TestTracingWithOverrides(t *testing.T) {
|
||||
Data: newRPCBytes(common.Hex2Bytes("8381f58a")), // call number()
|
||||
},
|
||||
config: &TraceCallConfig{
|
||||
//Tracer: &tracer,
|
||||
// Tracer: &tracer,
|
||||
StateOverrides: ðapi.StateOverride{
|
||||
randomAccounts[2].addr: ethapi.OverrideAccount{
|
||||
Code: newRPCBytes(common.Hex2Bytes("6080604052348015600f57600080fd5b506004361060285760003560e01c80638381f58a14602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000548156fea2646970667358221220eab35ffa6ab2adfe380772a48b8ba78e82a1b820a18fcb6f59aa4efb20a5f60064736f6c63430007040033")),
|
||||
@ -563,7 +563,7 @@ func TestTracingWithOverrides(t *testing.T) {
|
||||
From: &accounts[0].addr,
|
||||
// BLOCKNUMBER PUSH1 MSTORE
|
||||
Input: newRPCBytes(common.Hex2Bytes("4360005260206000f3")),
|
||||
//&hexutil.Bytes{0x43}, // blocknumber
|
||||
// &hexutil.Bytes{0x43}, // blocknumber
|
||||
},
|
||||
config: &TraceCallConfig{
|
||||
BlockOverrides: ðapi.BlockOverrides{Number: (*hexutil.Big)(big.NewInt(0x1337))},
|
||||
@ -639,7 +639,7 @@ func TestTracingWithOverrides(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
//want: `{"gas":46900,"failed":false,"returnValue":"0000000000000000000000000000000000000000000000000000000000000539"}`,
|
||||
// want: `{"gas":46900,"failed":false,"returnValue":"0000000000000000000000000000000000000000000000000000000000000539"}`,
|
||||
want: `{"gas":44100,"failed":false,"returnValue":"0000000000000000000000000000000000000000000000000000000000000001"}`,
|
||||
},
|
||||
{ // No state override
|
||||
|
Loading…
Reference in New Issue
Block a user