This commit is contained in:
William Banfield
2022-11-01 16:51:57 -04:00
parent 4bcbfd6c05
commit faf009ef48
5 changed files with 41 additions and 46 deletions
+6 -12
View File
@@ -498,6 +498,10 @@ func (n *Node) OnStop() {
// ConfigureRPC makes sure RPC has all the objects it needs to operate.
func (n *Node) ConfigureRPC() (*rpccore.Environment, error) {
pubKey, err := n.privValidator.GetPubKey()
if pubKey == nil || err != nil {
return nil, fmt.Errorf("can't get pubkey: %w", err)
}
rpcCoreEnv := rpccore.Environment{
ProxyAppQuery: n.proxyApp.Query(),
ProxyAppMempool: n.proxyApp.Mempool(),
@@ -508,6 +512,7 @@ func (n *Node) ConfigureRPC() (*rpccore.Environment, error) {
ConsensusState: n.consensusState,
P2PPeers: n.sw,
P2PTransport: n,
PubKey: pubKey,
GenDoc: n.genesisDoc,
TxIndexer: n.txIndexer,
@@ -520,20 +525,9 @@ func (n *Node) ConfigureRPC() (*rpccore.Environment, error) {
Config: *n.config.RPC,
}
if err := rpccore.InitGenesisChunks(); err != nil {
return nil, err
}
if n.config.Mode == cfg.ModeValidator {
pubKey, err := n.privValidator.GetPubKey()
if pubKey == nil || err != nil {
return nil, fmt.Errorf("can't get pubkey: %w", err)
}
rpcCoreEnv.PubKey = pubKey
}
if err := rpcCoreEnv.InitGenesisChunks(); err != nil {
return nil, err
}
return &rpcCoreEnv, nil
}
@@ -543,7 +537,7 @@ func (n *Node) startRPC() ([]net.Listener, error) {
return nil, err
}
listenAddrs := strings.SplitAndTrimEmpty(n.config.RPC.ListenAddress, ",", " ")
listenAddrs := splitAndTrimEmpty(n.config.RPC.ListenAddress, ",", " ")
routes := env.GetRoutes()
if n.config.RPC.Unsafe {
+2 -2
View File
@@ -168,11 +168,11 @@ func (c *Local) BlockResults(ctx context.Context, height *int64) (*ctypes.Result
}
func (c *Local) Header(ctx context.Context, height *int64) (*ctypes.ResultHeader, error) {
return core.Header(c.ctx, height)
return c.env.Header(c.ctx, height)
}
func (c *Local) HeaderByHash(ctx context.Context, hash bytes.HexBytes) (*ctypes.ResultHeader, error) {
return core.HeaderByHash(c.ctx, hash)
return c.env.HeaderByHash(c.ctx, hash)
}
func (c *Local) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error) {
+1 -1
View File
@@ -80,7 +80,7 @@ func TestBlockResults(t *testing.T) {
BeginBlock: &abci.ResponseBeginBlock{},
}
env = &Environment{}
env := &Environment{}
env.StateStore = sm.NewStore(dbm.NewMemDB(), sm.StoreOptions{
DiscardABCIResponses: false,
})
+3 -2
View File
@@ -70,12 +70,13 @@ func TestPaginationPerPage(t *testing.T) {
{5, maxPerPage, maxPerPage},
{5, maxPerPage + 1, maxPerPage},
}
env := &Environment{}
for _, c := range cases {
p := validatePerPage(&c.perPage)
p := env.validatePerPage(&c.perPage)
assert.Equal(t, c.newPerPage, p, fmt.Sprintf("%v", c))
}
// nil case
p := validatePerPage(nil)
p := env.validatePerPage(nil)
assert.Equal(t, defaultPerPage, p)
}
+29 -29
View File
@@ -17,45 +17,45 @@ func (env *Environment) GetRoutes() RoutesMap {
"unsubscribe_all": rpc.NewWSRPCFunc(env.UnsubscribeAll, ""),
// info API
"health": rpc.NewRPCFunc(env.Health, "", false),
"status": rpc.NewRPCFunc(env.Status, "", false),
"net_info": rpc.NewRPCFunc(env.NetInfo, "", false),
"blockchain": rpc.NewRPCFunc(env.BlockchainInfo, "minHeight,maxHeight", true),
"genesis": rpc.NewRPCFunc(env.Genesis, "", true),
"genesis_chunked": rpc.NewRPCFunc(env.GenesisChunked, "chunk", true),
"block": rpc.NewRPCFunc(env.Block, "height", true),
"block_by_hash": rpc.NewRPCFunc(env.BlockByHash, "hash", true),
"block_results": rpc.NewRPCFunc(env.BlockResults, "height", true),
"commit": rpc.NewRPCFunc(env.Commit, "height", true),
"check_tx": rpc.NewRPCFunc(env.CheckTx, "tx", true),
"tx": rpc.NewRPCFunc(env.Tx, "hash,prove", true),
"tx_search": rpc.NewRPCFunc(env.TxSearch, "query,prove,page,per_page,order_by", false),
"block_search": rpc.NewRPCFunc(env.BlockSearch, "query,page,per_page,order_by", false),
"validators": rpc.NewRPCFunc(env.Validators, "height,page,per_page", true),
"dump_consensus_state": rpc.NewRPCFunc(env.DumpConsensusState, "", false),
"consensus_state": rpc.NewRPCFunc(env.GetConsensusState, "", false),
"consensus_params": rpc.NewRPCFunc(env.ConsensusParams, "height", true),
"unconfirmed_txs": rpc.NewRPCFunc(env.UnconfirmedTxs, "limit", false),
"num_unconfirmed_txs": rpc.NewRPCFunc(env.NumUnconfirmedTxs, "", false),
"health": rpc.NewRPCFunc(env.Health, ""),
"status": rpc.NewRPCFunc(env.Status, ""),
"net_info": rpc.NewRPCFunc(env.NetInfo, ""),
"blockchain": rpc.NewRPCFunc(env.BlockchainInfo, "minHeight,maxHeight"),
"genesis": rpc.NewRPCFunc(env.Genesis, ""),
"genesis_chunked": rpc.NewRPCFunc(env.GenesisChunked, "chunk"),
"block": rpc.NewRPCFunc(env.Block, "height"),
"block_by_hash": rpc.NewRPCFunc(env.BlockByHash, "hash"),
"block_results": rpc.NewRPCFunc(env.BlockResults, "height"),
"commit": rpc.NewRPCFunc(env.Commit, "height"),
"check_tx": rpc.NewRPCFunc(env.CheckTx, "tx"),
"tx": rpc.NewRPCFunc(env.Tx, "hash,prove"),
"tx_search": rpc.NewRPCFunc(env.TxSearch, "query,prove,page,per_page,order_by"),
"block_search": rpc.NewRPCFunc(env.BlockSearch, "query,page,per_page,order_by"),
"validators": rpc.NewRPCFunc(env.Validators, "height,page,per_page"),
"dump_consensus_state": rpc.NewRPCFunc(env.DumpConsensusState, ""),
"consensus_state": rpc.NewRPCFunc(env.GetConsensusState, ""),
"consensus_params": rpc.NewRPCFunc(env.ConsensusParams, "height"),
"unconfirmed_txs": rpc.NewRPCFunc(env.UnconfirmedTxs, "limit"),
"num_unconfirmed_txs": rpc.NewRPCFunc(env.NumUnconfirmedTxs, ""),
// tx broadcast API
"broadcast_tx_commit": rpc.NewRPCFunc(env.BroadcastTxCommit, "tx", false),
"broadcast_tx_sync": rpc.NewRPCFunc(env.BroadcastTxSync, "tx", false),
"broadcast_tx_async": rpc.NewRPCFunc(env.BroadcastTxAsync, "tx", false),
"broadcast_tx_commit": rpc.NewRPCFunc(env.BroadcastTxCommit, "tx"),
"broadcast_tx_sync": rpc.NewRPCFunc(env.BroadcastTxSync, "tx"),
"broadcast_tx_async": rpc.NewRPCFunc(env.BroadcastTxAsync, "tx"),
// abci API
"abci_query": rpc.NewRPCFunc(env.ABCIQuery, "path,data,height,prove", false),
"abci_info": rpc.NewRPCFunc(env.ABCIInfo, "", true),
"abci_query": rpc.NewRPCFunc(env.ABCIQuery, "path,data,height,prove"),
"abci_info": rpc.NewRPCFunc(env.ABCIInfo, ""),
// evidence API
"broadcast_evidence": rpc.NewRPCFunc(env.BroadcastEvidence, "evidence", false),
"broadcast_evidence": rpc.NewRPCFunc(env.BroadcastEvidence, "evidence"),
}
}
// AddUnsafeRoutes adds unsafe routes.
func (env *Environment) AddUnsafe(routes RoutesMap) {
// control API
routes["dial_seeds"] = rpc.NewRPCFunc(env.UnsafeDialSeeds, "seeds", false)
routes["dial_peers"] = rpc.NewRPCFunc(env.UnsafeDialPeers, "peers,persistent,unconditional,private", false)
routes["unsafe_flush_mempool"] = rpc.NewRPCFunc(env.UnsafeFlushMempool, "", false)
routes["dial_seeds"] = rpc.NewRPCFunc(env.UnsafeDialSeeds, "seeds")
routes["dial_peers"] = rpc.NewRPCFunc(env.UnsafeDialPeers, "peers,persistent,unconditional,private")
routes["unsafe_flush_mempool"] = rpc.NewRPCFunc(env.UnsafeFlushMempool, "")
}