rpc, node, mempool and start of ight client

This commit is contained in:
Marko Baricevic
2021-02-02 14:42:20 +01:00
parent b2f3e767a7
commit 7e7e962d93
26 changed files with 73 additions and 77 deletions
+6 -6
View File
@@ -372,7 +372,7 @@ func (c *Client) initializeWithTrustOptions(ctx context.Context, options TrustOp
// - header has not been verified yet and is therefore not in the store
//
// Safe for concurrent use by multiple goroutines.
func (c *Client) TrustedLightBlock(height int64) (*types.LightBlock, error) {
func (c *Client) TrustedLightBlock(height uint64) (*types.LightBlock, error) {
height, err := c.compareWithLatestHeight(height)
if err != nil {
return nil, err
@@ -380,7 +380,7 @@ func (c *Client) TrustedLightBlock(height int64) (*types.LightBlock, error) {
return c.trustedStore.LightBlock(height)
}
func (c *Client) compareWithLatestHeight(height int64) (int64, error) {
func (c *Client) compareWithLatestHeight(height uint64) (uint64, error) {
latestHeight, err := c.LastTrustedHeight()
if err != nil {
return 0, fmt.Errorf("can't get last trusted height: %w", err)
@@ -805,7 +805,7 @@ func (c *Client) verifySkippingAgainstPrimary(
// there are no trusted headers.
//
// Safe for concurrent use by multiple goroutines.
func (c *Client) LastTrustedHeight() (int64, error) {
func (c *Client) LastTrustedHeight() (uint64, error) {
return c.trustedStore.LastLightBlockHeight()
}
@@ -813,7 +813,7 @@ func (c *Client) LastTrustedHeight() (int64, error) {
// there are no trusted headers.
//
// Safe for concurrent use by multiple goroutines.
func (c *Client) FirstTrustedHeight() (int64, error) {
func (c *Client) FirstTrustedHeight() (uint64, error) {
return c.trustedStore.FirstLightBlockHeight()
}
@@ -852,7 +852,7 @@ func (c *Client) Cleanup() error {
// cleanupAfter deletes all headers & validator sets after +height+. It also
// resets latestTrustedBlock to the latest header.
func (c *Client) cleanupAfter(height int64) error {
func (c *Client) cleanupAfter(height uint64) error {
prevHeight := c.latestTrustedBlock.Height
for {
@@ -972,7 +972,7 @@ func (c *Client) replacePrimaryProvider() error {
// lightBlockFromPrimary retrieves the lightBlock from the primary provider
// at the specified height. Handles dropout by the primary provider by swapping
// with an alternative provider.
func (c *Client) lightBlockFromPrimary(ctx context.Context, height int64) (*types.LightBlock, error) {
func (c *Client) lightBlockFromPrimary(ctx context.Context, height uint64) (*types.LightBlock, error) {
c.providerMutex.Lock()
l, err := c.primary.LightBlock(ctx, height)
c.providerMutex.Unlock()
+2 -2
View File
@@ -20,9 +20,9 @@ import (
func TestLightClientAttackEvidence_Lunatic(t *testing.T) {
// primary performs a lunatic attack
var (
latestHeight = int64(10)
latestHeight = uint64(10)
valSize = 5
divergenceHeight = int64(6)
divergenceHeight = uint64(6)
primaryHeaders = make(map[int64]*types.SignedHeader, latestHeight)
primaryValidators = make(map[int64]*types.ValidatorSet, latestHeight)
)
+2 -2
View File
@@ -50,8 +50,8 @@ var ErrFailedHeaderCrossReferencing = errors.New(
// ErrVerificationFailed means either sequential or skipping verification has
// failed to verify from header #1 to header #2 due to some reason.
type ErrVerificationFailed struct {
From int64
To int64
From uint64
To uint64
Reason error
}
+1 -1
View File
@@ -120,7 +120,7 @@ func makeVote(header *types.Header, valset *types.ValidatorSet,
return vote
}
func genHeader(chainID string, height int64, bTime time.Time, txs types.Txs,
func genHeader(chainID string, height uint64, bTime time.Time, txs types.Txs,
valset, nextValset *types.ValidatorSet, appHash, consHash, resHash []byte) *types.Header {
return &types.Header{
+1 -1
View File
@@ -19,7 +19,7 @@ type Provider interface {
// issues, an error will be returned.
// If there's no LightBlock for the given height, ErrLightBlockNotFound
// error is returned.
LightBlock(ctx context.Context, height int64) (*types.LightBlock, error)
LightBlock(ctx context.Context, height uint64) (*types.LightBlock, error)
// ReportEvidence reports an evidence of misbehavior.
ReportEvidence(context.Context, types.Evidence) error
+5 -5
View File
@@ -14,7 +14,7 @@ type Store interface {
// ValidatorSet (h: height).
//
// height must be > 0.
DeleteLightBlock(height int64) error
DeleteLightBlock(height uint64) error
// LightBlock returns the LightBlock that corresponds to the given
// height.
@@ -22,22 +22,22 @@ type Store interface {
// height must be > 0.
//
// If LightBlock is not found, ErrLightBlockNotFound is returned.
LightBlock(height int64) (*types.LightBlock, error)
LightBlock(height uint64) (*types.LightBlock, error)
// LastLightBlockHeight returns the last (newest) LightBlock height.
//
// If the store is empty, -1 and nil error are returned.
LastLightBlockHeight() (int64, error)
LastLightBlockHeight() (uint64, error)
// FirstLightBlockHeight returns the first (oldest) LightBlock height.
//
// If the store is empty, -1 and nil error are returned.
FirstLightBlockHeight() (int64, error)
FirstLightBlockHeight() (uint64, error)
// LightBlockBefore returns the LightBlock before a certain height.
//
// height must be > 0 && <= LastLightBlockHeight.
LightBlockBefore(height int64) (*types.LightBlock, error)
LightBlockBefore(height uint64) (*types.LightBlock, error)
// Prune removes headers & the associated validator sets when Store reaches a
// defined size (number of header & validator set pairs).
+1 -1
View File
@@ -31,7 +31,7 @@ type TrustOptions struct {
// Header's Height and Hash must both be provided to force the trusting of a
// particular header.
Height int64
Height uint64
Hash []byte
}