Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove checking trusted validator in relayer #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/chains/bsc/docker-compose.bsc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ services:
dockerfile: Dockerfile.bsc
args:
GIT_SOURCE: https://github.com/bnb-chain/bsc
GIT_CHECKOUT_BRANCH: v1.4.13
GIT_CHECKOUT_BRANCH: v1.4.16
image: bsc-geth:docker-local
18 changes: 16 additions & 2 deletions e2e/contracts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions module/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,10 @@ func setupNeighboringEpochHeader(
if err != nil {
return nil, fmt.Errorf("setupNeighboringEpochHeader: failed to get current validator set: epochHeight=%d : %+v", epochHeight, err)
}
trustedValidatorSet, trustedTurnLength, err := queryValidatorSetAndTurnLength(getHeader, trustedEpochHeight)
if err != nil {
return nil, fmt.Errorf("setupNeighboringEpochHeader: failed to get trusted validator set: trustedEpochHeight=%d : %+v", trustedEpochHeight, err)
}
if trustedValidatorSet.Contains(currentValidatorSet) {
// ex) trusted(prevSaved = 200), epochHeight = 400 must be finalized by min(610,latest)
nextCheckpoint := currentValidatorSet.Checkpoint(currentTurnLength) + (epochHeight + constant.BlocksPerEpoch)
limit := minUint64(nextCheckpoint-1, latestHeight.GetRevisionHeight())
return queryVerifiableHeader(epochHeight, limit)
} else {
// ex) trusted(prevSaved = 200), epochHeight = 400 must be finalized by min(410,latest)
checkpoint := trustedValidatorSet.Checkpoint(trustedTurnLength) + epochHeight
limit := minUint64(checkpoint-1, latestHeight.GetRevisionHeight())
return queryVerifiableHeader(epochHeight, limit)
}
// ex) trusted(prevSaved = 200), epochHeight = 400 must be finalized by min(610,latest)
nextCheckpoint := currentValidatorSet.Checkpoint(currentTurnLength) + (epochHeight + constant.BlocksPerEpoch)
limit := minUint64(nextCheckpoint-1, latestHeight.GetRevisionHeight())
return queryVerifiableHeader(epochHeight, limit)
}

func withTrustedHeight(targetHeaders []core.Header, clientStateLatestHeight exported.Height) []core.Header {
Expand Down
40 changes: 1 addition & 39 deletions module/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,45 +139,7 @@ func (ts *SetupTestSuite) TestSuccess_setupHeadersForUpdate_allEmpty() {
verify(constant.BlocksPerEpoch+1, 10*constant.BlocksPerEpoch+1, 0) // non neighboring
}

func (ts *SetupTestSuite) TestSuccess_setupNeighboringEpochHeader_notContainTrusted() {

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

neighboringEpochFn := func(height uint64, limit uint64) (core.Header, error) {
target, err := newETHHeader(&types2.Header{
Number: big.NewInt(int64(limit)),
})
ts.Require().NoError(err)
return &Header{
Headers: []*ETHHeader{target},
}, nil
}
headerFn := func(_ context.Context, height uint64) (*types2.Header, error) {
h := headerByHeight(int64(height))
const validatorCount = 4
const indexOfValidatorCount = extraVanity
const indexOfTurnLength = extraVanity + validatorNumberSize + validatorCount*validatorBytesLength
if h.Number.Uint64() == trustedEpochHeight {
// set invalid validator
for i := range h.Extra {
if i != indexOfValidatorCount && i != indexOfTurnLength {
h.Extra[i] = 0
}
}
}
return h, nil
}
hs, err := setupNeighboringEpochHeader(headerFn, neighboringEpochFn, epochHeight, trustedEpochHeight, clienttypes.NewHeight(0, 10000))
ts.Require().NoError(err)
target, err := hs.(*Header).Target()
ts.Require().NoError(err)

// checkpoint - 1
ts.Require().Equal(int64(402), target.Number.Int64())
}

func (ts *SetupTestSuite) TestSuccess_setupNeighboringEpochHeader_containTrusted() {
func (ts *SetupTestSuite) TestSuccess_setupNeighboringEpochHeader() {

epochHeight := uint64(400)
trustedEpochHeight := uint64(200)
Expand Down
26 changes: 0 additions & 26 deletions module/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package module
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

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

func (v Validators) Contains(other Validators) bool {
count := 0
for _, x := range other {
for _, y := range v {
if common.Bytes2Hex(x) == common.Bytes2Hex(y) {
count++
break
}
}
}
required := v.threshold()
return count >= required
}

func (v Validators) threshold() int {
return len(v) - ceilDiv(len(v)*2, 3) + 1
}

func ceilDiv(x, y int) int {
if y == 0 {
return 0
}
return (x + y - 1) / y
}

func queryValidatorSetAndTurnLength(fn getHeaderFn, epochBlockNumber uint64) (Validators, uint8, error) {
header, err := fn(context.TODO(), epochBlockNumber)
if err != nil {
Expand Down
29 changes: 0 additions & 29 deletions module/validator_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,3 @@ func (ts *ValidatorSetTestSuite) TestCheckpoint() {
ts.Equal(int(validator.Checkpoint(3)), 33)
ts.Equal(int(validator.Checkpoint(9)), 99)
}

func (ts *ValidatorSetTestSuite) TestTrustValidator() {
trusted := Validators([][]byte{{1}, {2}, {3}, {4}, {5}})
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}, {4}, {5}}))
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}, {4}, {5}, {10}, {11}, {12}, {13}, {14}}))
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}, {4}}))
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}, {4}, {10}, {11}, {12}, {13}, {14}}))
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}}))
ts.True(trusted.Contains([][]byte{{1}, {2}, {3}, {10}, {11}, {12}, {13}, {14}}))
ts.True(trusted.Contains([][]byte{{1}, {2}}))
ts.True(trusted.Contains([][]byte{{1}, {2}, {10}, {11}, {12}, {13}, {14}}))
ts.False(trusted.Contains([][]byte{{1}}))
ts.False(trusted.Contains([][]byte{{1}, {10}, {11}, {12}, {13}, {14}}))
ts.False(trusted.Contains([][]byte{}))
ts.False(trusted.Contains([][]byte{{10}, {11}, {12}, {13}, {14}}))
}

func (ts *ValidatorSetTestSuite) TestThreshold() {
ts.Equal(1, Validators(make([][]byte, 1)).threshold())
ts.Equal(1, Validators(make([][]byte, 2)).threshold())
ts.Equal(2, Validators(make([][]byte, 3)).threshold())
ts.Equal(2, Validators(make([][]byte, 4)).threshold())
ts.Equal(2, Validators(make([][]byte, 5)).threshold())
ts.Equal(3, Validators(make([][]byte, 6)).threshold())
ts.Equal(3, Validators(make([][]byte, 7)).threshold())
ts.Equal(3, Validators(make([][]byte, 8)).threshold())
ts.Equal(4, Validators(make([][]byte, 9)).threshold())
ts.Equal(8, Validators(make([][]byte, 21)).threshold())
}
2 changes: 1 addition & 1 deletion tool/testdata/internal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/datachainlab/ethereum-ibc-relay-chain/pkg/relay/ethereum"
"github.com/datachainlab/ethereum-ibc-relay-chain/pkg/relay/ethereum/signers/hd"
"github.com/datachainlab/ibc-hd-signer/pkg/hd"
"github.com/datachainlab/ibc-parlia-relay/module"
"github.com/spf13/viper"
"os"
Expand Down