Skip to content

Commit

Permalink
fix light header test (cosmos#930)
Browse files Browse the repository at this point in the history
attempt to fix light client header sync test

fixed it by specifying `InitialHeight=1` in the `GenesisDoc`. Not
entirely sure why this is needed for just the light node and not the
full nodes

Fixes cosmos#917

---------

Co-authored-by: Connor O'Hara <[email protected]>
Co-authored-by: Manav Aggarwal <[email protected]>
  • Loading branch information
3 people authored May 18, 2023
1 parent a1569f5 commit 1ed3c81
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions node/full_node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
tmtypes "github.com/tendermint/tendermint/types"

"github.com/rollkit/rollkit/config"
"github.com/rollkit/rollkit/da"
mockda "github.com/rollkit/rollkit/da/mock"
"github.com/rollkit/rollkit/mocks"
"github.com/rollkit/rollkit/p2p"
Expand Down Expand Up @@ -312,33 +311,43 @@ func testSingleAggreatorSingleFullNodeSingleLightNode(t *testing.T) {
var wg sync.WaitGroup
aggCtx, aggCancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
clientNodes := 2
nodes, _ := createNodes(aggCtx, ctx, clientNodes+1, false, &wg, t)

node1 := nodes[0]
node2 := nodes[1]
node3 := nodes[2]
num := 3
keys := make([]crypto.PrivKey, num)
for i := 0; i < num; i++ {
keys[i], _, _ = crypto.GenerateEd25519Key(rand.Reader)
}
dalc := &mockda.DataAvailabilityLayerClient{}
ds, _ := store.NewDefaultInMemoryKVStore()
_ = dalc.Init([8]byte{}, nil, ds, log.TestingLogger())
_ = dalc.Start()
sequencer, _ := createNode(aggCtx, 0, false, true, false, keys, &wg, t)
fullNode, _ := createNode(ctx, 1, false, false, false, keys, &wg, t)

require.NoError(node1.Start())
time.Sleep(2 * time.Second) // wait for more than 1 blocktime for syncer to work
require.NoError(node2.Start())
sequencer.(*FullNode).dalc = dalc
sequencer.(*FullNode).blockManager.SetDALC(dalc)
fullNode.(*FullNode).dalc = dalc
fullNode.(*FullNode).blockManager.SetDALC(dalc)

node3.conf.Light = true
require.NoError(node3.Start())
lightNode, _ := createNode(ctx, 2, false, false, true, keys, &wg, t)

require.NoError(sequencer.Start())
require.NoError(fullNode.Start())
require.NoError(lightNode.Start())

time.Sleep(3 * time.Second)

n1h := node1.hExService.headerStore.Height()
n1h := sequencer.(*FullNode).hExService.headerStore.Height()
aggCancel()
require.NoError(node1.Stop())
require.NoError(sequencer.Stop())

time.Sleep(3 * time.Second)

n2h := node2.hExService.headerStore.Height()
n3h := node3.hExService.headerStore.Height()
n2h := fullNode.(*FullNode).hExService.headerStore.Height()
n3h := lightNode.(*LightNode).hExService.headerStore.Height()
cancel()
require.NoError(node2.Stop())
require.NoError(node3.Stop())
require.NoError(fullNode.Stop())
require.NoError(lightNode.Stop())

assert.Equal(n1h, n2h, "heights must match")
assert.Equal(n1h, n3h, "heights must match")
Expand Down Expand Up @@ -476,15 +485,23 @@ func createNodes(aggCtx, ctx context.Context, num int, isMalicious bool, wg *syn
ds, _ := store.NewDefaultInMemoryKVStore()
_ = dalc.Init([8]byte{}, nil, ds, log.TestingLogger())
_ = dalc.Start()
nodes[0], apps[0] = createNode(aggCtx, 0, isMalicious, true, dalc, keys, wg, t)
node, app := createNode(aggCtx, 0, isMalicious, true, false, keys, wg, t)
apps[0] = app
nodes[0] = node.(*FullNode)
// use same, common DALC, so nodes can share data
nodes[0].dalc = dalc
nodes[0].blockManager.SetDALC(dalc)
for i := 1; i < num; i++ {
nodes[i], apps[i] = createNode(ctx, i, isMalicious, false, dalc, keys, wg, t)
node, apps[i] = createNode(ctx, i, isMalicious, false, false, keys, wg, t)
nodes[i] = node.(*FullNode)
nodes[i].dalc = dalc
nodes[i].blockManager.SetDALC(dalc)
}

return nodes, apps
}

func createNode(ctx context.Context, n int, isMalicious bool, aggregator bool, dalc da.DataAvailabilityLayerClient, keys []crypto.PrivKey, wg *sync.WaitGroup, t *testing.T) (*FullNode, *mocks.Application) {
func createNode(ctx context.Context, n int, isMalicious bool, aggregator bool, isLight bool, keys []crypto.PrivKey, wg *sync.WaitGroup, t *testing.T) (Node, *mocks.Application) {
t.Helper()
require := require.New(t)
// nodes will listen on consecutive ports on local interface
Expand Down Expand Up @@ -535,25 +552,25 @@ func createNode(ctx context.Context, n int, isMalicious bool, aggregator bool, d
}

genesisValidators, signingKey := getGenesisValidatorSetWithSigner(1)
node, err := newFullNode(
genesis := &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}
// TODO: need to investigate why this needs to be done for light nodes
genesis.InitialHeight = 1
node, err := NewNode(
ctx,
config.NodeConfig{
P2P: p2pConfig,
DALayer: "mock",
Aggregator: aggregator,
BlockManagerConfig: bmConfig,
Light: isLight,
},
keys[n],
signingKey,
proxy.NewLocalClientCreator(app),
&tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators},
genesis,
log.TestingLogger().With("node", n))
require.NoError(err)
require.NotNil(node)

// use same, common DALC, so nodes can share data
node.dalc = dalc
node.blockManager.SetDALC(dalc)

return node, app
}

0 comments on commit 1ed3c81

Please sign in to comment.