Browse Source

fix deadlock in light tests (#6332)

pull/6337/head
Callum Waters 3 years ago
committed by GitHub
parent
commit
a818f914ab
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 17 deletions
  1. +16
    -16
      light/detector_test.go
  2. +10
    -1
      light/provider/mock/mock.go

+ 16
- 16
light/detector_test.go View File

@ -233,24 +233,24 @@ 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{
SignedHeader: chainKeys[latestHeight].GenSignedHeader(
chainID,
proofHeight,
bTime.Add(time.Duration(proofHeight+1)*time.Minute), // 12 mins
nil,
vals,
vals,
hash("app_hash"),
hash("cons_hash"),
hash("results_hash"),
0, len(chainKeys),
),
ValidatorSet: vals,
}
go func() {
time.Sleep(2 * time.Second)
vals := chainKeys[latestHeight].ToValidators(2, 0)
newLb := &types.LightBlock{
SignedHeader: chainKeys[latestHeight].GenSignedHeader(
chainID,
proofHeight,
bTime.Add(time.Duration(proofHeight+1)*time.Minute), // 12 mins
nil,
vals,
vals,
hash("app_hash"),
hash("cons_hash"),
hash("results_hash"),
0, len(chainKeys),
),
ValidatorSet: vals,
}
witness.AddLightBlock(newLb)
}()


+ 10
- 1
light/provider/mock/mock.go View File

@ -5,13 +5,16 @@ import (
"errors"
"fmt"
"strings"
"sync"
"github.com/tendermint/tendermint/light/provider"
"github.com/tendermint/tendermint/types"
)
type Mock struct {
id string
id string
mtx sync.Mutex
headers map[int64]*types.SignedHeader
vals map[int64]*types.ValidatorSet
evidenceToReport map[string]types.Evidence // hash => evidence
@ -53,6 +56,9 @@ func (p *Mock) String() string {
}
func (p *Mock) LightBlock(_ context.Context, height int64) (*types.LightBlock, error) {
p.mtx.Lock()
defer p.mtx.Unlock()
var lb *types.LightBlock
if height > p.latestHeight {
@ -94,6 +100,9 @@ func (p *Mock) HasEvidence(ev types.Evidence) bool {
}
func (p *Mock) AddLightBlock(lb *types.LightBlock) {
p.mtx.Lock()
defer p.mtx.Unlock()
if err := lb.ValidateBasic(lb.ChainID); err != nil {
panic(fmt.Sprintf("unable to add light block, err: %v", err))
}


Loading…
Cancel
Save