mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
fix some things that broke in the latest rebase. fix the cross-validator
This commit is contained in:
parent
1329dcf6fb
commit
ad291040a3
9 changed files with 36 additions and 25 deletions
|
|
@ -81,7 +81,7 @@ var (
|
||||||
Usage: "",
|
Usage: "",
|
||||||
ArgsUsage: "server --chain-config /path/to/chain-config.json",
|
ArgsUsage: "server --chain-config /path/to/chain-config.json",
|
||||||
Flags: []cli.Flag{ChainConfigFlag},
|
Flags: []cli.Flag{ChainConfigFlag},
|
||||||
Description: `Runs an HTTP server which provides an API endpoint for stateless block verification`,
|
Description: `Runs an HTTP server (temporarily hard-coded to listen on the local address at port 8080) which provides an API endpoint for stateless block verification`,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
@ -9,7 +10,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func server(ctx *cli.Context) error {
|
func server(ctx *cli.Context) error {
|
||||||
chainConfig := loadChainConfig(ctx.String(ChainConfigFlag.Name))
|
var chainConfig *params.ChainConfig
|
||||||
|
if chainConfigFlagVal := ctx.String(ChainConfigFlag.Name); chainConfigFlagVal != "" {
|
||||||
|
chainConfig = loadChainConfig(ctx.String(ChainConfigFlag.Name))
|
||||||
|
} else {
|
||||||
|
// TODO: instead of assuming mainnet configuration in absence of chain config
|
||||||
|
// val, accept known chain configurations via network preset flag.
|
||||||
|
chainConfig = params.MainnetChainConfig
|
||||||
|
}
|
||||||
closeCh, _, err := utils.RunLocalServer(chainConfig, 8080)
|
closeCh, _, err := utils.RunLocalServer(chainConfig, 8080)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/triedb"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -25,7 +25,7 @@ func StatelessExecute(logOutput io.Writer, chainCfg *params.ChainConfig, witness
|
||||||
}
|
}
|
||||||
_, prestateRoot := rawdb.ReadAccountTrieNode(rawDb, nil)
|
_, prestateRoot := rawdb.ReadAccountTrieNode(rawDb, nil)
|
||||||
|
|
||||||
db, err := state.New(prestateRoot, state.NewDatabaseWithConfig(rawDb, trie.PathDefaults), nil)
|
db, err := state.New(prestateRoot, state.NewDatabaseWithConfig(rawDb, triedb.PathDefaults), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
@ -49,8 +49,9 @@ func StatelessExecute(logOutput io.Writer, chainCfg *params.ChainConfig, witness
|
||||||
return root, nil
|
return root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunLocalServer runs an http server at the specified port (or 0 to use a random port).
|
// RunLocalServer runs an http server on the local address at the specified
|
||||||
// The server provides a POST endpoint /verify_block which takes input as an RLP-encoded
|
// port (or 0 to use a random port).
|
||||||
|
// The server provides a POST endpoint /verify_block which takes input as an octet-stream RLP-encoded
|
||||||
// block witness proof in the body, executes the block proof and returns the computed state root.
|
// block witness proof in the body, executes the block proof and returns the computed state root.
|
||||||
func RunLocalServer(chainConfig *params.ChainConfig, port int) (closeChan chan<- struct{}, actualPort int, err error) {
|
func RunLocalServer(chainConfig *params.ChainConfig, port int) (closeChan chan<- struct{}, actualPort int, err error) {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
"github.com/holiman/uint256"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Proof-of-stake protocol constants.
|
// Proof-of-stake protocol constants.
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,7 @@ type BlockChain struct {
|
||||||
// remote endpoint. If validation fails, they are dumped to the folder specified at witnessRecordingPath
|
// remote endpoint. If validation fails, they are dumped to the folder specified at witnessRecordingPath
|
||||||
func NewBlockchainWithCrossValidator(endpoint string, witnessRecordingPath string, db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64) (*BlockChain, error) {
|
func NewBlockchainWithCrossValidator(endpoint string, witnessRecordingPath string, db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64) (*BlockChain, error) {
|
||||||
bc, err := NewBlockChain(db, cacheConfig, genesis, overrides, engine, vmConfig, shouldPreserve, txLookupLimit)
|
bc, err := NewBlockChain(db, cacheConfig, genesis, overrides, engine, vmConfig, shouldPreserve, txLookupLimit)
|
||||||
bc.crossValidator = &crossValidator{witnessRecordingPath, endpoint}
|
bc.crossValidator = &crossValidator{endpoint, witnessRecordingPath}
|
||||||
return bc, err
|
return bc, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1255,8 +1255,8 @@ func (s *StateDB) Witness() *Witness {
|
||||||
func (s *StateDB) ApplyWithdrawals(withdrawals types.Withdrawals) {
|
func (s *StateDB) ApplyWithdrawals(withdrawals types.Withdrawals) {
|
||||||
for _, w := range withdrawals {
|
for _, w := range withdrawals {
|
||||||
// Convert amount from gwei to wei.
|
// Convert amount from gwei to wei.
|
||||||
amount := new(big.Int).SetUint64(w.Amount)
|
amount := new(uint256.Int).SetUint64(w.Amount)
|
||||||
amount = amount.Mul(amount, big.NewInt(params.GWei))
|
amount = amount.Mul(amount, uint256.NewInt(params.GWei))
|
||||||
s.AddBalance(w.Address, amount)
|
s.AddBalance(w.Address, amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,19 +163,19 @@ func TestExecutionSpec(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func execBlockTest(t *testing.T, bt *testMatcher, test *BlockTest) {
|
func execBlockTest(t *testing.T, bt *testMatcher, test *BlockTest) {
|
||||||
if err := bt.checkFailure(t, test.Run(false, rawdb.HashScheme, nil)); err != nil {
|
if err := bt.checkFailure(t, test.Run(false, rawdb.HashScheme, nil, nil)); err != nil {
|
||||||
t.Errorf("test in hash mode without snapshotter failed: %v", err)
|
t.Errorf("test in hash mode without snapshotter failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := bt.checkFailure(t, test.Run(true, rawdb.HashScheme, nil)); err != nil {
|
if err := bt.checkFailure(t, test.Run(true, rawdb.HashScheme, nil, nil)); err != nil {
|
||||||
t.Errorf("test in hash mode with snapshotter failed: %v", err)
|
t.Errorf("test in hash mode with snapshotter failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := bt.checkFailure(t, test.Run(false, rawdb.PathScheme, nil)); err != nil {
|
if err := bt.checkFailure(t, test.Run(false, rawdb.PathScheme, nil, nil)); err != nil {
|
||||||
t.Errorf("test in path mode without snapshotter failed: %v", err)
|
t.Errorf("test in path mode without snapshotter failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := bt.checkFailure(t, test.Run(true, rawdb.PathScheme, nil)); err != nil {
|
if err := bt.checkFailure(t, test.Run(true, rawdb.PathScheme, nil, nil)); err != nil {
|
||||||
t.Errorf("test in path mode with snapshotter failed: %v", err)
|
t.Errorf("test in path mode with snapshotter failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,15 +112,15 @@ type btHeaderMarshaling struct {
|
||||||
ExcessBlobGas *math.HexOrDecimal64
|
ExcessBlobGas *math.HexOrDecimal64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *BlockTest) Run(snapshotter bool, scheme string, tracer vm.EVMLogger) error {
|
func (t *BlockTest) Run(snapshotter bool, scheme string, tracer vm.EVMLogger, postCheck func(error, *core.BlockChain)) error {
|
||||||
return t.run(false, snapshotter, scheme, tracer)
|
return t.run(false, snapshotter, scheme, tracer, postCheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *BlockTest) RunStateless(snapshotter bool, scheme string, tracer vm.EVMLogger) error {
|
func (t *BlockTest) RunStateless(snapshotter bool, scheme string, tracer vm.EVMLogger, postCheck func(error, *core.BlockChain)) error {
|
||||||
return t.run(true, snapshotter, scheme, tracer)
|
return t.run(true, snapshotter, scheme, tracer, postCheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *BlockTest) run(stateless bool, snapshotter bool, scheme string, tracer vm.EVMLogger) error {
|
func (t *BlockTest) run(stateless bool, snapshotter bool, scheme string, tracer vm.EVMLogger, postCheck func(error, *core.BlockChain)) (result error) {
|
||||||
config, ok := Forks[t.json.Network]
|
config, ok := Forks[t.json.Network]
|
||||||
if !ok {
|
if !ok {
|
||||||
return UnsupportedForkError{t.json.Network}
|
return UnsupportedForkError{t.json.Network}
|
||||||
|
|
@ -191,6 +191,11 @@ func (t *BlockTest) run(stateless bool, snapshotter bool, scheme string, tracer
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Import succeeded: regardless of whether the _test_ succeeds or not, schedule
|
||||||
|
// the post-check to run
|
||||||
|
if postCheck != nil {
|
||||||
|
defer postCheck(result, chain)
|
||||||
|
}
|
||||||
cmlast := chain.CurrentBlock().Hash()
|
cmlast := chain.CurrentBlock().Hash()
|
||||||
if common.Hash(t.json.BestBlock) != cmlast {
|
if common.Hash(t.json.BestBlock) != cmlast {
|
||||||
return fmt.Errorf("last block hash validation mismatch: want: %x, have: %x", t.json.BestBlock, cmlast)
|
return fmt.Errorf("last block hash validation mismatch: want: %x, have: %x", t.json.BestBlock, cmlast)
|
||||||
|
|
|
||||||
|
|
@ -220,13 +220,11 @@ func (t *StateTrie) AccessList() map[string][]byte {
|
||||||
func (t *StateTrie) CommitAndObtainAccessList(collectLeaf bool) (common.Hash, *trienode.NodeSet, map[string][]byte, error) {
|
func (t *StateTrie) CommitAndObtainAccessList(collectLeaf bool) (common.Hash, *trienode.NodeSet, map[string][]byte, error) {
|
||||||
// Write all the pre-images to the actual disk database
|
// Write all the pre-images to the actual disk database
|
||||||
if len(t.getSecKeyCache()) > 0 {
|
if len(t.getSecKeyCache()) > 0 {
|
||||||
if t.preimages != nil {
|
preimages := make(map[common.Hash][]byte)
|
||||||
preimages := make(map[common.Hash][]byte)
|
for hk, key := range t.secKeyCache {
|
||||||
for hk, key := range t.secKeyCache {
|
preimages[common.BytesToHash([]byte(hk))] = key
|
||||||
preimages[common.BytesToHash([]byte(hk))] = key
|
|
||||||
}
|
|
||||||
t.preimages.insertPreimage(preimages)
|
|
||||||
}
|
}
|
||||||
|
t.db.InsertPreimage(preimages)
|
||||||
t.secKeyCache = make(map[string][]byte)
|
t.secKeyCache = make(map[string][]byte)
|
||||||
}
|
}
|
||||||
// Commit the trie and return its modified nodeset.
|
// Commit the trie and return its modified nodeset.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue