[rpc] Show both latest header of beacon chain and shard chain (#2714)

pull/2720/head
Edgar Aroutiounian 5 years ago committed by GitHub
parent 1a2c23ada5
commit 3aa08e9e3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      block/header.go
  2. 12
      hmy/api_backend.go
  3. 2
      hmy/backend.go
  4. 9
      internal/hmyapi/apiv1/backend.go
  5. 6
      internal/hmyapi/apiv1/blockchain.go
  6. 1
      internal/hmyapi/apiv2/backend.go
  7. 7
      internal/hmyapi/backend.go

@ -24,6 +24,12 @@ type Header struct {
blockif.Header
}
// HeaderPair ..
type HeaderPair struct {
BeaconHeader *Header `json:"beacon-chain-header"`
ShardHeader *Header `json:"shard-chain-header"`
}
var (
// ErrHeaderIsNil ..
ErrHeaderIsNil = errors.New("cannot encode nil header receiver")

@ -421,6 +421,14 @@ func (b *APIBackend) GetMedianRawStakeSnapshot() (
return committee.NewEPoSRound(b.hmy.BlockChain())
}
// GetLatestChainHeaders ..
func (b *APIBackend) GetLatestChainHeaders() *block.HeaderPair {
return &block.HeaderPair{
BeaconHeader: b.hmy.BeaconChain().CurrentHeader(),
ShardHeader: b.hmy.BlockChain().CurrentHeader(),
}
}
// GetTotalStakingSnapshot ..
func (b *APIBackend) GetTotalStakingSnapshot() *big.Int {
b.TotalStakingCache.Lock()
@ -439,7 +447,9 @@ func (b *APIBackend) GetTotalStakingSnapshot() *big.Int {
for i := range candidates {
snapshot, _ := b.hmy.BlockChain().ReadValidatorSnapshot(candidates[i])
validator, _ := b.hmy.BlockChain().ReadValidatorInformation(candidates[i])
if !committee.IsEligibleForEPoSAuction(snapshot, validator, b.hmy.BlockChain().CurrentBlock().Epoch()) {
if !committee.IsEligibleForEPoSAuction(
snapshot, validator, b.hmy.BlockChain().CurrentBlock().Epoch(),
) {
continue
}
for i := range validator.Delegations {

@ -33,8 +33,6 @@ type Harmony struct {
nodeAPI NodeAPI
// aka network version, which is used to identify which network we are using
networkID uint64
// TODO(ricl): put this into config object
// TODO(ricl): this is never set. Will result in nil pointer bug
// RPCGasCap is the global gas cap for eth-call variants.
RPCGasCap *big.Int `toml:",omitempty"`
shardID uint32

@ -27,9 +27,8 @@ import (
// implementations:
// * hmy/api_backend.go
type Backend interface {
// NOTE(ricl): this is not in ETH Backend inteface. They put it directly in eth object.
NetVersion() uint64
// General Ethereum API
// Downloader() *downloader.Downloader
ProtocolVersion() int
// SuggestPrice(ctx context.Context) (*big.Int, error)
@ -38,14 +37,13 @@ type Backend interface {
AccountManager() *accounts.Manager
// ExtRPCEnabled() bool
RPCGasCap() *big.Int // global gas cap for hmy_call over rpc: DoS protection
// BlockChain API
// SetHead(number uint64)
HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*block.Header, error)
BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error)
StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.DB, *block.Header, error)
GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error)
GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error)
// GetTd(blockHash common.Hash) *big.Int
GetEVM(ctx context.Context, msg core.Message, state *state.DB, header *block.Header) (*vm.EVM, func() error, error)
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
@ -90,4 +88,5 @@ type Backend interface {
GetTotalStakingSnapshot() *big.Int
GetCurrentBadBlocks() []core.BadBlock
GetLastCrossLinks() ([]*types.CrossLink, error)
GetLatestChainHeaders() *block.HeaderPair
}

@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/rpc"
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/block"
"github.com/harmony-one/harmony/common/denominations"
"github.com/harmony-one/harmony/consensus/quorum"
"github.com/harmony-one/harmony/consensus/reward"
@ -544,6 +545,11 @@ func (s *PublicBlockChainAPI) GetMedianRawStakeSnapshot() (
return nil, errNotBeaconChainShard
}
// GetLatestChainHeaders ..
func (s *PublicBlockChainAPI) GetLatestChainHeaders() *block.HeaderPair {
return s.b.GetLatestChainHeaders()
}
// GetAllValidatorAddresses returns all validator addresses.
func (s *PublicBlockChainAPI) GetAllValidatorAddresses() ([]string, error) {
addresses := []string{}

@ -90,4 +90,5 @@ type Backend interface {
GetTotalStakingSnapshot() *big.Int
GetCurrentBadBlocks() []core.BadBlock
GetLastCrossLinks() ([]*types.CrossLink, error)
GetLatestChainHeaders() *block.HeaderPair
}

@ -31,17 +31,11 @@ import (
type Backend interface {
// NOTE(ricl): this is not in ETH Backend inteface. They put it directly in eth object.
NetVersion() uint64
// General Ethereum API
// Downloader() *downloader.Downloader
ProtocolVersion() int
// SuggestPrice(ctx context.Context) (*big.Int, error)
ChainDb() ethdb.Database
EventMux() *event.TypeMux
AccountManager() *accounts.Manager
// ExtRPCEnabled() bool
RPCGasCap() *big.Int // global gas cap for hmy_call over rpc: DoS protection
// BlockChain API
// SetHead(number uint64)
HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*block.Header, error)
BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error)
StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.DB, *block.Header, error)
@ -92,6 +86,7 @@ type Backend interface {
GetTotalStakingSnapshot() *big.Int
GetCurrentBadBlocks() []core.BadBlock
GetLastCrossLinks() ([]*types.CrossLink, error)
GetLatestChainHeaders() *block.HeaderPair
}
// GetAPIs returns all the APIs.

Loading…
Cancel
Save