mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-28 18:55:42 +00:00
evidence migration with fixes to generated mocks
This commit is contained in:
+2
-2
@@ -385,7 +385,7 @@ func (c *Client) compareWithLatestHeight(height uint64) (uint64, error) {
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("can't get last trusted height: %w", err)
|
||||
}
|
||||
if latestHeight == -1 { // todo standardize errors
|
||||
if latestHeight == 0 { // todo: should we standardize errors to avoid 0 checks
|
||||
return 0, errors.New("no headers exist")
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ func (c *Client) Update(ctx context.Context, now time.Time) (*types.LightBlock,
|
||||
return nil, fmt.Errorf("can't get last trusted height: %w", err)
|
||||
}
|
||||
|
||||
if lastTrustedHeight == -1 {
|
||||
if lastTrustedHeight == 0 {
|
||||
// no light blocks yet => wait
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
+10
-10
@@ -27,20 +27,20 @@ func TestLightClientAttackEvidence_Lunatic(t *testing.T) {
|
||||
primaryValidators = make(map[int64]*types.ValidatorSet, latestHeight)
|
||||
)
|
||||
|
||||
witnessHeaders, witnessValidators, chainKeys := genMockNodeWithKeys(chainID, latestHeight, valSize, 2, bTime)
|
||||
witnessHeaders, witnessValidators, chainKeys := genMockNodeWithKeys(chainID, int64(latestHeight), valSize, 2, bTime)
|
||||
witness := mockp.New(chainID, witnessHeaders, witnessValidators)
|
||||
forgedKeys := chainKeys[divergenceHeight-1].ChangeKeys(3) // we change 3 out of the 5 validators (still 2/5 remain)
|
||||
forgedKeys := chainKeys[int64(divergenceHeight)-1].ChangeKeys(3) // we change 3 out of the 5 validators (still 2/5 remain)
|
||||
forgedVals := forgedKeys.ToValidators(2, 0)
|
||||
|
||||
for height := int64(1); height <= latestHeight; height++ {
|
||||
for height := uint64(1); height <= latestHeight; height++ {
|
||||
if height < divergenceHeight {
|
||||
primaryHeaders[height] = witnessHeaders[height]
|
||||
primaryValidators[height] = witnessValidators[height]
|
||||
primaryHeaders[int64(height)] = witnessHeaders[int64(height)]
|
||||
primaryValidators[int64(height)] = witnessValidators[int64(height)]
|
||||
continue
|
||||
}
|
||||
primaryHeaders[height] = forgedKeys.GenSignedHeader(chainID, height, bTime.Add(time.Duration(height)*time.Minute),
|
||||
primaryHeaders[int64(height)] = forgedKeys.GenSignedHeader(chainID, height, bTime.Add(time.Duration(height)*time.Minute),
|
||||
nil, forgedVals, forgedVals, hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(forgedKeys))
|
||||
primaryValidators[height] = forgedVals
|
||||
primaryValidators[int64(height)] = forgedVals
|
||||
}
|
||||
primary := mockp.New(chainID, primaryHeaders, primaryValidators)
|
||||
|
||||
@@ -118,7 +118,7 @@ func TestLightClientAttackEvidence_Equivocation(t *testing.T) {
|
||||
}
|
||||
// we don't have a network partition so we will make 4/5 (greater than 2/3) malicious and vote again for
|
||||
// a different block (which we do by adding txs)
|
||||
primaryHeaders[height] = chainKeys[height].GenSignedHeader(chainID, height,
|
||||
primaryHeaders[height] = chainKeys[height].GenSignedHeader(chainID, uint64(height),
|
||||
bTime.Add(time.Duration(height)*time.Minute), []types.Tx{[]byte("abcd")},
|
||||
witnessValidators[height], witnessValidators[height+1], hash("app_hash"),
|
||||
hash("cons_hash"), hash("results_hash"), 0, len(chainKeys[height])-1)
|
||||
@@ -157,7 +157,7 @@ func TestLightClientAttackEvidence_Equivocation(t *testing.T) {
|
||||
SignedHeader: primaryHeaders[divergenceHeight],
|
||||
ValidatorSet: primaryValidators[divergenceHeight],
|
||||
},
|
||||
CommonHeight: divergenceHeight,
|
||||
CommonHeight: uint64(divergenceHeight),
|
||||
}
|
||||
assert.True(t, witness.HasEvidence(evAgainstPrimary))
|
||||
|
||||
@@ -166,7 +166,7 @@ func TestLightClientAttackEvidence_Equivocation(t *testing.T) {
|
||||
SignedHeader: witnessHeaders[divergenceHeight],
|
||||
ValidatorSet: witnessValidators[divergenceHeight],
|
||||
},
|
||||
CommonHeight: divergenceHeight,
|
||||
CommonHeight: uint64(divergenceHeight),
|
||||
}
|
||||
assert.True(t, primary.HasEvidence(evAgainstWitness))
|
||||
}
|
||||
|
||||
+10
-10
@@ -75,10 +75,10 @@ func makeNetInfoFunc(c *lrpc.Client) rpcNetInfoFunc {
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBlockchainInfoFunc func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
|
||||
type rpcBlockchainInfoFunc func(ctx *rpctypes.Context, minHeight, maxHeight uint64) (*ctypes.ResultBlockchainInfo, error)
|
||||
|
||||
func makeBlockchainInfoFunc(c *lrpc.Client) rpcBlockchainInfoFunc {
|
||||
return func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
|
||||
return func(ctx *rpctypes.Context, minHeight, maxHeight uint64) (*ctypes.ResultBlockchainInfo, error) {
|
||||
return c.BlockchainInfo(ctx.Context(), minHeight, maxHeight)
|
||||
}
|
||||
}
|
||||
@@ -91,10 +91,10 @@ func makeGenesisFunc(c *lrpc.Client) rpcGenesisFunc {
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBlockFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlock, error)
|
||||
type rpcBlockFunc func(ctx *rpctypes.Context, height *uint64) (*ctypes.ResultBlock, error)
|
||||
|
||||
func makeBlockFunc(c *lrpc.Client) rpcBlockFunc {
|
||||
return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlock, error) {
|
||||
return func(ctx *rpctypes.Context, height *uint64) (*ctypes.ResultBlock, error) {
|
||||
return c.Block(ctx.Context(), height)
|
||||
}
|
||||
}
|
||||
@@ -107,18 +107,18 @@ func makeBlockByHashFunc(c *lrpc.Client) rpcBlockByHashFunc {
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBlockResultsFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlockResults, error)
|
||||
type rpcBlockResultsFunc func(ctx *rpctypes.Context, height *uint64) (*ctypes.ResultBlockResults, error)
|
||||
|
||||
func makeBlockResultsFunc(c *lrpc.Client) rpcBlockResultsFunc {
|
||||
return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlockResults, error) {
|
||||
return func(ctx *rpctypes.Context, height *uint64) (*ctypes.ResultBlockResults, error) {
|
||||
return c.BlockResults(ctx.Context(), height)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcCommitFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultCommit, error)
|
||||
type rpcCommitFunc func(ctx *rpctypes.Context, height *uint64) (*ctypes.ResultCommit, error)
|
||||
|
||||
func makeCommitFunc(c *lrpc.Client) rpcCommitFunc {
|
||||
return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultCommit, error) {
|
||||
return func(ctx *rpctypes.Context, height *uint64) (*ctypes.ResultCommit, error) {
|
||||
return c.Commit(ctx.Context(), height)
|
||||
}
|
||||
}
|
||||
@@ -141,11 +141,11 @@ func makeTxSearchFunc(c *lrpc.Client) rpcTxSearchFunc {
|
||||
}
|
||||
}
|
||||
|
||||
type rpcValidatorsFunc func(ctx *rpctypes.Context, height *int64,
|
||||
type rpcValidatorsFunc func(ctx *rpctypes.Context, height *uint64,
|
||||
page, perPage *int) (*ctypes.ResultValidators, error)
|
||||
|
||||
func makeValidatorsFunc(c *lrpc.Client) rpcValidatorsFunc {
|
||||
return func(ctx *rpctypes.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error) {
|
||||
return func(ctx *rpctypes.Context, height *uint64, page, perPage *int) (*ctypes.ResultValidators, error) {
|
||||
return c.Validators(ctx.Context(), height, page, perPage)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ var errNegOrZeroHeight = errors.New("negative or zero height")
|
||||
type KeyPathFunc func(path string, key []byte) (merkle.KeyPath, error)
|
||||
|
||||
// LightClient is an interface that contains functionality needed by Client from the light client.
|
||||
//go:generate mockery --case underscore --name LightClient
|
||||
type LightClient interface {
|
||||
ChainID() string
|
||||
VerifyLightBlockAtHeight(ctx context.Context, height uint64, now time.Time) (*types.LightBlock, error)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.3.0. DO NOT EDIT.
|
||||
// Code generated by mockery v2.5.1. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
@@ -36,7 +36,7 @@ func (_m *LightClient) TrustedLightBlock(height uint64) (*types.LightBlock, erro
|
||||
ret := _m.Called(height)
|
||||
|
||||
var r0 *types.LightBlock
|
||||
if rf, ok := ret.Get(0).(func(int64) *types.LightBlock); ok {
|
||||
if rf, ok := ret.Get(0).(func(uint64) *types.LightBlock); ok {
|
||||
r0 = rf(height)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
@@ -45,7 +45,7 @@ func (_m *LightClient) TrustedLightBlock(height uint64) (*types.LightBlock, erro
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(int64) error); ok {
|
||||
if rf, ok := ret.Get(1).(func(uint64) error); ok {
|
||||
r1 = rf(height)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
@@ -55,11 +55,11 @@ func (_m *LightClient) TrustedLightBlock(height uint64) (*types.LightBlock, erro
|
||||
}
|
||||
|
||||
// VerifyLightBlockAtHeight provides a mock function with given fields: ctx, height, now
|
||||
func (_m *LightClient) VerifyLightBlockAtHeight(ctx context.Context, height int64, now time.Time) (*types.LightBlock, error) {
|
||||
func (_m *LightClient) VerifyLightBlockAtHeight(ctx context.Context, height uint64, now time.Time) (*types.LightBlock, error) {
|
||||
ret := _m.Called(ctx, height, now)
|
||||
|
||||
var r0 *types.LightBlock
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, time.Time) *types.LightBlock); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context, uint64, time.Time) *types.LightBlock); ok {
|
||||
r0 = rf(ctx, height, now)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
@@ -68,7 +68,7 @@ func (_m *LightClient) VerifyLightBlockAtHeight(ctx context.Context, height int6
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, int64, time.Time) error); ok {
|
||||
if rf, ok := ret.Get(1).(func(context.Context, uint64, time.Time) error); ok {
|
||||
r1 = rf(ctx, height, now)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
|
||||
Reference in New Issue
Block a user