mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-20 06:06:15 +00:00
make the rest of the code compile
This commit is contained in:
+7
-6
@@ -14,7 +14,8 @@ import (
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
"github.com/tendermint/tendermint/light/provider"
|
||||
"github.com/tendermint/tendermint/light/store"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
types "github.com/tendermint/tendermint/pkg/light"
|
||||
"github.com/tendermint/tendermint/pkg/metadata"
|
||||
)
|
||||
|
||||
type mode byte
|
||||
@@ -451,7 +452,7 @@ func (c *Client) VerifyLightBlockAtHeight(ctx context.Context, height int64, now
|
||||
// If, at any moment, a LightBlock is not found by the primary provider as part of
|
||||
// verification then the provider will be replaced by another and the process will
|
||||
// restart.
|
||||
func (c *Client) VerifyHeader(ctx context.Context, newHeader *types.Header, now time.Time) error {
|
||||
func (c *Client) VerifyHeader(ctx context.Context, newHeader *metadata.Header, now time.Time) error {
|
||||
if newHeader == nil {
|
||||
return errors.New("nil header")
|
||||
}
|
||||
@@ -873,12 +874,12 @@ func (c *Client) updateTrustedLightBlock(l *types.LightBlock) error {
|
||||
// replaced with another provider and the operation is repeated.
|
||||
func (c *Client) backwards(
|
||||
ctx context.Context,
|
||||
trustedHeader *types.Header,
|
||||
newHeader *types.Header) error {
|
||||
trustedHeader *metadata.Header,
|
||||
newHeader *metadata.Header) error {
|
||||
|
||||
var (
|
||||
verifiedHeader = trustedHeader
|
||||
interimHeader *types.Header
|
||||
interimHeader *metadata.Header
|
||||
)
|
||||
|
||||
for verifiedHeader.Height > newHeader.Height {
|
||||
@@ -1069,7 +1070,7 @@ func (c *Client) findNewPrimary(ctx context.Context, height int64, remove bool)
|
||||
|
||||
// compareFirstHeaderWithWitnesses concurrently compares h with all witnesses. If any
|
||||
// witness reports a different header than h, the function returns an error.
|
||||
func (c *Client) compareFirstHeaderWithWitnesses(ctx context.Context, h *types.SignedHeader) error {
|
||||
func (c *Client) compareFirstHeaderWithWitnesses(ctx context.Context, h *metadata.SignedHeader) error {
|
||||
compareCtx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -11,7 +11,10 @@ import (
|
||||
"github.com/tendermint/tendermint/light"
|
||||
"github.com/tendermint/tendermint/light/provider"
|
||||
dbs "github.com/tendermint/tendermint/light/store/db"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tendermint/pkg/consensus"
|
||||
"github.com/tendermint/tendermint/pkg/evidence"
|
||||
types "github.com/tendermint/tendermint/pkg/light"
|
||||
"github.com/tendermint/tendermint/pkg/metadata"
|
||||
)
|
||||
|
||||
// NOTE: block is produced every minute. Make sure the verification time
|
||||
@@ -28,8 +31,8 @@ type providerBenchmarkImpl struct {
|
||||
blocks map[int64]*types.LightBlock
|
||||
}
|
||||
|
||||
func newProviderBenchmarkImpl(headers map[int64]*types.SignedHeader,
|
||||
vals map[int64]*types.ValidatorSet) provider.Provider {
|
||||
func newProviderBenchmarkImpl(headers map[int64]*metadata.SignedHeader,
|
||||
vals map[int64]*consensus.ValidatorSet) provider.Provider {
|
||||
impl := providerBenchmarkImpl{
|
||||
blocks: make(map[int64]*types.LightBlock, len(headers)),
|
||||
}
|
||||
@@ -56,7 +59,7 @@ func (impl *providerBenchmarkImpl) LightBlock(ctx context.Context, height int64)
|
||||
return lb, nil
|
||||
}
|
||||
|
||||
func (impl *providerBenchmarkImpl) ReportEvidence(_ context.Context, _ types.Evidence) error {
|
||||
func (impl *providerBenchmarkImpl) ReportEvidence(_ context.Context, _ evidence.Evidence) error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
|
||||
+54
-52
@@ -20,7 +20,9 @@ import (
|
||||
"github.com/tendermint/tendermint/light/provider"
|
||||
provider_mocks "github.com/tendermint/tendermint/light/provider/mocks"
|
||||
dbs "github.com/tendermint/tendermint/light/store/db"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tendermint/pkg/consensus"
|
||||
types "github.com/tendermint/tendermint/pkg/light"
|
||||
"github.com/tendermint/tendermint/pkg/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -36,23 +38,23 @@ var (
|
||||
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys))
|
||||
// 3/3 signed
|
||||
h2 = keys.GenSignedHeaderLastBlockID(chainID, 2, bTime.Add(30*time.Minute), nil, vals, vals,
|
||||
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys), types.BlockID{Hash: h1.Hash()})
|
||||
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys), metadata.BlockID{Hash: h1.Hash()})
|
||||
// 3/3 signed
|
||||
h3 = keys.GenSignedHeaderLastBlockID(chainID, 3, bTime.Add(1*time.Hour), nil, vals, vals,
|
||||
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys), types.BlockID{Hash: h2.Hash()})
|
||||
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys), metadata.BlockID{Hash: h2.Hash()})
|
||||
trustPeriod = 4 * time.Hour
|
||||
trustOptions = light.TrustOptions{
|
||||
Period: 4 * time.Hour,
|
||||
Height: 1,
|
||||
Hash: h1.Hash(),
|
||||
}
|
||||
valSet = map[int64]*types.ValidatorSet{
|
||||
valSet = map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
2: vals,
|
||||
3: vals,
|
||||
4: vals,
|
||||
}
|
||||
headerSet = map[int64]*types.SignedHeader{
|
||||
headerSet = map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
// interim header (3/3 signed)
|
||||
2: h2,
|
||||
@@ -117,8 +119,8 @@ func TestClient_SequentialVerification(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
otherHeaders map[int64]*types.SignedHeader // all except ^
|
||||
vals map[int64]*types.ValidatorSet
|
||||
otherHeaders map[int64]*metadata.SignedHeader // all except ^
|
||||
vals map[int64]*consensus.ValidatorSet
|
||||
initErr bool
|
||||
verifyErr bool
|
||||
}{
|
||||
@@ -131,12 +133,12 @@ func TestClient_SequentialVerification(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"bad: different first header",
|
||||
map[int64]*types.SignedHeader{
|
||||
map[int64]*metadata.SignedHeader{
|
||||
// different header
|
||||
1: keys.GenSignedHeader(chainID, 1, bTime.Add(1*time.Hour), nil, vals, vals,
|
||||
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)),
|
||||
},
|
||||
map[int64]*types.ValidatorSet{
|
||||
map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
},
|
||||
true,
|
||||
@@ -144,8 +146,8 @@ func TestClient_SequentialVerification(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"bad: no first signed header",
|
||||
map[int64]*types.SignedHeader{},
|
||||
map[int64]*types.ValidatorSet{
|
||||
map[int64]*metadata.SignedHeader{},
|
||||
map[int64]*consensus.ValidatorSet{
|
||||
1: differentVals,
|
||||
},
|
||||
true,
|
||||
@@ -153,10 +155,10 @@ func TestClient_SequentialVerification(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"bad: different first validator set",
|
||||
map[int64]*types.SignedHeader{
|
||||
map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
},
|
||||
map[int64]*types.ValidatorSet{
|
||||
map[int64]*consensus.ValidatorSet{
|
||||
1: differentVals,
|
||||
},
|
||||
true,
|
||||
@@ -164,7 +166,7 @@ func TestClient_SequentialVerification(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"bad: 1/3 signed interim header",
|
||||
map[int64]*types.SignedHeader{
|
||||
map[int64]*metadata.SignedHeader{
|
||||
// trusted header
|
||||
1: h1,
|
||||
// interim header (1/3 signed)
|
||||
@@ -180,7 +182,7 @@ func TestClient_SequentialVerification(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"bad: 1/3 signed last header",
|
||||
map[int64]*types.SignedHeader{
|
||||
map[int64]*metadata.SignedHeader{
|
||||
// trusted header
|
||||
1: h1,
|
||||
// interim header (3/3 signed)
|
||||
@@ -197,7 +199,7 @@ func TestClient_SequentialVerification(t *testing.T) {
|
||||
{
|
||||
"bad: different validator set at height 3",
|
||||
headerSet,
|
||||
map[int64]*types.ValidatorSet{
|
||||
map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
2: vals,
|
||||
3: newVals,
|
||||
@@ -252,14 +254,14 @@ func TestClient_SkippingVerification(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
otherHeaders map[int64]*types.SignedHeader // all except ^
|
||||
vals map[int64]*types.ValidatorSet
|
||||
otherHeaders map[int64]*metadata.SignedHeader // all except ^
|
||||
vals map[int64]*consensus.ValidatorSet
|
||||
initErr bool
|
||||
verifyErr bool
|
||||
}{
|
||||
{
|
||||
"good",
|
||||
map[int64]*types.SignedHeader{
|
||||
map[int64]*metadata.SignedHeader{
|
||||
// trusted header
|
||||
1: h1,
|
||||
// last header (3/3 signed)
|
||||
@@ -271,13 +273,13 @@ func TestClient_SkippingVerification(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"good, but val set changes by 2/3 (1/3 of vals is still present)",
|
||||
map[int64]*types.SignedHeader{
|
||||
map[int64]*metadata.SignedHeader{
|
||||
// trusted header
|
||||
1: h1,
|
||||
3: transitKeys.GenSignedHeader(chainID, 3, bTime.Add(2*time.Hour), nil, transitVals, transitVals,
|
||||
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(transitKeys)),
|
||||
},
|
||||
map[int64]*types.ValidatorSet{
|
||||
map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
2: vals,
|
||||
3: transitVals,
|
||||
@@ -287,7 +289,7 @@ func TestClient_SkippingVerification(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"good, but val set changes 100% at height 2",
|
||||
map[int64]*types.SignedHeader{
|
||||
map[int64]*metadata.SignedHeader{
|
||||
// trusted header
|
||||
1: h1,
|
||||
// interim header (3/3 signed)
|
||||
@@ -297,7 +299,7 @@ func TestClient_SkippingVerification(t *testing.T) {
|
||||
3: newKeys.GenSignedHeader(chainID, 3, bTime.Add(2*time.Hour), nil, newVals, newVals,
|
||||
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(newKeys)),
|
||||
},
|
||||
map[int64]*types.ValidatorSet{
|
||||
map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
2: vals,
|
||||
3: newVals,
|
||||
@@ -307,7 +309,7 @@ func TestClient_SkippingVerification(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"bad: last header signed by newVals, interim header has no signers",
|
||||
map[int64]*types.SignedHeader{
|
||||
map[int64]*metadata.SignedHeader{
|
||||
// trusted header
|
||||
1: h1,
|
||||
// last header (0/4 of the original val set signed)
|
||||
@@ -317,7 +319,7 @@ func TestClient_SkippingVerification(t *testing.T) {
|
||||
3: newKeys.GenSignedHeader(chainID, 3, bTime.Add(2*time.Hour), nil, newVals, newVals,
|
||||
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(newKeys)),
|
||||
},
|
||||
map[int64]*types.ValidatorSet{
|
||||
map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
2: vals,
|
||||
3: newVals,
|
||||
@@ -599,7 +601,7 @@ func TestClient_Concurrency(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClient_AddProviders(t *testing.T) {
|
||||
mockFullNode := mockNodeFromHeadersAndVals(map[int64]*types.SignedHeader{
|
||||
mockFullNode := mockNodeFromHeadersAndVals(map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
2: h2,
|
||||
}, valSet)
|
||||
@@ -725,12 +727,12 @@ func TestClient_BackwardsVerification(t *testing.T) {
|
||||
}
|
||||
{
|
||||
testCases := []struct {
|
||||
headers map[int64]*types.SignedHeader
|
||||
vals map[int64]*types.ValidatorSet
|
||||
headers map[int64]*metadata.SignedHeader
|
||||
vals map[int64]*consensus.ValidatorSet
|
||||
}{
|
||||
{
|
||||
// 7) provides incorrect height
|
||||
headers: map[int64]*types.SignedHeader{
|
||||
headers: map[int64]*metadata.SignedHeader{
|
||||
2: keys.GenSignedHeader(chainID, 1, bTime.Add(30*time.Minute), nil, vals, vals,
|
||||
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)),
|
||||
3: h3,
|
||||
@@ -739,7 +741,7 @@ func TestClient_BackwardsVerification(t *testing.T) {
|
||||
},
|
||||
{
|
||||
// 8) provides incorrect hash
|
||||
headers: map[int64]*types.SignedHeader{
|
||||
headers: map[int64]*metadata.SignedHeader{
|
||||
2: keys.GenSignedHeader(chainID, 2, bTime.Add(30*time.Minute), nil, vals, vals,
|
||||
hash("app_hash2"), hash("cons_hash23"), hash("results_hash30"), 0, len(keys)),
|
||||
3: h3,
|
||||
@@ -797,13 +799,13 @@ func TestClient_NewClientFromTrustedStore(t *testing.T) {
|
||||
|
||||
func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) {
|
||||
// different headers hash then primary plus less than 1/3 signed (no fork)
|
||||
headers1 := map[int64]*types.SignedHeader{
|
||||
headers1 := map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
2: keys.GenSignedHeaderLastBlockID(chainID, 2, bTime.Add(30*time.Minute), nil, vals, vals,
|
||||
hash("app_hash2"), hash("cons_hash"), hash("results_hash"),
|
||||
len(keys), len(keys), types.BlockID{Hash: h1.Hash()}),
|
||||
len(keys), len(keys), metadata.BlockID{Hash: h1.Hash()}),
|
||||
}
|
||||
vals1 := map[int64]*types.ValidatorSet{
|
||||
vals1 := map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
2: vals,
|
||||
}
|
||||
@@ -811,11 +813,11 @@ func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) {
|
||||
mockBadNode1.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrLightBlockNotFound)
|
||||
|
||||
// header is empty
|
||||
headers2 := map[int64]*types.SignedHeader{
|
||||
headers2 := map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
2: h2,
|
||||
}
|
||||
vals2 := map[int64]*types.ValidatorSet{
|
||||
vals2 := map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
2: vals,
|
||||
}
|
||||
@@ -861,24 +863,24 @@ func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) {
|
||||
func TestClient_TrustedValidatorSet(t *testing.T) {
|
||||
differentVals, _ := factory.RandValidatorSet(10, 100)
|
||||
mockBadValSetNode := mockNodeFromHeadersAndVals(
|
||||
map[int64]*types.SignedHeader{
|
||||
map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
// 3/3 signed, but validator set at height 2 below is invalid -> witness
|
||||
// should be removed.
|
||||
2: keys.GenSignedHeaderLastBlockID(chainID, 2, bTime.Add(30*time.Minute), nil, vals, vals,
|
||||
hash("app_hash2"), hash("cons_hash"), hash("results_hash"),
|
||||
0, len(keys), types.BlockID{Hash: h1.Hash()}),
|
||||
0, len(keys), metadata.BlockID{Hash: h1.Hash()}),
|
||||
},
|
||||
map[int64]*types.ValidatorSet{
|
||||
map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
2: differentVals,
|
||||
})
|
||||
mockFullNode := mockNodeFromHeadersAndVals(
|
||||
map[int64]*types.SignedHeader{
|
||||
map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
2: h2,
|
||||
},
|
||||
map[int64]*types.ValidatorSet{
|
||||
map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
2: vals,
|
||||
})
|
||||
@@ -904,12 +906,12 @@ func TestClient_TrustedValidatorSet(t *testing.T) {
|
||||
|
||||
func TestClientPrunesHeadersAndValidatorSets(t *testing.T) {
|
||||
mockFullNode := mockNodeFromHeadersAndVals(
|
||||
map[int64]*types.SignedHeader{
|
||||
map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
3: h3,
|
||||
0: h3,
|
||||
},
|
||||
map[int64]*types.ValidatorSet{
|
||||
map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
3: vals,
|
||||
0: vals,
|
||||
@@ -939,14 +941,14 @@ func TestClientPrunesHeadersAndValidatorSets(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientEnsureValidHeadersAndValSets(t *testing.T) {
|
||||
emptyValSet := &types.ValidatorSet{
|
||||
emptyValSet := &consensus.ValidatorSet{
|
||||
Validators: nil,
|
||||
Proposer: nil,
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
headers map[int64]*types.SignedHeader
|
||||
vals map[int64]*types.ValidatorSet
|
||||
headers map[int64]*metadata.SignedHeader
|
||||
vals map[int64]*consensus.ValidatorSet
|
||||
|
||||
errorToThrow error
|
||||
errorHeight int64
|
||||
@@ -954,21 +956,21 @@ func TestClientEnsureValidHeadersAndValSets(t *testing.T) {
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
headers: map[int64]*types.SignedHeader{
|
||||
headers: map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
3: h3,
|
||||
},
|
||||
vals: map[int64]*types.ValidatorSet{
|
||||
vals: map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
3: vals,
|
||||
},
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
headers: map[int64]*types.SignedHeader{
|
||||
headers: map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
},
|
||||
vals: map[int64]*types.ValidatorSet{
|
||||
vals: map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
},
|
||||
errorToThrow: provider.ErrBadLightBlock{Reason: errors.New("nil header or vals")},
|
||||
@@ -976,7 +978,7 @@ func TestClientEnsureValidHeadersAndValSets(t *testing.T) {
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
headers: map[int64]*types.SignedHeader{
|
||||
headers: map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
},
|
||||
errorToThrow: provider.ErrBadLightBlock{Reason: errors.New("nil header or vals")},
|
||||
@@ -985,11 +987,11 @@ func TestClientEnsureValidHeadersAndValSets(t *testing.T) {
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
headers: map[int64]*types.SignedHeader{
|
||||
headers: map[int64]*metadata.SignedHeader{
|
||||
1: h1,
|
||||
3: h3,
|
||||
},
|
||||
vals: map[int64]*types.ValidatorSet{
|
||||
vals: map[int64]*consensus.ValidatorSet{
|
||||
1: vals,
|
||||
3: emptyValSet,
|
||||
},
|
||||
|
||||
+16
-14
@@ -8,7 +8,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/light/provider"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tendermint/pkg/evidence"
|
||||
lighttypes "github.com/tendermint/tendermint/pkg/light"
|
||||
"github.com/tendermint/tendermint/pkg/metadata"
|
||||
)
|
||||
|
||||
// The detector component of the light client detects and handles attacks on the light client.
|
||||
@@ -25,7 +27,7 @@ import (
|
||||
//
|
||||
// If there are no conflictinge headers, the light client deems the verified target header
|
||||
// trusted and saves it to the trusted store.
|
||||
func (c *Client) detectDivergence(ctx context.Context, primaryTrace []*types.LightBlock, now time.Time) error {
|
||||
func (c *Client) detectDivergence(ctx context.Context, primaryTrace []*lighttypes.LightBlock, now time.Time) error {
|
||||
if primaryTrace == nil || len(primaryTrace) < 2 {
|
||||
return errors.New("nil or single block primary trace")
|
||||
}
|
||||
@@ -107,7 +109,7 @@ func (c *Client) detectDivergence(ctx context.Context, primaryTrace []*types.Lig
|
||||
// 2: errBadWitness -> the witness has either not responded, doesn't have the header or has given us an invalid one
|
||||
// Note: In the case of an invalid header we remove the witness
|
||||
// 3: nil -> the hashes of the two headers match
|
||||
func (c *Client) compareNewHeaderWithWitness(ctx context.Context, errc chan error, h *types.SignedHeader,
|
||||
func (c *Client) compareNewHeaderWithWitness(ctx context.Context, errc chan error, h *metadata.SignedHeader,
|
||||
witness provider.Provider, witnessIndex int) {
|
||||
|
||||
lightBlock, err := witness.LightBlock(ctx, h.Height)
|
||||
@@ -203,7 +205,7 @@ func (c *Client) compareNewHeaderWithWitness(ctx context.Context, errc chan erro
|
||||
}
|
||||
|
||||
// sendEvidence sends evidence to a provider on a best effort basis.
|
||||
func (c *Client) sendEvidence(ctx context.Context, ev *types.LightClientAttackEvidence, receiver provider.Provider) {
|
||||
func (c *Client) sendEvidence(ctx context.Context, ev *evidence.LightClientAttackEvidence, receiver provider.Provider) {
|
||||
err := receiver.ReportEvidence(ctx, ev)
|
||||
if err != nil {
|
||||
c.logger.Error("failed to report evidence to provider", "ev", ev, "provider", receiver)
|
||||
@@ -214,8 +216,8 @@ func (c *Client) sendEvidence(ctx context.Context, ev *types.LightClientAttackEv
|
||||
// two headers of the same height but with different hashes
|
||||
func (c *Client) handleConflictingHeaders(
|
||||
ctx context.Context,
|
||||
primaryTrace []*types.LightBlock,
|
||||
challendingBlock *types.LightBlock,
|
||||
primaryTrace []*lighttypes.LightBlock,
|
||||
challendingBlock *lighttypes.LightBlock,
|
||||
witnessIndex int,
|
||||
now time.Time,
|
||||
) error {
|
||||
@@ -287,14 +289,14 @@ func (c *Client) handleConflictingHeaders(
|
||||
// 3. The
|
||||
func (c *Client) examineConflictingHeaderAgainstTrace(
|
||||
ctx context.Context,
|
||||
trace []*types.LightBlock,
|
||||
targetBlock *types.LightBlock,
|
||||
trace []*lighttypes.LightBlock,
|
||||
targetBlock *lighttypes.LightBlock,
|
||||
source provider.Provider, now time.Time,
|
||||
) ([]*types.LightBlock, *types.LightBlock, error) {
|
||||
) ([]*lighttypes.LightBlock, *lighttypes.LightBlock, error) {
|
||||
|
||||
var (
|
||||
previouslyVerifiedBlock, sourceBlock *types.LightBlock
|
||||
sourceTrace []*types.LightBlock
|
||||
previouslyVerifiedBlock, sourceBlock *lighttypes.LightBlock
|
||||
sourceTrace []*lighttypes.LightBlock
|
||||
err error
|
||||
)
|
||||
|
||||
@@ -378,7 +380,7 @@ func (c *Client) getTargetBlockOrLatest(
|
||||
ctx context.Context,
|
||||
height int64,
|
||||
witness provider.Provider,
|
||||
) (bool, *types.LightBlock, error) {
|
||||
) (bool, *lighttypes.LightBlock, error) {
|
||||
lightBlock, err := witness.LightBlock(ctx, 0)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
@@ -403,8 +405,8 @@ func (c *Client) getTargetBlockOrLatest(
|
||||
|
||||
// newLightClientAttackEvidence determines the type of attack and then forms the evidence filling out
|
||||
// all the fields such that it is ready to be sent to a full node.
|
||||
func newLightClientAttackEvidence(conflicted, trusted, common *types.LightBlock) *types.LightClientAttackEvidence {
|
||||
ev := &types.LightClientAttackEvidence{ConflictingBlock: conflicted}
|
||||
func newLightClientAttackEvidence(conflicted, trusted, common *lighttypes.LightBlock) *evidence.LightClientAttackEvidence {
|
||||
ev := &evidence.LightClientAttackEvidence{ConflictingBlock: conflicted}
|
||||
// We use the common height to indicate the form of the attack.
|
||||
// if this is an equivocation or amnesia attack, i.e. the validator sets are the same, then we
|
||||
// return the height of the conflicting block as the common height. If instead it is a lunatic
|
||||
|
||||
+33
-29
@@ -16,7 +16,11 @@ import (
|
||||
"github.com/tendermint/tendermint/light/provider"
|
||||
provider_mocks "github.com/tendermint/tendermint/light/provider/mocks"
|
||||
dbs "github.com/tendermint/tendermint/light/store/db"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tendermint/pkg/consensus"
|
||||
"github.com/tendermint/tendermint/pkg/evidence"
|
||||
lighttypes "github.com/tendermint/tendermint/pkg/light"
|
||||
"github.com/tendermint/tendermint/pkg/mempool"
|
||||
"github.com/tendermint/tendermint/pkg/metadata"
|
||||
)
|
||||
|
||||
func TestLightClientAttackEvidence_Lunatic(t *testing.T) {
|
||||
@@ -25,8 +29,8 @@ func TestLightClientAttackEvidence_Lunatic(t *testing.T) {
|
||||
latestHeight = int64(3)
|
||||
valSize = 5
|
||||
divergenceHeight = int64(2)
|
||||
primaryHeaders = make(map[int64]*types.SignedHeader, latestHeight)
|
||||
primaryValidators = make(map[int64]*types.ValidatorSet, latestHeight)
|
||||
primaryHeaders = make(map[int64]*metadata.SignedHeader, latestHeight)
|
||||
primaryValidators = make(map[int64]*consensus.ValidatorSet, latestHeight)
|
||||
)
|
||||
|
||||
witnessHeaders, witnessValidators, chainKeys := genLightBlocksWithKeys(chainID, latestHeight, valSize, 2, bTime)
|
||||
@@ -52,29 +56,29 @@ func TestLightClientAttackEvidence_Lunatic(t *testing.T) {
|
||||
mockWitness := mockNodeFromHeadersAndVals(witnessHeaders, witnessValidators)
|
||||
mockPrimary := mockNodeFromHeadersAndVals(primaryHeaders, primaryValidators)
|
||||
|
||||
mockWitness.On("ReportEvidence", mock.Anything, mock.MatchedBy(func(evidence types.Evidence) bool {
|
||||
evAgainstPrimary := &types.LightClientAttackEvidence{
|
||||
mockWitness.On("ReportEvidence", mock.Anything, mock.MatchedBy(func(ev evidence.Evidence) bool {
|
||||
evAgainstPrimary := &evidence.LightClientAttackEvidence{
|
||||
// after the divergence height the valset doesn't change so we expect the evidence to be for the latest height
|
||||
ConflictingBlock: &types.LightBlock{
|
||||
ConflictingBlock: &lighttypes.LightBlock{
|
||||
SignedHeader: primaryHeaders[latestHeight],
|
||||
ValidatorSet: primaryValidators[latestHeight],
|
||||
},
|
||||
CommonHeight: 1,
|
||||
}
|
||||
return bytes.Equal(evidence.Hash(), evAgainstPrimary.Hash())
|
||||
return bytes.Equal(ev.Hash(), evAgainstPrimary.Hash())
|
||||
})).Return(nil)
|
||||
|
||||
mockPrimary.On("ReportEvidence", mock.Anything, mock.MatchedBy(func(evidence types.Evidence) bool {
|
||||
evAgainstWitness := &types.LightClientAttackEvidence{
|
||||
mockPrimary.On("ReportEvidence", mock.Anything, mock.MatchedBy(func(ev evidence.Evidence) bool {
|
||||
evAgainstWitness := &evidence.LightClientAttackEvidence{
|
||||
// when forming evidence against witness we learn that the canonical chain continued to change validator sets
|
||||
// hence the conflicting block is at 7
|
||||
ConflictingBlock: &types.LightBlock{
|
||||
ConflictingBlock: &lighttypes.LightBlock{
|
||||
SignedHeader: witnessHeaders[divergenceHeight+1],
|
||||
ValidatorSet: witnessValidators[divergenceHeight+1],
|
||||
},
|
||||
CommonHeight: divergenceHeight - 1,
|
||||
}
|
||||
return bytes.Equal(evidence.Hash(), evAgainstWitness.Hash())
|
||||
return bytes.Equal(ev.Hash(), evAgainstWitness.Hash())
|
||||
})).Return(nil)
|
||||
|
||||
c, err := light.NewClient(
|
||||
@@ -134,9 +138,9 @@ func TestLightClientAttackEvidence_Equivocation(t *testing.T) {
|
||||
// primary performs an equivocation attack
|
||||
var (
|
||||
valSize = 5
|
||||
primaryHeaders = make(map[int64]*types.SignedHeader, testCase.latestHeight)
|
||||
primaryHeaders = make(map[int64]*metadata.SignedHeader, testCase.latestHeight)
|
||||
// validators don't change in this network (however we still use a map just for convenience)
|
||||
primaryValidators = make(map[int64]*types.ValidatorSet, testCase.latestHeight)
|
||||
primaryValidators = make(map[int64]*consensus.ValidatorSet, testCase.latestHeight)
|
||||
)
|
||||
witnessHeaders, witnessValidators, chainKeys := genLightBlocksWithKeys(chainID,
|
||||
testCase.latestHeight+1, valSize, 2, bTime)
|
||||
@@ -149,7 +153,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,
|
||||
bTime.Add(time.Duration(height)*time.Minute), []types.Tx{[]byte("abcd")},
|
||||
bTime.Add(time.Duration(height)*time.Minute), []mempool.Tx{[]byte("abcd")},
|
||||
witnessValidators[height], witnessValidators[height+1], hash("app_hash"),
|
||||
hash("cons_hash"), hash("results_hash"), 0, len(chainKeys[height])-1)
|
||||
primaryValidators[height] = witnessValidators[height]
|
||||
@@ -167,25 +171,25 @@ func TestLightClientAttackEvidence_Equivocation(t *testing.T) {
|
||||
// Check evidence was sent to both full nodes.
|
||||
// Common height should be set to the height of the divergent header in the instance
|
||||
// of an equivocation attack and the validator sets are the same as what the witness has
|
||||
mockWitness.On("ReportEvidence", mock.Anything, mock.MatchedBy(func(evidence types.Evidence) bool {
|
||||
evAgainstPrimary := &types.LightClientAttackEvidence{
|
||||
ConflictingBlock: &types.LightBlock{
|
||||
mockWitness.On("ReportEvidence", mock.Anything, mock.MatchedBy(func(ev evidence.Evidence) bool {
|
||||
evAgainstPrimary := &evidence.LightClientAttackEvidence{
|
||||
ConflictingBlock: &lighttypes.LightBlock{
|
||||
SignedHeader: primaryHeaders[testCase.divergenceHeight],
|
||||
ValidatorSet: primaryValidators[testCase.divergenceHeight],
|
||||
},
|
||||
CommonHeight: testCase.divergenceHeight,
|
||||
}
|
||||
return bytes.Equal(evidence.Hash(), evAgainstPrimary.Hash())
|
||||
return bytes.Equal(ev.Hash(), evAgainstPrimary.Hash())
|
||||
})).Return(nil)
|
||||
mockPrimary.On("ReportEvidence", mock.Anything, mock.MatchedBy(func(evidence types.Evidence) bool {
|
||||
evAgainstWitness := &types.LightClientAttackEvidence{
|
||||
ConflictingBlock: &types.LightBlock{
|
||||
mockPrimary.On("ReportEvidence", mock.Anything, mock.MatchedBy(func(ev evidence.Evidence) bool {
|
||||
evAgainstWitness := &evidence.LightClientAttackEvidence{
|
||||
ConflictingBlock: &lighttypes.LightBlock{
|
||||
SignedHeader: witnessHeaders[testCase.divergenceHeight],
|
||||
ValidatorSet: witnessValidators[testCase.divergenceHeight],
|
||||
},
|
||||
CommonHeight: testCase.divergenceHeight,
|
||||
}
|
||||
return bytes.Equal(evidence.Hash(), evAgainstWitness.Hash())
|
||||
return bytes.Equal(ev.Hash(), evAgainstWitness.Hash())
|
||||
})).Return(nil)
|
||||
|
||||
c, err := light.NewClient(
|
||||
@@ -224,8 +228,8 @@ func TestLightClientAttackEvidence_ForwardLunatic(t *testing.T) {
|
||||
valSize = 5
|
||||
forgedHeight = int64(12)
|
||||
proofHeight = int64(11)
|
||||
primaryHeaders = make(map[int64]*types.SignedHeader, forgedHeight)
|
||||
primaryValidators = make(map[int64]*types.ValidatorSet, forgedHeight)
|
||||
primaryHeaders = make(map[int64]*metadata.SignedHeader, forgedHeight)
|
||||
primaryValidators = make(map[int64]*consensus.ValidatorSet, forgedHeight)
|
||||
)
|
||||
|
||||
witnessHeaders, witnessValidators, chainKeys := genLightBlocksWithKeys(chainID, latestHeight, valSize, 2, bTime)
|
||||
@@ -271,16 +275,16 @@ func TestLightClientAttackEvidence_ForwardLunatic(t *testing.T) {
|
||||
mockWitness.On("LightBlock", mock.Anything, int64(0)).Return(lastBlock, nil).Once()
|
||||
mockWitness.On("LightBlock", mock.Anything, int64(12)).Return(nil, provider.ErrHeightTooHigh)
|
||||
|
||||
mockWitness.On("ReportEvidence", mock.Anything, mock.MatchedBy(func(evidence types.Evidence) bool {
|
||||
mockWitness.On("ReportEvidence", mock.Anything, mock.MatchedBy(func(ev evidence.Evidence) bool {
|
||||
// Check evidence was sent to the witness against the full node
|
||||
evAgainstPrimary := &types.LightClientAttackEvidence{
|
||||
ConflictingBlock: &types.LightBlock{
|
||||
evAgainstPrimary := &evidence.LightClientAttackEvidence{
|
||||
ConflictingBlock: &lighttypes.LightBlock{
|
||||
SignedHeader: primaryHeaders[forgedHeight],
|
||||
ValidatorSet: primaryValidators[forgedHeight],
|
||||
},
|
||||
CommonHeight: latestHeight,
|
||||
}
|
||||
return bytes.Equal(evidence.Hash(), evAgainstPrimary.Hash())
|
||||
return bytes.Equal(ev.Hash(), evAgainstPrimary.Hash())
|
||||
})).Return(nil).Twice()
|
||||
|
||||
// In order to perform the attack, the primary needs at least one accomplice as a witness to also
|
||||
@@ -307,7 +311,7 @@ func TestLightClientAttackEvidence_ForwardLunatic(t *testing.T) {
|
||||
// two seconds later, the supporting withness should receive the header that can be used
|
||||
// to prove that there was an attack
|
||||
vals := chainKeys[latestHeight].ToValidators(2, 0)
|
||||
newLb := &types.LightBlock{
|
||||
newLb := &lighttypes.LightBlock{
|
||||
SignedHeader: chainKeys[latestHeight].GenSignedHeader(
|
||||
chainID,
|
||||
proofHeight,
|
||||
|
||||
+4
-3
@@ -5,7 +5,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tendermint/pkg/consensus"
|
||||
"github.com/tendermint/tendermint/pkg/light"
|
||||
)
|
||||
|
||||
// ErrOldHeaderExpired means the old (trusted) header has expired according to
|
||||
@@ -23,7 +24,7 @@ func (e ErrOldHeaderExpired) Error() string {
|
||||
// ErrNewValSetCantBeTrusted means the new validator set cannot be trusted
|
||||
// because < 1/3rd (+trustLevel+) of the old validator set has signed.
|
||||
type ErrNewValSetCantBeTrusted struct {
|
||||
Reason types.ErrNotEnoughVotingPowerSigned
|
||||
Reason consensus.ErrNotEnoughVotingPowerSigned
|
||||
}
|
||||
|
||||
func (e ErrNewValSetCantBeTrusted) Error() string {
|
||||
@@ -80,7 +81,7 @@ var ErrNoWitnesses = errors.New("no witnesses connected. please reset light clie
|
||||
|
||||
// ErrConflictingHeaders is thrown when two conflicting headers are discovered.
|
||||
type errConflictingHeaders struct {
|
||||
Block *types.LightBlock
|
||||
Block *light.LightBlock
|
||||
WitnessIndex int
|
||||
}
|
||||
|
||||
|
||||
+36
-33
@@ -9,8 +9,11 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
tmtime "github.com/tendermint/tendermint/libs/time"
|
||||
provider_mocks "github.com/tendermint/tendermint/light/provider/mocks"
|
||||
"github.com/tendermint/tendermint/pkg/consensus"
|
||||
"github.com/tendermint/tendermint/pkg/light"
|
||||
"github.com/tendermint/tendermint/pkg/mempool"
|
||||
"github.com/tendermint/tendermint/pkg/metadata"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tendermint/version"
|
||||
)
|
||||
|
||||
@@ -65,24 +68,24 @@ func (pkz privKeys) Extend(n int) privKeys {
|
||||
// The first key has weight `init` and it increases by `inc` every step
|
||||
// so we can have all the same weight, or a simple linear distribution
|
||||
// (should be enough for testing).
|
||||
func (pkz privKeys) ToValidators(init, inc int64) *types.ValidatorSet {
|
||||
res := make([]*types.Validator, len(pkz))
|
||||
func (pkz privKeys) ToValidators(init, inc int64) *consensus.ValidatorSet {
|
||||
res := make([]*consensus.Validator, len(pkz))
|
||||
for i, k := range pkz {
|
||||
res[i] = types.NewValidator(k.PubKey(), init+int64(i)*inc)
|
||||
res[i] = consensus.NewValidator(k.PubKey(), init+int64(i)*inc)
|
||||
}
|
||||
return types.NewValidatorSet(res)
|
||||
return consensus.NewValidatorSet(res)
|
||||
}
|
||||
|
||||
// signHeader properly signs the header with all keys from first to last exclusive.
|
||||
func (pkz privKeys) signHeader(header *types.Header, valSet *types.ValidatorSet, first, last int) *types.Commit {
|
||||
commitSigs := make([]types.CommitSig, len(pkz))
|
||||
func (pkz privKeys) signHeader(header *metadata.Header, valSet *consensus.ValidatorSet, first, last int) *metadata.Commit {
|
||||
commitSigs := make([]metadata.CommitSig, len(pkz))
|
||||
for i := 0; i < len(pkz); i++ {
|
||||
commitSigs[i] = types.NewCommitSigAbsent()
|
||||
commitSigs[i] = metadata.NewCommitSigAbsent()
|
||||
}
|
||||
|
||||
blockID := types.BlockID{
|
||||
blockID := metadata.BlockID{
|
||||
Hash: header.Hash(),
|
||||
PartSetHeader: types.PartSetHeader{Total: 1, Hash: crypto.CRandBytes(32)},
|
||||
PartSetHeader: metadata.PartSetHeader{Total: 1, Hash: crypto.CRandBytes(32)},
|
||||
}
|
||||
|
||||
// Fill in the votes we want.
|
||||
@@ -91,15 +94,15 @@ func (pkz privKeys) signHeader(header *types.Header, valSet *types.ValidatorSet,
|
||||
commitSigs[vote.ValidatorIndex] = vote.CommitSig()
|
||||
}
|
||||
|
||||
return types.NewCommit(header.Height, 1, blockID, commitSigs)
|
||||
return metadata.NewCommit(header.Height, 1, blockID, commitSigs)
|
||||
}
|
||||
|
||||
func makeVote(header *types.Header, valset *types.ValidatorSet,
|
||||
key crypto.PrivKey, blockID types.BlockID) *types.Vote {
|
||||
func makeVote(header *metadata.Header, valset *consensus.ValidatorSet,
|
||||
key crypto.PrivKey, blockID metadata.BlockID) *consensus.Vote {
|
||||
|
||||
addr := key.PubKey().Address()
|
||||
idx, _ := valset.GetByAddress(addr)
|
||||
vote := &types.Vote{
|
||||
vote := &consensus.Vote{
|
||||
ValidatorAddress: addr,
|
||||
ValidatorIndex: idx,
|
||||
Height: header.Height,
|
||||
@@ -111,7 +114,7 @@ func makeVote(header *types.Header, valset *types.ValidatorSet,
|
||||
|
||||
v := vote.ToProto()
|
||||
// Sign it
|
||||
signBytes := types.VoteSignBytes(header.ChainID, v)
|
||||
signBytes := consensus.VoteSignBytes(header.ChainID, v)
|
||||
sig, err := key.Sign(signBytes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -122,10 +125,10 @@ func makeVote(header *types.Header, valset *types.ValidatorSet,
|
||||
return vote
|
||||
}
|
||||
|
||||
func genHeader(chainID string, height int64, bTime time.Time, txs types.Txs,
|
||||
valset, nextValset *types.ValidatorSet, appHash, consHash, resHash []byte) *types.Header {
|
||||
func genHeader(chainID string, height int64, bTime time.Time, txs mempool.Txs,
|
||||
valset, nextValset *consensus.ValidatorSet, appHash, consHash, resHash []byte) *metadata.Header {
|
||||
|
||||
return &types.Header{
|
||||
return &metadata.Header{
|
||||
Version: version.Consensus{Block: version.BlockProtocol, App: 0},
|
||||
ChainID: chainID,
|
||||
Height: height,
|
||||
@@ -143,24 +146,24 @@ func genHeader(chainID string, height int64, bTime time.Time, txs types.Txs,
|
||||
}
|
||||
|
||||
// GenSignedHeader calls genHeader and signHeader and combines them into a SignedHeader.
|
||||
func (pkz privKeys) GenSignedHeader(chainID string, height int64, bTime time.Time, txs types.Txs,
|
||||
valset, nextValset *types.ValidatorSet, appHash, consHash, resHash []byte, first, last int) *types.SignedHeader {
|
||||
func (pkz privKeys) GenSignedHeader(chainID string, height int64, bTime time.Time, txs mempool.Txs,
|
||||
valset, nextValset *consensus.ValidatorSet, appHash, consHash, resHash []byte, first, last int) *metadata.SignedHeader {
|
||||
|
||||
header := genHeader(chainID, height, bTime, txs, valset, nextValset, appHash, consHash, resHash)
|
||||
return &types.SignedHeader{
|
||||
return &metadata.SignedHeader{
|
||||
Header: header,
|
||||
Commit: pkz.signHeader(header, valset, first, last),
|
||||
}
|
||||
}
|
||||
|
||||
// GenSignedHeaderLastBlockID calls genHeader and signHeader and combines them into a SignedHeader.
|
||||
func (pkz privKeys) GenSignedHeaderLastBlockID(chainID string, height int64, bTime time.Time, txs types.Txs,
|
||||
valset, nextValset *types.ValidatorSet, appHash, consHash, resHash []byte, first, last int,
|
||||
lastBlockID types.BlockID) *types.SignedHeader {
|
||||
func (pkz privKeys) GenSignedHeaderLastBlockID(chainID string, height int64, bTime time.Time, txs mempool.Txs,
|
||||
valset, nextValset *consensus.ValidatorSet, appHash, consHash, resHash []byte, first, last int,
|
||||
lastBlockID metadata.BlockID) *metadata.SignedHeader {
|
||||
|
||||
header := genHeader(chainID, height, bTime, txs, valset, nextValset, appHash, consHash, resHash)
|
||||
header.LastBlockID = lastBlockID
|
||||
return &types.SignedHeader{
|
||||
return &metadata.SignedHeader{
|
||||
Header: header,
|
||||
Commit: pkz.signHeader(header, valset, first, last),
|
||||
}
|
||||
@@ -180,13 +183,13 @@ func genLightBlocksWithKeys(
|
||||
valSize int,
|
||||
valVariation float32,
|
||||
bTime time.Time) (
|
||||
map[int64]*types.SignedHeader,
|
||||
map[int64]*types.ValidatorSet,
|
||||
map[int64]*metadata.SignedHeader,
|
||||
map[int64]*consensus.ValidatorSet,
|
||||
map[int64]privKeys) {
|
||||
|
||||
var (
|
||||
headers = make(map[int64]*types.SignedHeader, numBlocks)
|
||||
valset = make(map[int64]*types.ValidatorSet, numBlocks+1)
|
||||
headers = make(map[int64]*metadata.SignedHeader, numBlocks)
|
||||
valset = make(map[int64]*consensus.ValidatorSet, numBlocks+1)
|
||||
keymap = make(map[int64]privKeys, numBlocks+1)
|
||||
keys = genPrivKeys(valSize)
|
||||
totalVariation = valVariation
|
||||
@@ -217,7 +220,7 @@ func genLightBlocksWithKeys(
|
||||
currentHeader = keys.GenSignedHeaderLastBlockID(chainID, height, bTime.Add(time.Duration(height)*time.Minute),
|
||||
nil,
|
||||
keys.ToValidators(2, 0), newKeys.ToValidators(2, 0), hash("app_hash"), hash("cons_hash"),
|
||||
hash("results_hash"), 0, len(keys), types.BlockID{Hash: lastHeader.Hash()})
|
||||
hash("results_hash"), 0, len(keys), metadata.BlockID{Hash: lastHeader.Hash()})
|
||||
headers[height] = currentHeader
|
||||
valset[height] = keys.ToValidators(2, 0)
|
||||
lastHeader = currentHeader
|
||||
@@ -228,11 +231,11 @@ func genLightBlocksWithKeys(
|
||||
return headers, valset, keymap
|
||||
}
|
||||
|
||||
func mockNodeFromHeadersAndVals(headers map[int64]*types.SignedHeader,
|
||||
vals map[int64]*types.ValidatorSet) *provider_mocks.Provider {
|
||||
func mockNodeFromHeadersAndVals(headers map[int64]*metadata.SignedHeader,
|
||||
vals map[int64]*consensus.ValidatorSet) *provider_mocks.Provider {
|
||||
mockNode := &provider_mocks.Provider{}
|
||||
for i, header := range headers {
|
||||
lb := &types.LightBlock{SignedHeader: header, ValidatorSet: vals[i]}
|
||||
lb := &light.LightBlock{SignedHeader: header, ValidatorSet: vals[i]}
|
||||
mockNode.On("LightBlock", mock.Anything, i).Return(lb, nil)
|
||||
}
|
||||
return mockNode
|
||||
|
||||
+2
-2
@@ -16,8 +16,8 @@ import (
|
||||
"github.com/tendermint/tendermint/light/provider"
|
||||
httpp "github.com/tendermint/tendermint/light/provider/http"
|
||||
dbs "github.com/tendermint/tendermint/light/store/db"
|
||||
lighttypes "github.com/tendermint/tendermint/pkg/light"
|
||||
rpctest "github.com/tendermint/tendermint/rpc/test"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// NOTE: these are ports of the tests from example_test.go but
|
||||
@@ -143,7 +143,7 @@ func TestClientIntegration_VerifyLightBlockAtHeight(t *testing.T) {
|
||||
require.EqualValues(t, 3, h.Height)
|
||||
}
|
||||
|
||||
func waitForBlock(ctx context.Context, p provider.Provider, height int64) (*types.LightBlock, error) {
|
||||
func waitForBlock(ctx context.Context, p provider.Provider, height int64) (*lighttypes.LightBlock, error) {
|
||||
for {
|
||||
block, err := p.LightBlock(ctx, height)
|
||||
switch err {
|
||||
|
||||
@@ -10,7 +10,8 @@ import (
|
||||
|
||||
tmjson "github.com/tendermint/tendermint/libs/json"
|
||||
"github.com/tendermint/tendermint/light"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tendermint/pkg/consensus"
|
||||
"github.com/tendermint/tendermint/pkg/metadata"
|
||||
)
|
||||
|
||||
const jsonDir = "./json"
|
||||
@@ -101,10 +102,10 @@ type testCase struct {
|
||||
}
|
||||
|
||||
type initialData struct {
|
||||
SignedHeader types.SignedHeader `json:"signed_header"`
|
||||
NextValidatorSet types.ValidatorSet `json:"next_validator_set"`
|
||||
TrustingPeriod uint64 `json:"trusting_period"`
|
||||
Now time.Time `json:"now"`
|
||||
SignedHeader metadata.SignedHeader `json:"signed_header"`
|
||||
NextValidatorSet consensus.ValidatorSet `json:"next_validator_set"`
|
||||
TrustingPeriod uint64 `json:"trusting_period"`
|
||||
Now time.Time `json:"now"`
|
||||
}
|
||||
|
||||
type inputData struct {
|
||||
@@ -116,7 +117,7 @@ type inputData struct {
|
||||
// In tendermint-rs, NextValidatorSet is used to verify new blocks (opposite to
|
||||
// Go tendermint).
|
||||
type lightBlockWithNextValidatorSet struct {
|
||||
*types.SignedHeader `json:"signed_header"`
|
||||
ValidatorSet *types.ValidatorSet `json:"validator_set"`
|
||||
NextValidatorSet *types.ValidatorSet `json:"next_validator_set"`
|
||||
*metadata.SignedHeader `json:"signed_header"`
|
||||
ValidatorSet *consensus.ValidatorSet `json:"validator_set"`
|
||||
NextValidatorSet *consensus.ValidatorSet `json:"next_validator_set"`
|
||||
}
|
||||
|
||||
@@ -10,11 +10,14 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/light/provider"
|
||||
"github.com/tendermint/tendermint/pkg/consensus"
|
||||
"github.com/tendermint/tendermint/pkg/evidence"
|
||||
types "github.com/tendermint/tendermint/pkg/light"
|
||||
"github.com/tendermint/tendermint/pkg/metadata"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
var defaultOptions = Options{
|
||||
@@ -148,12 +151,12 @@ func (p *http) LightBlock(ctx context.Context, height int64) (*types.LightBlock,
|
||||
}
|
||||
|
||||
// ReportEvidence calls `/broadcast_evidence` endpoint.
|
||||
func (p *http) ReportEvidence(ctx context.Context, ev types.Evidence) error {
|
||||
func (p *http) ReportEvidence(ctx context.Context, ev evidence.Evidence) error {
|
||||
_, err := p.client.BroadcastEvidence(ctx, ev)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *http) validatorSet(ctx context.Context, height *int64) (*types.ValidatorSet, error) {
|
||||
func (p *http) validatorSet(ctx context.Context, height *int64) (*consensus.ValidatorSet, error) {
|
||||
// Since the malicious node could report a massive number of pages, making us
|
||||
// spend a considerable time iterating, we restrict the number of pages here.
|
||||
// => 10000 validators max
|
||||
@@ -161,7 +164,7 @@ func (p *http) validatorSet(ctx context.Context, height *int64) (*types.Validato
|
||||
|
||||
var (
|
||||
perPage = 100
|
||||
vals = []*types.Validator{}
|
||||
vals = []*consensus.Validator{}
|
||||
page = 1
|
||||
total = -1
|
||||
)
|
||||
@@ -224,14 +227,14 @@ func (p *http) validatorSet(ctx context.Context, height *int64) (*types.Validato
|
||||
}
|
||||
}
|
||||
|
||||
valSet, err := types.ValidatorSetFromExistingValidators(vals)
|
||||
valSet, err := consensus.ValidatorSetFromExistingValidators(vals)
|
||||
if err != nil {
|
||||
return nil, provider.ErrBadLightBlock{Reason: err}
|
||||
}
|
||||
return valSet, nil
|
||||
}
|
||||
|
||||
func (p *http) signedHeader(ctx context.Context, height *int64) (*types.SignedHeader, error) {
|
||||
func (p *http) signedHeader(ctx context.Context, height *int64) (*metadata.SignedHeader, error) {
|
||||
// create a for loop to control retries. If p.maxRetryAttempts
|
||||
// is negative we will keep repeating.
|
||||
for attempt := uint16(0); attempt != p.maxRetryAttempts+1; attempt++ {
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
"github.com/tendermint/tendermint/light/provider"
|
||||
lighthttp "github.com/tendermint/tendermint/light/provider/http"
|
||||
"github.com/tendermint/tendermint/pkg/consensus"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||
rpctest "github.com/tendermint/tendermint/rpc/test"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
func TestNewProvider(t *testing.T) {
|
||||
@@ -44,7 +44,7 @@ func TestProvider(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
rpcAddr := cfg.RPC.ListenAddress
|
||||
genDoc, err := types.GenesisDocFromFile(cfg.GenesisFile())
|
||||
genDoc, err := consensus.GenesisDocFromFile(cfg.GenesisFile())
|
||||
require.NoError(t, err)
|
||||
|
||||
chainID := genDoc.ChainID
|
||||
|
||||
@@ -5,9 +5,10 @@ package mocks
|
||||
import (
|
||||
context "context"
|
||||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
evidence "github.com/tendermint/tendermint/pkg/evidence"
|
||||
light "github.com/tendermint/tendermint/pkg/light"
|
||||
|
||||
types "github.com/tendermint/tendermint/types"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// Provider is an autogenerated mock type for the Provider type
|
||||
@@ -16,15 +17,15 @@ type Provider struct {
|
||||
}
|
||||
|
||||
// LightBlock provides a mock function with given fields: ctx, height
|
||||
func (_m *Provider) LightBlock(ctx context.Context, height int64) (*types.LightBlock, error) {
|
||||
func (_m *Provider) LightBlock(ctx context.Context, height int64) (*light.LightBlock, error) {
|
||||
ret := _m.Called(ctx, height)
|
||||
|
||||
var r0 *types.LightBlock
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) *types.LightBlock); ok {
|
||||
var r0 *light.LightBlock
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) *light.LightBlock); ok {
|
||||
r0 = rf(ctx, height)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*types.LightBlock)
|
||||
r0 = ret.Get(0).(*light.LightBlock)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +40,11 @@ func (_m *Provider) LightBlock(ctx context.Context, height int64) (*types.LightB
|
||||
}
|
||||
|
||||
// ReportEvidence provides a mock function with given fields: _a0, _a1
|
||||
func (_m *Provider) ReportEvidence(_a0 context.Context, _a1 types.Evidence) error {
|
||||
func (_m *Provider) ReportEvidence(_a0 context.Context, _a1 evidence.Evidence) error {
|
||||
ret := _m.Called(_a0, _a1)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, types.Evidence) error); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context, evidence.Evidence) error); ok {
|
||||
r0 = rf(_a0, _a1)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
|
||||
@@ -3,7 +3,8 @@ package provider
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tendermint/pkg/evidence"
|
||||
"github.com/tendermint/tendermint/pkg/light"
|
||||
)
|
||||
|
||||
//go:generate ../../scripts/mockery_generate.sh Provider
|
||||
@@ -21,8 +22,8 @@ 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 int64) (*light.LightBlock, error)
|
||||
|
||||
// ReportEvidence reports an evidence of misbehavior.
|
||||
ReportEvidence(context.Context, types.Evidence) error
|
||||
ReportEvidence(context.Context, evidence.Evidence) error
|
||||
}
|
||||
|
||||
+10
-9
@@ -3,11 +3,12 @@ package proxy
|
||||
import (
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
lrpc "github.com/tendermint/tendermint/light/rpc"
|
||||
"github.com/tendermint/tendermint/pkg/evidence"
|
||||
"github.com/tendermint/tendermint/pkg/mempool"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
|
||||
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
func RPCRoutes(c *lrpc.Client) map[string]*rpcserver.RPCFunc {
|
||||
@@ -230,26 +231,26 @@ func makeNumUnconfirmedTxsFunc(c *lrpc.Client) rpcNumUnconfirmedTxsFunc {
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBroadcastTxCommitFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
|
||||
type rpcBroadcastTxCommitFunc func(ctx *rpctypes.Context, tx mempool.Tx) (*ctypes.ResultBroadcastTxCommit, error)
|
||||
|
||||
func makeBroadcastTxCommitFunc(c *lrpc.Client) rpcBroadcastTxCommitFunc {
|
||||
return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
return func(ctx *rpctypes.Context, tx mempool.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
return c.BroadcastTxCommit(ctx.Context(), tx)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBroadcastTxSyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error)
|
||||
type rpcBroadcastTxSyncFunc func(ctx *rpctypes.Context, tx mempool.Tx) (*ctypes.ResultBroadcastTx, error)
|
||||
|
||||
func makeBroadcastTxSyncFunc(c *lrpc.Client) rpcBroadcastTxSyncFunc {
|
||||
return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
return func(ctx *rpctypes.Context, tx mempool.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
return c.BroadcastTxSync(ctx.Context(), tx)
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBroadcastTxAsyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error)
|
||||
type rpcBroadcastTxAsyncFunc func(ctx *rpctypes.Context, tx mempool.Tx) (*ctypes.ResultBroadcastTx, error)
|
||||
|
||||
func makeBroadcastTxAsyncFunc(c *lrpc.Client) rpcBroadcastTxAsyncFunc {
|
||||
return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
return func(ctx *rpctypes.Context, tx mempool.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
return c.BroadcastTxAsync(ctx.Context(), tx)
|
||||
}
|
||||
}
|
||||
@@ -276,11 +277,11 @@ func makeABCIInfoFunc(c *lrpc.Client) rpcABCIInfoFunc {
|
||||
}
|
||||
}
|
||||
|
||||
type rpcBroadcastEvidenceFunc func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error)
|
||||
type rpcBroadcastEvidenceFunc func(ctx *rpctypes.Context, ev evidence.Evidence) (*ctypes.ResultBroadcastEvidence, error)
|
||||
|
||||
// nolint: interfacer
|
||||
func makeBroadcastEvidenceFunc(c *lrpc.Client) rpcBroadcastEvidenceFunc {
|
||||
return func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
|
||||
return func(ctx *rpctypes.Context, ev evidence.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
|
||||
return c.BroadcastEvidence(ctx.Context(), ev)
|
||||
}
|
||||
}
|
||||
|
||||
+10
-8
@@ -10,15 +10,17 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto/merkle"
|
||||
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
service "github.com/tendermint/tendermint/libs/service"
|
||||
"github.com/tendermint/tendermint/pkg/abci"
|
||||
"github.com/tendermint/tendermint/pkg/evidence"
|
||||
types "github.com/tendermint/tendermint/pkg/light"
|
||||
"github.com/tendermint/tendermint/pkg/mempool"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// KeyPathFunc builds a merkle path out of the given path and key.
|
||||
@@ -188,15 +190,15 @@ func (c *Client) ABCIQueryWithOptions(ctx context.Context, path string, data tmb
|
||||
return &ctypes.ResultABCIQuery{Response: resp}, nil
|
||||
}
|
||||
|
||||
func (c *Client) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
func (c *Client) BroadcastTxCommit(ctx context.Context, tx mempool.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
return c.next.BroadcastTxCommit(ctx, tx)
|
||||
}
|
||||
|
||||
func (c *Client) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
func (c *Client) BroadcastTxAsync(ctx context.Context, tx mempool.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
return c.next.BroadcastTxAsync(ctx, tx)
|
||||
}
|
||||
|
||||
func (c *Client) BroadcastTxSync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
func (c *Client) BroadcastTxSync(ctx context.Context, tx mempool.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
return c.next.BroadcastTxSync(ctx, tx)
|
||||
}
|
||||
|
||||
@@ -208,7 +210,7 @@ func (c *Client) NumUnconfirmedTxs(ctx context.Context) (*ctypes.ResultUnconfirm
|
||||
return c.next.NumUnconfirmedTxs(ctx)
|
||||
}
|
||||
|
||||
func (c *Client) CheckTx(ctx context.Context, tx types.Tx) (*ctypes.ResultCheckTx, error) {
|
||||
func (c *Client) CheckTx(ctx context.Context, tx mempool.Tx) (*ctypes.ResultCheckTx, error) {
|
||||
return c.next.CheckTx(ctx, tx)
|
||||
}
|
||||
|
||||
@@ -416,7 +418,7 @@ func (c *Client) BlockResults(ctx context.Context, height *int64) (*ctypes.Resul
|
||||
}
|
||||
|
||||
// Build a Merkle tree of proto-encoded DeliverTx results and get a hash.
|
||||
results := types.NewResults(res.TxsResults)
|
||||
results := abci.NewResults(res.TxsResults)
|
||||
|
||||
// proto-encode EndBlock events.
|
||||
ebeBytes, err := proto.Marshal(&abci.ResponseEndBlock{
|
||||
@@ -525,7 +527,7 @@ func (c *Client) Validators(
|
||||
Total: totalCount}, nil
|
||||
}
|
||||
|
||||
func (c *Client) BroadcastEvidence(ctx context.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
|
||||
func (c *Client) BroadcastEvidence(ctx context.Context, ev evidence.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
|
||||
return c.next.BroadcastEvidence(ctx, ev)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,9 @@ import (
|
||||
context "context"
|
||||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
light "github.com/tendermint/tendermint/pkg/light"
|
||||
|
||||
time "time"
|
||||
|
||||
types "github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// LightClient is an autogenerated mock type for the LightClient type
|
||||
@@ -32,15 +31,15 @@ func (_m *LightClient) ChainID() string {
|
||||
}
|
||||
|
||||
// TrustedLightBlock provides a mock function with given fields: height
|
||||
func (_m *LightClient) TrustedLightBlock(height int64) (*types.LightBlock, error) {
|
||||
func (_m *LightClient) TrustedLightBlock(height int64) (*light.LightBlock, error) {
|
||||
ret := _m.Called(height)
|
||||
|
||||
var r0 *types.LightBlock
|
||||
if rf, ok := ret.Get(0).(func(int64) *types.LightBlock); ok {
|
||||
var r0 *light.LightBlock
|
||||
if rf, ok := ret.Get(0).(func(int64) *light.LightBlock); ok {
|
||||
r0 = rf(height)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*types.LightBlock)
|
||||
r0 = ret.Get(0).(*light.LightBlock)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,15 +54,15 @@ func (_m *LightClient) TrustedLightBlock(height int64) (*types.LightBlock, error
|
||||
}
|
||||
|
||||
// Update provides a mock function with given fields: ctx, now
|
||||
func (_m *LightClient) Update(ctx context.Context, now time.Time) (*types.LightBlock, error) {
|
||||
func (_m *LightClient) Update(ctx context.Context, now time.Time) (*light.LightBlock, error) {
|
||||
ret := _m.Called(ctx, now)
|
||||
|
||||
var r0 *types.LightBlock
|
||||
if rf, ok := ret.Get(0).(func(context.Context, time.Time) *types.LightBlock); ok {
|
||||
var r0 *light.LightBlock
|
||||
if rf, ok := ret.Get(0).(func(context.Context, time.Time) *light.LightBlock); ok {
|
||||
r0 = rf(ctx, now)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*types.LightBlock)
|
||||
r0 = ret.Get(0).(*light.LightBlock)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,15 +77,15 @@ func (_m *LightClient) Update(ctx context.Context, now time.Time) (*types.LightB
|
||||
}
|
||||
|
||||
// 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 int64, now time.Time) (*light.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 {
|
||||
var r0 *light.LightBlock
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, time.Time) *light.LightBlock); ok {
|
||||
r0 = rf(ctx, height, now)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*types.LightBlock)
|
||||
r0 = ret.Get(0).(*light.LightBlock)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
tmsync "github.com/tendermint/tendermint/internal/libs/sync"
|
||||
"github.com/tendermint/tendermint/light/store"
|
||||
"github.com/tendermint/tendermint/pkg/light"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -45,7 +45,7 @@ func New(db dbm.DB) store.Store {
|
||||
// SaveLightBlock persists LightBlock to the db.
|
||||
//
|
||||
// Safe for concurrent use by multiple goroutines.
|
||||
func (s *dbs) SaveLightBlock(lb *types.LightBlock) error {
|
||||
func (s *dbs) SaveLightBlock(lb *light.LightBlock) error {
|
||||
if lb.Height <= 0 {
|
||||
panic("negative or zero height")
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func (s *dbs) DeleteLightBlock(height int64) error {
|
||||
// LightBlock retrieves the LightBlock at the given height.
|
||||
//
|
||||
// Safe for concurrent use by multiple goroutines.
|
||||
func (s *dbs) LightBlock(height int64) (*types.LightBlock, error) {
|
||||
func (s *dbs) LightBlock(height int64) (*light.LightBlock, error) {
|
||||
if height <= 0 {
|
||||
panic("negative or zero height")
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func (s *dbs) LightBlock(height int64) (*types.LightBlock, error) {
|
||||
return nil, fmt.Errorf("unmarshal error: %w", err)
|
||||
}
|
||||
|
||||
lightBlock, err := types.LightBlockFromProto(&lbpb)
|
||||
lightBlock, err := light.LightBlockFromProto(&lbpb)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("proto conversion error: %w", err)
|
||||
}
|
||||
@@ -181,7 +181,7 @@ func (s *dbs) FirstLightBlockHeight() (int64, error) {
|
||||
// the given height. It returns ErrLightBlockNotFound if no such block exists.
|
||||
//
|
||||
// Safe for concurrent use by multiple goroutines.
|
||||
func (s *dbs) LightBlockBefore(height int64) (*types.LightBlock, error) {
|
||||
func (s *dbs) LightBlockBefore(height int64) (*light.LightBlock, error) {
|
||||
if height <= 0 {
|
||||
panic("negative or zero height")
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func (s *dbs) LightBlockBefore(height int64) (*types.LightBlock, error) {
|
||||
return nil, fmt.Errorf("unmarshal error: %w", err)
|
||||
}
|
||||
|
||||
lightBlock, err := types.LightBlockFromProto(&lbpb)
|
||||
lightBlock, err := light.LightBlockFromProto(&lbpb)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("proto conversion error: %w", err)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
"github.com/tendermint/tendermint/internal/test/factory"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tendermint/pkg/light"
|
||||
"github.com/tendermint/tendermint/pkg/metadata"
|
||||
"github.com/tendermint/tendermint/version"
|
||||
)
|
||||
|
||||
@@ -183,16 +184,16 @@ func Test_Concurrency(t *testing.T) {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func randLightBlock(height int64) *types.LightBlock {
|
||||
func randLightBlock(height int64) *light.LightBlock {
|
||||
vals, _ := factory.RandValidatorSet(2, 1)
|
||||
return &types.LightBlock{
|
||||
SignedHeader: &types.SignedHeader{
|
||||
Header: &types.Header{
|
||||
return &light.LightBlock{
|
||||
SignedHeader: &metadata.SignedHeader{
|
||||
Header: &metadata.Header{
|
||||
Version: version.Consensus{Block: version.BlockProtocol, App: 0},
|
||||
ChainID: tmrand.Str(12),
|
||||
Height: height,
|
||||
Time: time.Now(),
|
||||
LastBlockID: types.BlockID{},
|
||||
LastBlockID: metadata.BlockID{},
|
||||
LastCommitHash: crypto.CRandBytes(tmhash.Size),
|
||||
DataHash: crypto.CRandBytes(tmhash.Size),
|
||||
ValidatorsHash: crypto.CRandBytes(tmhash.Size),
|
||||
@@ -203,7 +204,7 @@ func randLightBlock(height int64) *types.LightBlock {
|
||||
EvidenceHash: crypto.CRandBytes(tmhash.Size),
|
||||
ProposerAddress: crypto.CRandBytes(crypto.AddressSize),
|
||||
},
|
||||
Commit: &types.Commit{},
|
||||
Commit: &metadata.Commit{},
|
||||
},
|
||||
ValidatorSet: vals,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package store
|
||||
|
||||
import "github.com/tendermint/tendermint/types"
|
||||
import "github.com/tendermint/tendermint/pkg/light"
|
||||
|
||||
// Store is anything that can persistently store headers.
|
||||
type Store interface {
|
||||
@@ -8,7 +8,7 @@ type Store interface {
|
||||
// ValidatorSet (h: sh.Height).
|
||||
//
|
||||
// height must be > 0.
|
||||
SaveLightBlock(lb *types.LightBlock) error
|
||||
SaveLightBlock(lb *light.LightBlock) error
|
||||
|
||||
// DeleteSignedHeaderAndValidatorSet deletes SignedHeader (h: height) and
|
||||
// ValidatorSet (h: height).
|
||||
@@ -22,7 +22,7 @@ type Store interface {
|
||||
// height must be > 0.
|
||||
//
|
||||
// If LightBlock is not found, ErrLightBlockNotFound is returned.
|
||||
LightBlock(height int64) (*types.LightBlock, error)
|
||||
LightBlock(height int64) (*light.LightBlock, error)
|
||||
|
||||
// LastLightBlockHeight returns the last (newest) LightBlock height.
|
||||
//
|
||||
@@ -37,7 +37,7 @@ type Store interface {
|
||||
// LightBlockBefore returns the LightBlock before a certain height.
|
||||
//
|
||||
// height must be > 0 && <= LastLightBlockHeight.
|
||||
LightBlockBefore(height int64) (*types.LightBlock, error)
|
||||
LightBlockBefore(height int64) (*light.LightBlock, error)
|
||||
|
||||
// Prune removes headers & the associated validator sets when Store reaches a
|
||||
// defined size (number of header & validator set pairs).
|
||||
|
||||
+20
-19
@@ -7,7 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tendermint/pkg/consensus"
|
||||
"github.com/tendermint/tendermint/pkg/metadata"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -31,10 +32,10 @@ var (
|
||||
// future.
|
||||
// trustedHeader must have a ChainID, Height and Time
|
||||
func VerifyNonAdjacent(
|
||||
trustedHeader *types.SignedHeader, // height=X
|
||||
trustedVals *types.ValidatorSet, // height=X or height=X+1
|
||||
untrustedHeader *types.SignedHeader, // height=Y
|
||||
untrustedVals *types.ValidatorSet, // height=Y
|
||||
trustedHeader *metadata.SignedHeader, // height=X
|
||||
trustedVals *consensus.ValidatorSet, // height=X or height=X+1
|
||||
untrustedHeader *metadata.SignedHeader, // height=Y
|
||||
untrustedVals *consensus.ValidatorSet, // height=Y
|
||||
trustingPeriod time.Duration,
|
||||
now time.Time,
|
||||
maxClockDrift time.Duration,
|
||||
@@ -67,7 +68,7 @@ func VerifyNonAdjacent(
|
||||
err := trustedVals.VerifyCommitLightTrusting(trustedHeader.ChainID, untrustedHeader.Commit, trustLevel)
|
||||
if err != nil {
|
||||
switch e := err.(type) {
|
||||
case types.ErrNotEnoughVotingPowerSigned:
|
||||
case consensus.ErrNotEnoughVotingPowerSigned:
|
||||
return ErrNewValSetCantBeTrusted{e}
|
||||
default:
|
||||
return ErrInvalidHeader{e}
|
||||
@@ -101,9 +102,9 @@ func VerifyNonAdjacent(
|
||||
// future.
|
||||
// trustedHeader must have a ChainID, Height, Time and NextValidatorsHash
|
||||
func VerifyAdjacent(
|
||||
trustedHeader *types.SignedHeader, // height=X
|
||||
untrustedHeader *types.SignedHeader, // height=X+1
|
||||
untrustedVals *types.ValidatorSet, // height=X+1
|
||||
trustedHeader *metadata.SignedHeader, // height=X
|
||||
untrustedHeader *metadata.SignedHeader, // height=X+1
|
||||
untrustedVals *consensus.ValidatorSet, // height=X+1
|
||||
trustingPeriod time.Duration,
|
||||
now time.Time,
|
||||
maxClockDrift time.Duration) error {
|
||||
@@ -150,10 +151,10 @@ func VerifyAdjacent(
|
||||
|
||||
// Verify combines both VerifyAdjacent and VerifyNonAdjacent functions.
|
||||
func Verify(
|
||||
trustedHeader *types.SignedHeader, // height=X
|
||||
trustedVals *types.ValidatorSet, // height=X or height=X+1
|
||||
untrustedHeader *types.SignedHeader, // height=Y
|
||||
untrustedVals *types.ValidatorSet, // height=Y
|
||||
trustedHeader *metadata.SignedHeader, // height=X
|
||||
trustedVals *consensus.ValidatorSet, // height=X or height=X+1
|
||||
untrustedHeader *metadata.SignedHeader, // height=Y
|
||||
untrustedVals *consensus.ValidatorSet, // height=Y
|
||||
trustingPeriod time.Duration,
|
||||
now time.Time,
|
||||
maxClockDrift time.Duration,
|
||||
@@ -180,7 +181,7 @@ func ValidateTrustLevel(lvl tmmath.Fraction) error {
|
||||
}
|
||||
|
||||
// HeaderExpired return true if the given header expired.
|
||||
func HeaderExpired(h *types.SignedHeader, trustingPeriod time.Duration, now time.Time) bool {
|
||||
func HeaderExpired(h *metadata.SignedHeader, trustingPeriod time.Duration, now time.Time) bool {
|
||||
expirationTime := h.Time.Add(trustingPeriod)
|
||||
return !expirationTime.After(now)
|
||||
}
|
||||
@@ -198,7 +199,7 @@ func HeaderExpired(h *types.SignedHeader, trustingPeriod time.Duration, now time
|
||||
// or not. These checks are not necessary because the detector never runs during
|
||||
// backwards verification and thus evidence that needs to be within a certain
|
||||
// time bound is never sent.
|
||||
func VerifyBackwards(untrustedHeader, trustedHeader *types.Header) error {
|
||||
func VerifyBackwards(untrustedHeader, trustedHeader *metadata.Header) error {
|
||||
if err := untrustedHeader.ValidateBasic(); err != nil {
|
||||
return ErrInvalidHeader{err}
|
||||
}
|
||||
@@ -228,9 +229,9 @@ func VerifyBackwards(untrustedHeader, trustedHeader *types.Header) error {
|
||||
// NOTE: This function assumes that untrustedHeader is after trustedHeader.
|
||||
// Do not use for backwards verification.
|
||||
func verifyNewHeaderAndVals(
|
||||
untrustedHeader *types.SignedHeader,
|
||||
untrustedVals *types.ValidatorSet,
|
||||
trustedHeader *types.SignedHeader,
|
||||
untrustedHeader *metadata.SignedHeader,
|
||||
untrustedVals *consensus.ValidatorSet,
|
||||
trustedHeader *metadata.SignedHeader,
|
||||
now time.Time,
|
||||
maxClockDrift time.Duration) error {
|
||||
|
||||
@@ -268,7 +269,7 @@ func verifyNewHeaderAndVals(
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkRequiredHeaderFields(h *types.SignedHeader) {
|
||||
func checkRequiredHeaderFields(h *metadata.SignedHeader) {
|
||||
if h.Height == 0 {
|
||||
panic("height in trusted header must be set (non zero")
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
"github.com/tendermint/tendermint/light"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tendermint/pkg/consensus"
|
||||
"github.com/tendermint/tendermint/pkg/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -33,8 +34,8 @@ func TestVerifyAdjacentHeaders(t *testing.T) {
|
||||
)
|
||||
|
||||
testCases := []struct {
|
||||
newHeader *types.SignedHeader
|
||||
newVals *types.ValidatorSet
|
||||
newHeader *metadata.SignedHeader
|
||||
newVals *consensus.ValidatorSet
|
||||
trustingPeriod time.Duration
|
||||
now time.Time
|
||||
expErr error
|
||||
@@ -117,7 +118,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) {
|
||||
vals,
|
||||
3 * time.Hour,
|
||||
bTime.Add(2 * time.Hour),
|
||||
light.ErrInvalidHeader{Reason: types.ErrNotEnoughVotingPowerSigned{Got: 50, Needed: 93}},
|
||||
light.ErrInvalidHeader{Reason: consensus.ErrNotEnoughVotingPowerSigned{Got: 50, Needed: 93}},
|
||||
"",
|
||||
},
|
||||
// vals does not match with what we have -> error
|
||||
@@ -197,8 +198,8 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) {
|
||||
)
|
||||
|
||||
testCases := []struct {
|
||||
newHeader *types.SignedHeader
|
||||
newVals *types.ValidatorSet
|
||||
newHeader *metadata.SignedHeader
|
||||
newVals *consensus.ValidatorSet
|
||||
trustingPeriod time.Duration
|
||||
now time.Time
|
||||
expErr error
|
||||
@@ -231,7 +232,7 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) {
|
||||
vals,
|
||||
3 * time.Hour,
|
||||
bTime.Add(2 * time.Hour),
|
||||
light.ErrInvalidHeader{types.ErrNotEnoughVotingPowerSigned{Got: 50, Needed: 93}},
|
||||
light.ErrInvalidHeader{consensus.ErrNotEnoughVotingPowerSigned{Got: 50, Needed: 93}},
|
||||
"",
|
||||
},
|
||||
// 3/3 new vals signed, 2/3 old vals present -> no error
|
||||
@@ -261,7 +262,7 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) {
|
||||
lessThanOneThirdVals,
|
||||
3 * time.Hour,
|
||||
bTime.Add(2 * time.Hour),
|
||||
light.ErrNewValSetCantBeTrusted{types.ErrNotEnoughVotingPowerSigned{Got: 20, Needed: 46}},
|
||||
light.ErrNewValSetCantBeTrusted{consensus.ErrNotEnoughVotingPowerSigned{Got: 20, Needed: 46}},
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user