Add getter for GenesisTime (#3274)

* Add getter for gensis time

* Lint

* Lint
This commit is contained in:
terence tsao 2019-08-22 10:41:05 -06:00 committed by Raul Jordan
parent e0d3e78746
commit 2e352cf5ff
2 changed files with 37 additions and 2 deletions

View File

@ -1,18 +1,39 @@
package blockchain
import (
"time"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
)
// ChainInfoRetriever defines a common interface for methods in blockchain service which
// directly retrieves chain head related data.
// directly retrieves chain info related data.
type ChainInfoRetriever interface {
FinalizedCheckpt() *ethpb.Checkpoint
HeadRetriever
CanonicalRetriever
FinalizationRetriever
GenesisTime() time.Time
}
// HeadRetriever defines a common interface for methods in blockchain service which
// directly retrieves head related data.
type HeadRetriever interface {
HeadSlot() uint64
HeadRoot() []byte
}
// CanonicalRetriever defines a common interface for methods in blockchain service which
// directly retrieves canonical roots related data.
type CanonicalRetriever interface {
CanonicalRoot(slot uint64) []byte
}
// FinalizationRetriever defines a common interface for methods in blockchain service which
// directly retrieves finalization related data.
type FinalizationRetriever interface {
FinalizedCheckpt() *ethpb.Checkpoint
}
// FinalizedCheckpt returns the latest finalized checkpoint tracked in fork choice service.
func (c *ChainService) FinalizedCheckpt() *ethpb.Checkpoint {
return c.forkChoiceStore.FinalizedCheckpt()
@ -38,3 +59,8 @@ func (c *ChainService) CanonicalRoot(slot uint64) []byte {
return c.canonicalRoots[slot]
}
// GenesisTime returns the genesis time of beacon chain.
func (c *ChainService) GenesisTime() time.Time {
return c.genesisTime
}

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"testing"
"time"
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
@ -54,3 +55,11 @@ func TestCanonicalRoot_CanRetrieve(t *testing.T) {
t.Errorf("Wanted head root: %v, got: %d", []byte{'A'}, c.CanonicalRoot(slot))
}
}
func TestGenesisTime_CanRetrieve(t *testing.T) {
c := &ChainService{}
c.genesisTime = time.Unix(100, 0)
if c.GenesisTime() != time.Unix(100, 0) {
t.Error("incorrect genesis time received")
}
}