2023-07-08 17:01:26 +00:00
|
|
|
package jsonrpc
|
2022-02-07 21:30:46 +00:00
|
|
|
|
|
|
|
import (
|
2023-10-06 10:58:08 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-01-27 04:39:34 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
2022-02-07 21:30:46 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
2023-01-13 18:12:18 +00:00
|
|
|
|
2023-10-06 10:58:08 +00:00
|
|
|
"github.com/ledgerwatch/erigon/consensus"
|
2023-10-02 17:55:31 +00:00
|
|
|
"github.com/ledgerwatch/erigon/consensus/bor"
|
2023-01-31 08:30:57 +00:00
|
|
|
"github.com/ledgerwatch/erigon/consensus/bor/valset"
|
2022-02-07 21:30:46 +00:00
|
|
|
"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)
|
2023-10-05 16:56:02 +00:00
|
|
|
GetAuthor(blockNrOrHash *rpc.BlockNumberOrHash) (*common.Address, error)
|
2023-01-27 04:39:34 +00:00
|
|
|
GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)
|
|
|
|
GetSigners(number *rpc.BlockNumber) ([]common.Address, error)
|
|
|
|
GetSignersAtHash(hash common.Hash) ([]common.Address, error)
|
|
|
|
GetCurrentProposer() (common.Address, error)
|
2023-01-31 08:30:57 +00:00
|
|
|
GetCurrentValidators() ([]*valset.Validator, error)
|
2023-10-05 16:56:02 +00:00
|
|
|
GetSnapshotProposer(blockNrOrHash *rpc.BlockNumberOrHash) (common.Address, error)
|
[bor] Implement bor_getSnapshotProposerSequence RPC method (#7770)
Implements `bor_getSnapshotProposerSequence` RPC method which returns an
ordered set of validators (selected to mine) for a given block number.
```
> curl http://localhost:8545 -X POST --data '{"jsonrpc":"2.0","method":"bor_getSnapshotProposerSequence","params":["0x235A310"],"id":1}' -H "Content-Type: application/json"
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"Signers": [
{
"Signer": "0xcfef2a3dc244ef7d0fb93c45e762d671445c4569",
"Difficulty": 5
},
{
"Signer": "0x3a22c8bc68e98b0faf40f349dd2b2890fae01484",
"Difficulty": 4
},
{
"Signer": "0xbe188d6641e8b680743a4815dfa0f6208038960f",
"Difficulty": 3
},
{
"Signer": "0xc26880a0af2ea0c7e8130e6ec47af756465452e8",
"Difficulty": 2
},
{
"Signer": "0xc275dc8be39f50d12f66b6a63629c39da5bae5bd",
"Difficulty": 1
}
],
"Diff": 5,
"Author": "0xcfef2a3dc244ef7d0fb93c45e762d671445c4569"
}
}
```
2023-06-27 15:15:45 +00:00
|
|
|
GetSnapshotProposerSequence(blockNrOrHash *rpc.BlockNumberOrHash) (BlockSigners, error)
|
2022-02-07 21:30:46 +00:00
|
|
|
GetRootHash(start uint64, end uint64) (string, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// BorImpl is implementation of the BorAPI interface
|
|
|
|
type BorImpl struct {
|
|
|
|
*BaseAPI
|
2023-10-06 10:58:08 +00:00
|
|
|
db kv.RoDB // the chain db
|
2022-02-07 21:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewBorAPI returns BorImpl instance
|
2023-10-06 10:58:08 +00:00
|
|
|
func NewBorAPI(base *BaseAPI, db kv.RoDB) *BorImpl {
|
2022-02-07 21:30:46 +00:00
|
|
|
return &BorImpl{
|
|
|
|
BaseAPI: base,
|
|
|
|
db: db,
|
|
|
|
}
|
|
|
|
}
|
2023-10-06 10:58:08 +00:00
|
|
|
|
|
|
|
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())
|
|
|
|
}
|