Skip to content

Commit 29e3833

Browse files
author
Naohiro Yoshida
committed
remove trusted check in relayer
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
1 parent a6dc0af commit 29e3833

File tree

7 files changed

+23
-113
lines changed

7 files changed

+23
-113
lines changed

e2e/chains/bsc/docker-compose.bsc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ services:
55
dockerfile: Dockerfile.bsc
66
args:
77
GIT_SOURCE: https://github.com/bnb-chain/bsc
8-
GIT_CHECKOUT_BRANCH: v1.4.13
8+
GIT_CHECKOUT_BRANCH: v1.4.16
99
image: bsc-geth:docker-local

e2e/contracts/package-lock.json

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

module/setup.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,10 @@ func setupNeighboringEpochHeader(
6161
if err != nil {
6262
return nil, fmt.Errorf("setupNeighboringEpochHeader: failed to get current validator set: epochHeight=%d : %+v", epochHeight, err)
6363
}
64-
trustedValidatorSet, trustedTurnLength, err := queryValidatorSetAndTurnLength(getHeader, trustedEpochHeight)
65-
if err != nil {
66-
return nil, fmt.Errorf("setupNeighboringEpochHeader: failed to get trusted validator set: trustedEpochHeight=%d : %+v", trustedEpochHeight, err)
67-
}
68-
if trustedValidatorSet.Contains(currentValidatorSet) {
69-
// ex) trusted(prevSaved = 200), epochHeight = 400 must be finalized by min(610,latest)
70-
nextCheckpoint := currentValidatorSet.Checkpoint(currentTurnLength) + (epochHeight + constant.BlocksPerEpoch)
71-
limit := minUint64(nextCheckpoint-1, latestHeight.GetRevisionHeight())
72-
return queryVerifiableHeader(epochHeight, limit)
73-
} else {
74-
// ex) trusted(prevSaved = 200), epochHeight = 400 must be finalized by min(410,latest)
75-
checkpoint := trustedValidatorSet.Checkpoint(trustedTurnLength) + epochHeight
76-
limit := minUint64(checkpoint-1, latestHeight.GetRevisionHeight())
77-
return queryVerifiableHeader(epochHeight, limit)
78-
}
64+
// ex) trusted(prevSaved = 200), epochHeight = 400 must be finalized by min(610,latest)
65+
nextCheckpoint := currentValidatorSet.Checkpoint(currentTurnLength) + (epochHeight + constant.BlocksPerEpoch)
66+
limit := minUint64(nextCheckpoint-1, latestHeight.GetRevisionHeight())
67+
return queryVerifiableHeader(epochHeight, limit)
7968
}
8069

8170
func withTrustedHeight(targetHeaders []core.Header, clientStateLatestHeight exported.Height) []core.Header {

module/setup_test.go

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -139,45 +139,7 @@ func (ts *SetupTestSuite) TestSuccess_setupHeadersForUpdate_allEmpty() {
139139
verify(constant.BlocksPerEpoch+1, 10*constant.BlocksPerEpoch+1, 0) // non neighboring
140140
}
141141

142-
func (ts *SetupTestSuite) TestSuccess_setupNeighboringEpochHeader_notContainTrusted() {
143-
144-
epochHeight := uint64(400)
145-
trustedEpochHeight := uint64(200)
146-
147-
neighboringEpochFn := func(height uint64, limit uint64) (core.Header, error) {
148-
target, err := newETHHeader(&types2.Header{
149-
Number: big.NewInt(int64(limit)),
150-
})
151-
ts.Require().NoError(err)
152-
return &Header{
153-
Headers: []*ETHHeader{target},
154-
}, nil
155-
}
156-
headerFn := func(_ context.Context, height uint64) (*types2.Header, error) {
157-
h := headerByHeight(int64(height))
158-
const validatorCount = 4
159-
const indexOfValidatorCount = extraVanity
160-
const indexOfTurnLength = extraVanity + validatorNumberSize + validatorCount*validatorBytesLength
161-
if h.Number.Uint64() == trustedEpochHeight {
162-
// set invalid validator
163-
for i := range h.Extra {
164-
if i != indexOfValidatorCount && i != indexOfTurnLength {
165-
h.Extra[i] = 0
166-
}
167-
}
168-
}
169-
return h, nil
170-
}
171-
hs, err := setupNeighboringEpochHeader(headerFn, neighboringEpochFn, epochHeight, trustedEpochHeight, clienttypes.NewHeight(0, 10000))
172-
ts.Require().NoError(err)
173-
target, err := hs.(*Header).Target()
174-
ts.Require().NoError(err)
175-
176-
// checkpoint - 1
177-
ts.Require().Equal(int64(402), target.Number.Int64())
178-
}
179-
180-
func (ts *SetupTestSuite) TestSuccess_setupNeighboringEpochHeader_containTrusted() {
142+
func (ts *SetupTestSuite) TestSuccess_setupNeighboringEpochHeader() {
181143

182144
epochHeight := uint64(400)
183145
trustedEpochHeight := uint64(200)

module/validator_set.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package module
33
import (
44
"context"
55
"fmt"
6-
"github.com/ethereum/go-ethereum/common"
76
"github.com/ethereum/go-ethereum/core/types"
87
)
98

@@ -13,31 +12,6 @@ func (v Validators) Checkpoint(turnLength uint8) uint64 {
1312
return uint64(len(v)/2+1) * uint64(turnLength)
1413
}
1514

16-
func (v Validators) Contains(other Validators) bool {
17-
count := 0
18-
for _, x := range other {
19-
for _, y := range v {
20-
if common.Bytes2Hex(x) == common.Bytes2Hex(y) {
21-
count++
22-
break
23-
}
24-
}
25-
}
26-
required := v.threshold()
27-
return count >= required
28-
}
29-
30-
func (v Validators) threshold() int {
31-
return len(v) - ceilDiv(len(v)*2, 3) + 1
32-
}
33-
34-
func ceilDiv(x, y int) int {
35-
if y == 0 {
36-
return 0
37-
}
38-
return (x + y - 1) / y
39-
}
40-
4115
func queryValidatorSetAndTurnLength(fn getHeaderFn, epochBlockNumber uint64) (Validators, uint8, error) {
4216
header, err := fn(context.TODO(), epochBlockNumber)
4317
if err != nil {

module/validator_set_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,32 +89,3 @@ func (ts *ValidatorSetTestSuite) TestCheckpoint() {
8989
ts.Equal(int(validator.Checkpoint(3)), 33)
9090
ts.Equal(int(validator.Checkpoint(9)), 99)
9191
}
92-
93-
func (ts *ValidatorSetTestSuite) TestTrustValidator() {
94-
trusted := Validators([][]byte{{1}, {2}, {3}, {4}, {5}})
95-
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}, {4}, {5}}))
96-
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}, {4}, {5}, {10}, {11}, {12}, {13}, {14}}))
97-
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}, {4}}))
98-
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}, {4}, {10}, {11}, {12}, {13}, {14}}))
99-
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}}))
100-
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}, {10}, {11}, {12}, {13}, {14}}))
101-
ts.True(trusted.Contains([][]byte{{1}, {2}}))
102-
ts.True(trusted.Contains([][]byte{{1}, {2}, {10}, {11}, {12}, {13}, {14}}))
103-
ts.False(trusted.Contains([][]byte{{1}}))
104-
ts.False(trusted.Contains([][]byte{{1}, {10}, {11}, {12}, {13}, {14}}))
105-
ts.False(trusted.Contains([][]byte{}))
106-
ts.False(trusted.Contains([][]byte{{10}, {11}, {12}, {13}, {14}}))
107-
}
108-
109-
func (ts *ValidatorSetTestSuite) TestThreshold() {
110-
ts.Equal(1, Validators(make([][]byte, 1)).threshold())
111-
ts.Equal(1, Validators(make([][]byte, 2)).threshold())
112-
ts.Equal(2, Validators(make([][]byte, 3)).threshold())
113-
ts.Equal(2, Validators(make([][]byte, 4)).threshold())
114-
ts.Equal(2, Validators(make([][]byte, 5)).threshold())
115-
ts.Equal(3, Validators(make([][]byte, 6)).threshold())
116-
ts.Equal(3, Validators(make([][]byte, 7)).threshold())
117-
ts.Equal(3, Validators(make([][]byte, 8)).threshold())
118-
ts.Equal(4, Validators(make([][]byte, 9)).threshold())
119-
ts.Equal(8, Validators(make([][]byte, 21)).threshold())
120-
}

tool/testdata/internal/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"github.com/cosmos/cosmos-sdk/codec/types"
66
"github.com/datachainlab/ethereum-ibc-relay-chain/pkg/relay/ethereum"
7-
"github.com/datachainlab/ethereum-ibc-relay-chain/pkg/relay/ethereum/signers/hd"
7+
"github.com/datachainlab/ibc-hd-signer/pkg/hd"
88
"github.com/datachainlab/ibc-parlia-relay/module"
99
"github.com/spf13/viper"
1010
"os"

0 commit comments

Comments
 (0)