Skip to content

Commit

Permalink
refactor(swamp): use celestia-app instead of the kvstore (#1160)
Browse files Browse the repository at this point in the history
Co-authored-by: Wondertan <[email protected]>
  • Loading branch information
evan-forbes and Wondertan authored Oct 11, 2022
1 parent e89b628 commit d0eaef6
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 153 deletions.
15 changes: 12 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ replace github.com/ipfs/go-verifcid => github.com/celestiaorg/go-verifcid v0.0.1

require (
cosmossdk.io/math v1.0.0-beta.3
github.com/99designs/keyring v1.2.1 // indirect
github.com/BurntSushi/toml v1.2.0
github.com/celestiaorg/celestia-app v0.7.0-rc-1
github.com/celestiaorg/go-libp2p-messenger v0.1.0
Expand Down Expand Up @@ -71,7 +72,6 @@ require (
cosmossdk.io/errors v1.0.0-beta.7 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/Workiva/go-datastructures v1.0.53 // indirect
github.com/armon/go-metrics v0.4.0 // indirect
Expand All @@ -88,6 +88,8 @@ require (
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cheekybits/genny v1.0.0 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
github.com/confio/ics23/go v0.7.0 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 // indirect
Expand All @@ -104,6 +106,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/docker/go-units v0.4.0 // indirect
Expand Down Expand Up @@ -151,6 +154,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/go-ipfs-delay v0.0.1 // indirect
Expand Down Expand Up @@ -196,6 +200,7 @@ require (
github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-19 v0.1.0-beta.1 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/miekg/dns v1.1.50 // indirect
Expand Down Expand Up @@ -231,7 +236,9 @@ require (
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/rs/zerolog v1.27.0 // indirect
github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
Expand Down Expand Up @@ -271,18 +278,20 @@ require (
google.golang.org/api v0.81.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad // indirect
google.golang.org/protobuf v1.28.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
nhooyr.io/websocket v1.8.6 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace (
github.com/celestiaorg/celestia-app => github.com/celestiaorg/celestia-app v0.7.0-rc-1.0.20220930201625-f8540b2aec19
github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.2.0-sdk-v0.46.0
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/libp2p/go-libp2p-pubsub v0.7.0 => github.com/celestiaorg/go-libp2p-pubsub v0.6.2-0.20220812132010-46b2a019f2f2
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.3.3-tm-v0.34.20
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.3.3-tm-v0.34.20-celestia-node-patch
)
273 changes: 268 additions & 5 deletions go.sum

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions nodebuilder/tests/fraud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestFraudProofBroadcasting(t *testing.T) {

bridge := sw.NewBridgeNode(core.WithHeaderConstructFn(header.FraudMaker(t, 20)))

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout)
t.Cleanup(cancel)

err := bridge.Start(ctx)
Expand All @@ -56,17 +56,18 @@ func TestFraudProofBroadcasting(t *testing.T) {
subscr, err := full.FraudServ.Subscribe(fraud.BadEncoding)
require.NoError(t, err)

_, err = subscr.Proof(ctx)
p, err := subscr.Proof(ctx)
require.NoError(t, err)

// Since GetByHeight is a blocking operation for headers that is not received, we
// should set a timeout because all daser/syncer are stopped at this point
newCtx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500)
// rework this after https://github.com/celestiaorg/celestia-node/issues/427
t.Cleanup(cancel)

_, err = full.HeaderServ.GetByHeight(newCtx, 25)
require.Equal(t, 20, int(p.Height()))

// This is an obscure way to check if the Syncer was stopped.
// If we cannot get a height header within a timeframe it means the syncer was stopped
// FIXME: Eventually, this should be a check on service registry managing and keeping
// lifecycles of each Module.
syncCtx, syncCancel := context.WithTimeout(context.Background(), time.Millisecond*100)
_, err = full.HeaderServ.GetByHeight(syncCtx, 100)
require.ErrorIs(t, err, context.DeadlineExceeded)
syncCancel()

require.NoError(t, full.Stop(ctx))
require.NoError(t, sw.RemoveNode(full, node.Full))
Expand All @@ -93,7 +94,7 @@ Steps:
7. Wait until LN will be connected to FN and fetch a fraud proof.
*/
func TestFraudProofSyncing(t *testing.T) {
sw := swamp.NewSwamp(t, swamp.WithBlockTime(time.Millisecond*100))
sw := swamp.NewSwamp(t, swamp.WithBlockTime(time.Millisecond*300))

const defaultTimeInterval = time.Second * 5

Expand All @@ -106,7 +107,7 @@ func TestFraudProofSyncing(t *testing.T) {
store := nodebuilder.MockStore(t, cfg)
bridge := sw.NewNodeWithStore(node.Bridge, store, core.WithHeaderConstructFn(header.FraudMaker(t, 10)))

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
t.Cleanup(cancel)

err := bridge.Start(ctx)
Expand Down
8 changes: 4 additions & 4 deletions nodebuilder/tests/p2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestUseBridgeNodeAsBootstraper(t *testing.T) {

bridge := sw.NewBridgeNode()

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout)
t.Cleanup(cancel)

err := bridge.Start(ctx)
Expand Down Expand Up @@ -63,7 +63,7 @@ Steps:
func TestAddPeerToBlackList(t *testing.T) {
sw := swamp.NewSwamp(t)
full := sw.NewFullNode()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout)
t.Cleanup(cancel)
require.NoError(t, full.Start(ctx))

Expand Down Expand Up @@ -97,7 +97,7 @@ func TestBootstrapNodesFromBridgeNode(t *testing.T) {

bridge := sw.NewNodeWithConfig(node.Bridge, cfg)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout)
t.Cleanup(cancel)

err := bridge.Start(ctx)
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestRestartNodeDiscovery(t *testing.T) {
cfg.Share.PeersLimit = fullNodes
bridge := sw.NewNodeWithConfig(node.Bridge, cfg)

ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout)
t.Cleanup(cancel)

err := bridge.Start(ctx)
Expand Down
23 changes: 9 additions & 14 deletions nodebuilder/tests/reconstruct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,13 @@ func TestFullReconstructFromBridge(t *testing.T) {
const (
blocks = 20
bsize = 16
btime = time.Millisecond * 100
btime = time.Millisecond * 300
)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout)
t.Cleanup(cancel)
sw := swamp.NewSwamp(t, swamp.WithBlockTime(btime))
errCh := make(chan error)
go func() {
errCh <- sw.FillBlocks(ctx, bsize, blocks)
}()
fillDn := sw.FillBlocks(ctx, bsize, blocks)

bridge := sw.NewBridgeNode()
err := bridge.Start(ctx)
Expand All @@ -72,7 +69,7 @@ func TestFullReconstructFromBridge(t *testing.T) {
return full.ShareServ.SharesAvailable(bctx, h.DAH)
})
}
require.NoError(t, <-errCh)
require.NoError(t, <-fillDn)
require.NoError(t, errg.Wait())
}

Expand All @@ -97,18 +94,16 @@ func TestFullReconstructFromLights(t *testing.T) {
share.DefaultSampleAmount = 20
const (
blocks = 20
btime = time.Millisecond * 100
btime = time.Millisecond * 300
bsize = 16
lnodes = 69
)

ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout)

t.Cleanup(cancel)
sw := swamp.NewSwamp(t, swamp.WithBlockTime(btime))
errCh := make(chan error)
go func() {
errCh <- sw.FillBlocks(ctx, bsize, blocks)
}()
fillDn := sw.FillBlocks(ctx, bsize, blocks)

const defaultTimeInterval = time.Second * 5
cfg := nodebuilder.DefaultConfig(node.Full)
Expand Down Expand Up @@ -171,7 +166,7 @@ func TestFullReconstructFromLights(t *testing.T) {
return full.ShareServ.SharesAvailable(bctx, h.DAH)
})
}
require.NoError(t, <-errCh)
require.NoError(t, <-fillDn)
require.NoError(t, errg.Wait())
}

Expand Down
12 changes: 3 additions & 9 deletions nodebuilder/tests/swamp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,20 @@ package swamp
import (
"time"

"github.com/tendermint/tendermint/abci/types"
tn "github.com/tendermint/tendermint/config"

"github.com/celestiaorg/celestia-node/core"
)

// Components struct represents a set of pre-requisite attributes from the test scenario
type Components struct {
App types.Application
CoreCfg *tn.Config
}

// DefaultComponents creates a KvStore with a block retention of 200
// In addition, the empty block interval is set to 200ms
func DefaultComponents() *Components {
app := core.CreateKVStore(2000)
tnCfg := tn.ResetTestRoot("swamp_tests")
tnCfg.Consensus.CreateEmptyBlocksInterval = 100 * time.Millisecond
tnCfg := tn.TestConfig()
tnCfg.Consensus.TimeoutCommit = 50 * time.Millisecond
return &Components{
App: app,
CoreCfg: tnCfg,
}
}
Expand All @@ -37,6 +31,6 @@ func WithBlockTime(t time.Duration) Option {
c.CoreCfg.Consensus.CreateEmptyBlocksInterval = t
// for filled block
c.CoreCfg.Consensus.TimeoutCommit = t
c.CoreCfg.Consensus.SkipTimeoutCommit = true
c.CoreCfg.Consensus.SkipTimeoutCommit = false
}
}
Loading

0 comments on commit d0eaef6

Please sign in to comment.