mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 22:44:24 +00:00
evidence: remove ConflictingHeaders type (#5317)
## Description Remove ConflictingHeaders & compositeEvidence types Ref #5288
This commit is contained in:
+2
-33
@@ -931,10 +931,7 @@ func (c *Client) compareNewHeaderWithWitnesses(l *types.LightBlock, now time.Tim
|
||||
defer c.providerMutex.Unlock()
|
||||
|
||||
// 1. Make sure AT LEAST ONE witness returns the same header.
|
||||
var (
|
||||
headerMatched bool
|
||||
lastErrConfHeaders error
|
||||
)
|
||||
var headerMatched bool
|
||||
for attempt := uint16(1); attempt <= c.maxRetryAttempts; attempt++ {
|
||||
if len(c.witnesses) == 0 {
|
||||
return errNoWitnesses{}
|
||||
@@ -955,10 +952,6 @@ func (c *Client) compareNewHeaderWithWitnesses(l *types.LightBlock, now time.Tim
|
||||
switch e := err.(type) {
|
||||
case nil: // at least one header matched
|
||||
headerMatched = true
|
||||
case ErrConflictingHeaders: // fork detected
|
||||
c.logger.Info("FORK DETECTED", "witness", e.Witness, "err", err)
|
||||
c.sendConflictingHeadersEvidence(&types.ConflictingHeadersEvidence{H1: e.H1, H2: e.H2})
|
||||
lastErrConfHeaders = e
|
||||
case errBadWitness:
|
||||
c.logger.Info("Bad witness", "witness", c.witnesses[e.WitnessIndex], "err", err)
|
||||
// if witness sent us invalid header / vals, remove it
|
||||
@@ -973,11 +966,7 @@ func (c *Client) compareNewHeaderWithWitnesses(l *types.LightBlock, now time.Tim
|
||||
c.removeWitness(idx)
|
||||
}
|
||||
|
||||
if lastErrConfHeaders != nil {
|
||||
// NOTE: all of the potential forks will be reported, but we only return
|
||||
// the last ErrConflictingHeaders error here.
|
||||
return lastErrConfHeaders
|
||||
} else if headerMatched {
|
||||
if headerMatched {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1003,7 +992,6 @@ func (c *Client) compareNewHeaderWithWitness(errc chan error, l *types.LightBloc
|
||||
errc <- errBadWitness{bsErr, invalidLightBlock, witnessIndex}
|
||||
return
|
||||
}
|
||||
errc <- ErrConflictingHeaders{H1: l.SignedHeader, Primary: c.primary, H2: altBlock.SignedHeader, Witness: witness}
|
||||
}
|
||||
|
||||
errc <- nil
|
||||
@@ -1120,25 +1108,6 @@ func (c *Client) validateLightBlock(l *types.LightBlock, expectedHeight int64) e
|
||||
return nil
|
||||
}
|
||||
|
||||
// sendConflictingHeadersEvidence sends evidence to all witnesses and primary
|
||||
// on best effort basis.
|
||||
//
|
||||
// Evidence needs to be submitted to all full nodes since there's no way to
|
||||
// determine which full node is correct (honest).
|
||||
func (c *Client) sendConflictingHeadersEvidence(ev *types.ConflictingHeadersEvidence) {
|
||||
err := c.primary.ReportEvidence(ev)
|
||||
if err != nil {
|
||||
c.logger.Error("Failed to report evidence to primary", "ev", ev, "primary", c.primary)
|
||||
}
|
||||
|
||||
for _, w := range c.witnesses {
|
||||
err := w.ReportEvidence(ev)
|
||||
if err != nil {
|
||||
c.logger.Error("Failed to report evidence to witness", "ev", ev, "witness", w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// exponential backoff (with jitter)
|
||||
// 0.5s -> 2s -> 4.5s -> 8s -> 12.5 with 1s variation
|
||||
func backoffTimeout(attempt uint16) time.Duration {
|
||||
|
||||
@@ -973,46 +973,6 @@ func TestClient_TrustedValidatorSet(t *testing.T) {
|
||||
assert.Equal(t, 1, len(c.Witnesses()))
|
||||
}
|
||||
|
||||
func TestClientReportsConflictingHeadersEvidence(t *testing.T) {
|
||||
// fullNode2 sends us different header
|
||||
altH2 := 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()})
|
||||
fullNode2 := mockp.New(
|
||||
chainID,
|
||||
map[int64]*types.SignedHeader{
|
||||
1: h1,
|
||||
2: altH2,
|
||||
},
|
||||
map[int64]*types.ValidatorSet{
|
||||
1: vals,
|
||||
2: vals,
|
||||
},
|
||||
)
|
||||
|
||||
c, err := light.NewClient(
|
||||
chainID,
|
||||
trustOptions,
|
||||
fullNode,
|
||||
[]provider.Provider{fullNode2},
|
||||
dbs.New(dbm.NewMemDB(), chainID),
|
||||
light.Logger(log.TestingLogger()),
|
||||
light.MaxRetryAttempts(1),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check verification returns an error.
|
||||
_, err = c.VerifyLightBlockAtHeight(2, bTime.Add(2*time.Hour))
|
||||
if assert.Error(t, err) {
|
||||
assert.Contains(t, err.Error(), "does not match one")
|
||||
}
|
||||
|
||||
// Check evidence was sent to both full nodes.
|
||||
ev := &types.ConflictingHeadersEvidence{H1: h2, H2: altH2}
|
||||
assert.True(t, fullNode2.HasEvidence(ev))
|
||||
assert.True(t, fullNode.HasEvidence(ev))
|
||||
}
|
||||
|
||||
func TestClientPrunesHeadersAndValidatorSets(t *testing.T) {
|
||||
c, err := light.NewClient(
|
||||
chainID,
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/light/provider"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
@@ -40,22 +39,6 @@ func (e ErrInvalidHeader) Error() string {
|
||||
return fmt.Sprintf("invalid header: %v", e.Reason)
|
||||
}
|
||||
|
||||
// ErrConflictingHeaders is thrown when two conflicting headers are discovered.
|
||||
type ErrConflictingHeaders struct {
|
||||
H1 *types.SignedHeader
|
||||
Primary provider.Provider
|
||||
|
||||
H2 *types.SignedHeader
|
||||
Witness provider.Provider
|
||||
}
|
||||
|
||||
func (e ErrConflictingHeaders) Error() string {
|
||||
return fmt.Sprintf(
|
||||
"header hash %X from primary %v does not match one %X from witness %v",
|
||||
e.H1.Hash(), e.Primary,
|
||||
e.H2.Hash(), e.Witness)
|
||||
}
|
||||
|
||||
// ErrVerificationFailed means either sequential or skipping verification has
|
||||
// failed to verify from header #1 to header #2 due to some reason.
|
||||
type ErrVerificationFailed struct {
|
||||
|
||||
Reference in New Issue
Block a user