mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 09:37:38 +00:00
ca3ad096e1
This fixes 2 related issues: * Now that the bor consensus engine is required for queries it can't be created based on the pretense of a db directory, but must be based on chain config read from the db. Using the DB presence causes Bor to get instantiated for non bor chains which breaks. * At the moment eth_calls on a remote daemon don't check Bor headers prior to calling the EVM code as it was just using a fake ETHash instance - which performs ETH header validation only. The current version is mostly working but needs adapting to perform lazy initialization of the engine.
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package jsonrpc
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
|
|
"github.com/ledgerwatch/erigon/consensus"
|
|
"github.com/ledgerwatch/erigon/consensus/bor"
|
|
"github.com/ledgerwatch/erigon/consensus/bor/valset"
|
|
"github.com/ledgerwatch/erigon/rpc"
|
|
)
|
|
|
|
// BorAPI Bor specific routines
|
|
type BorAPI interface {
|
|
// Bor snapshot related (see ./bor_snapshot.go)
|
|
GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)
|
|
GetAuthor(blockNrOrHash *rpc.BlockNumberOrHash) (*common.Address, error)
|
|
GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)
|
|
GetSigners(number *rpc.BlockNumber) ([]common.Address, error)
|
|
GetSignersAtHash(hash common.Hash) ([]common.Address, error)
|
|
GetCurrentProposer() (common.Address, error)
|
|
GetCurrentValidators() ([]*valset.Validator, error)
|
|
GetSnapshotProposer(blockNrOrHash *rpc.BlockNumberOrHash) (common.Address, error)
|
|
GetSnapshotProposerSequence(blockNrOrHash *rpc.BlockNumberOrHash) (BlockSigners, error)
|
|
GetRootHash(start uint64, end uint64) (string, error)
|
|
}
|
|
|
|
// BorImpl is implementation of the BorAPI interface
|
|
type BorImpl struct {
|
|
*BaseAPI
|
|
db kv.RoDB // the chain db
|
|
}
|
|
|
|
// NewBorAPI returns BorImpl instance
|
|
func NewBorAPI(base *BaseAPI, db kv.RoDB) *BorImpl {
|
|
return &BorImpl{
|
|
BaseAPI: base,
|
|
db: db,
|
|
}
|
|
}
|
|
|
|
func (api *BorImpl) bor() (*bor.Bor, error) {
|
|
type lazy interface {
|
|
HasEngine() bool
|
|
Engine() consensus.EngineReader
|
|
}
|
|
|
|
switch engine := api.engine().(type) {
|
|
case *bor.Bor:
|
|
return engine, nil
|
|
case lazy:
|
|
if engine.HasEngine() {
|
|
if bor, ok := engine.Engine().(*bor.Bor); ok {
|
|
return bor, nil
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil, fmt.Errorf("unknown or invalid consensus engine: %T", api.engine())
|
|
}
|