Skip to content

Commit 06e9b98

Browse files
Manav-AggarwalFerret-sanGanesha Upadhyaya
authored
code-hygiene: Move fraud proofs to feature branch (#1092)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview Closes: #1094 Moved the existing fraud proof related code to this [branch](https://github.com/rollkit/rollkit/tree/with_abci_fraud_proofs). <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [x] New and updated code has appropriate documentation - [x] New and updated code has new and/or updated testing - [x] Required CI checks are passing - [x] Visual proof for any user facing features like CLI or documentation updates - [x] Linked issues closed with keywords --------- Co-authored-by: Diego <31937514+Ferret-san@users.noreply.github.com> Co-authored-by: Ganesha Upadhyaya <gupadhyaya@Ganeshas-MacBook-Pro-2.local>
1 parent efdb3e3 commit 06e9b98

17 files changed

Lines changed: 67 additions & 655 deletions

block/manager.go

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"sync/atomic"
1010
"time"
1111

12-
"github.com/celestiaorg/go-fraud/fraudserv"
1312
abci "github.com/cometbft/cometbft/abci/types"
1413
cmcrypto "github.com/cometbft/cometbft/crypto"
1514
"github.com/cometbft/cometbft/crypto/merkle"
@@ -120,7 +119,7 @@ func NewManager(
120119
conf.DABlockTime = defaultDABlockTime
121120
}
122121

123-
exec := state.NewBlockExecutor(proposerAddress, conf.NamespaceID, genesis.ChainID, mempool, proxyApp, conf.FraudProofs, eventBus, logger)
122+
exec := state.NewBlockExecutor(proposerAddress, conf.NamespaceID, genesis.ChainID, mempool, proxyApp, eventBus, logger)
124123
if s.LastBlockHeight+1 == genesis.InitialHeight {
125124
res, err := exec.InitChain(genesis)
126125
if err != nil {
@@ -246,45 +245,6 @@ func (m *Manager) AggregationLoop(ctx context.Context, lazy bool) {
246245
}
247246
}
248247

249-
func (m *Manager) SetFraudProofService(fraudProofServ *fraudserv.ProofService) {
250-
m.executor.SetFraudProofService(fraudProofServ)
251-
}
252-
253-
func (m *Manager) ProcessFraudProof(ctx context.Context, cancel context.CancelFunc) {
254-
defer cancel()
255-
// subscribe to state fraud proof
256-
sub, err := m.executor.FraudService.Subscribe(types.StateFraudProofType)
257-
if err != nil {
258-
m.logger.Error("failed to subscribe to fraud proof gossip", "error", err)
259-
return
260-
}
261-
defer sub.Cancel()
262-
263-
// blocks until a valid fraud proof is received via subscription
264-
// sub.Proof is a blocking call that only returns on proof received or context ended
265-
proof, err := sub.Proof(ctx)
266-
if err != nil {
267-
m.logger.Error("failed to receive gossiped fraud proof", "error", err)
268-
return
269-
}
270-
271-
// only handle the state fraud proofs for now
272-
fraudProof, ok := proof.(*types.StateFraudProof)
273-
if !ok {
274-
m.logger.Error("unexpected type received for state fraud proof", "error", err)
275-
return
276-
}
277-
m.logger.Debug("fraud proof received",
278-
"block height", fraudProof.BlockHeight,
279-
"pre-state app hash", fraudProof.PreStateAppHash,
280-
"expected valid app hash", fraudProof.ExpectedValidAppHash,
281-
"length of state witness", len(fraudProof.StateWitness),
282-
)
283-
284-
// halt chain
285-
m.logger.Info("verified fraud proof, halting chain")
286-
}
287-
288248
// SyncLoop is responsible for syncing blocks.
289249
//
290250
// SyncLoop processes headers gossiped in P2p network to know what's the latest block height,
@@ -307,9 +267,6 @@ func (m *Manager) SyncLoop(ctx context.Context, cancel context.CancelFunc) {
307267
m.retrieveCond.Signal()
308268

309269
err := m.trySyncNextBlock(ctx, daHeight)
310-
if err != nil && err.Error() == fmt.Errorf("failed to ApplyBlock: %w", state.ErrFraudProofGenerated).Error() {
311-
return
312-
}
313270
if err != nil {
314271
m.logger.Info("failed to sync next block", "error", err)
315272
}

config/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const (
1818
flagDABlockTime = "rollkit.da_block_time"
1919
flagDAStartHeight = "rollkit.da_start_height"
2020
flagNamespaceID = "rollkit.namespace_id"
21-
flagFraudProofs = "rollkit.experimental_insecure_fraud_proofs"
2221
flagLight = "rollkit.light"
2322
flagTrustedHash = "rollkit.trusted_hash"
2423
flagLazyAggregator = "rollkit.lazy_aggregator"
@@ -55,7 +54,6 @@ type BlockManagerConfig struct {
5554
// DAStartHeight allows skipping first DAStartHeight-1 blocks when querying for blocks.
5655
DAStartHeight uint64 `mapstructure:"da_start_height"`
5756
NamespaceID types.NamespaceID `mapstructure:"namespace_id"`
58-
FraudProofs bool `mapstructure:"fraud_proofs"`
5957
}
6058

6159
// GetViperConfig reads configuration parameters from Viper instance.
@@ -70,7 +68,6 @@ func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error {
7068
nc.BlockTime = v.GetDuration(flagBlockTime)
7169
nc.LazyAggregator = v.GetBool(flagLazyAggregator)
7270
nsID := v.GetString(flagNamespaceID)
73-
nc.FraudProofs = v.GetBool(flagFraudProofs)
7471
nc.Light = v.GetBool(flagLight)
7572
bytes, err := hex.DecodeString(nsID)
7673
if err != nil {
@@ -94,7 +91,6 @@ func AddFlags(cmd *cobra.Command) {
9491
cmd.Flags().Duration(flagDABlockTime, def.DABlockTime, "DA chain block time (for syncing)")
9592
cmd.Flags().Uint64(flagDAStartHeight, def.DAStartHeight, "starting DA block height (for syncing)")
9693
cmd.Flags().BytesHex(flagNamespaceID, def.NamespaceID[:], "namespace identifies (8 bytes in hex)")
97-
cmd.Flags().Bool(flagFraudProofs, def.FraudProofs, "enable fraud proofs (experimental & insecure)")
9894
cmd.Flags().Bool(flagLight, def.Light, "run light client")
9995
cmd.Flags().String(flagTrustedHash, def.TrustedHash, "initial trusted hash to start the header exchange service")
10096
}

config/config_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func TestViperAndCobra(t *testing.T) {
2626
assert.NoError(cmd.Flags().Set(flagDAConfig, `{"json":true}`))
2727
assert.NoError(cmd.Flags().Set(flagBlockTime, "1234s"))
2828
assert.NoError(cmd.Flags().Set(flagNamespaceID, "0102030405060708"))
29-
assert.NoError(cmd.Flags().Set(flagFraudProofs, "false"))
3029

3130
nc := DefaultNodeConfig
3231
assert.NoError(nc.GetViperConfig(v))
@@ -36,5 +35,4 @@ func TestViperAndCobra(t *testing.T) {
3635
assert.Equal(`{"json":true}`, nc.DAConfig)
3736
assert.Equal(1234*time.Second, nc.BlockTime)
3837
assert.Equal(types.NamespaceID{1, 2, 3, 4, 5, 6, 7, 8}, nc.NamespaceID)
39-
assert.Equal(false, nc.FraudProofs)
4038
}

config/defaults.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ var DefaultNodeConfig = NodeConfig{
2323
BlockManagerConfig: BlockManagerConfig{
2424
BlockTime: 30 * time.Second,
2525
NamespaceID: types.NamespaceID{},
26-
FraudProofs: false,
2726
},
2827
DALayer: "mock",
2928
DAConfig: "",

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ go 1.20
44

55
require (
66
cosmossdk.io/math v1.0.1
7-
github.com/celestiaorg/go-fraud v0.1.2
87
github.com/celestiaorg/go-header v0.2.12
98
github.com/celestiaorg/nmt v0.17.0
109
github.com/celestiaorg/rsmt2d v0.9.0
1110
github.com/celestiaorg/utils v0.1.0
12-
github.com/cometbft/cometbft v0.37.0
11+
github.com/cometbft/cometbft v0.37.1
1312
github.com/creachadair/taskgroup v0.3.2
1413
github.com/dgraph-io/badger/v3 v3.2103.5
1514
github.com/go-kit/kit v0.12.0
@@ -42,6 +41,7 @@ require (
4241
github.com/beorn7/perks v1.0.1 // indirect
4342
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
4443
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect
44+
github.com/celestiaorg/go-fraud v0.1.2 // indirect
4545
github.com/celestiaorg/go-libp2p-messenger v0.2.0 // indirect
4646
github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 // indirect
4747
github.com/cespare/xxhash v1.1.0 // indirect
@@ -188,7 +188,6 @@ require (
188188
)
189189

190190
replace (
191-
github.com/cometbft/cometbft => github.com/rollkit/cometbft v0.37.1
192191
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4
193192
google.golang.org/grpc => google.golang.org/grpc v1.33.2
194193
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH
237237
github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
238238
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
239239
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
240+
github.com/cometbft/cometbft v0.37.1 h1:KLxkQTK2hICXYq21U2hn1W5hOVYUdQgDQ1uB+90xPIg=
241+
github.com/cometbft/cometbft v0.37.1/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs=
240242
github.com/cometbft/cometbft-db v0.8.0 h1:vUMDaH3ApkX8m0KZvOFFy9b5DZHBAjsnEuo9AKVZpjo=
241243
github.com/cometbft/cometbft-db v0.8.0/go.mod h1:6ASCP4pfhmrCBpfk01/9E1SI29nD3HfVHrY4PG8x5c0=
242244
github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE=
@@ -1366,8 +1368,6 @@ github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4
13661368
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
13671369
github.com/rollkit/celestia-openrpc v0.1.1 h1:Ub8ydB1c0qDQJmYL+s7i5u9YiQyINxw88AL1S8A+Lig=
13681370
github.com/rollkit/celestia-openrpc v0.1.1/go.mod h1:Or8y0vuAzJu3SLOahIOt96+y4Vxaf74vrPFkUJl0oj0=
1369-
github.com/rollkit/cometbft v0.37.1 h1:Nj8Tg3MQoinOI1HmESlqoAgViCAlBb6I2GmAnZoytlQ=
1370-
github.com/rollkit/cometbft v0.37.1/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs=
13711371
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
13721372
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
13731373
github.com/rs/cors v1.9.0 h1:l9HGsTsHJcvW14Nk7J9KFz8bzeAWXn3CG6bgt7LsrAE=

mocks/Application.go

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

node/full.go

Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"errors"
88
"fmt"
99

10-
"github.com/celestiaorg/go-fraud/fraudserv"
11-
"github.com/celestiaorg/go-header"
1210
ds "github.com/ipfs/go-datastore"
1311
ktds "github.com/ipfs/go-datastore/keytransform"
1412
"github.com/libp2p/go-libp2p/core/crypto"
@@ -34,7 +32,6 @@ import (
3432
"github.com/rollkit/rollkit/state/txindex"
3533
"github.com/rollkit/rollkit/state/txindex/kv"
3634
"github.com/rollkit/rollkit/store"
37-
"github.com/rollkit/rollkit/types"
3835
)
3936

4037
// prefixes used in KV store to separate main node data from DALC data
@@ -79,10 +76,8 @@ type FullNode struct {
7976
BlockIndexer indexer.BlockIndexer
8077
IndexerService *txindex.IndexerService
8178

82-
hExService *HeaderExchangeService
83-
bExService *BlockExchangeService
84-
fraudService *fraudserv.ProofService
85-
proofServiceFactory ProofServiceFactory
79+
hExService *HeaderExchangeService
80+
bExService *BlockExchangeService
8681

8782
// keep context here only because of API compatibility
8883
// - it's used in `OnStart` (defined in service.Service interface)
@@ -167,16 +162,6 @@ func newFullNode(
167162
return nil, fmt.Errorf("HeaderExchangeService initialization error: %w", err)
168163
}
169164

170-
fraudProofFactory := NewProofServiceFactory(
171-
client,
172-
func(ctx context.Context, u uint64) (header.Header, error) {
173-
return headerExchangeService.headerStore.GetByHeight(ctx, u)
174-
},
175-
mainKV,
176-
true,
177-
genesis.ChainID,
178-
)
179-
180165
blockExchangeService, err := NewBlockExchangeService(ctx, mainKV, conf, genesis, client, logger.With("module", "BlockExchangeService"))
181166
if err != nil {
182167
return nil, fmt.Errorf("BlockExchangeService initialization error: %w", err)
@@ -185,26 +170,25 @@ func newFullNode(
185170
ctx, cancel := context.WithCancel(ctx)
186171

187172
node := &FullNode{
188-
proxyApp: proxyApp,
189-
eventBus: eventBus,
190-
genesis: genesis,
191-
conf: conf,
192-
P2P: client,
193-
blockManager: blockManager,
194-
dalc: dalc,
195-
Mempool: mp,
196-
mempoolIDs: mpIDs,
197-
incomingTxCh: make(chan *p2p.GossipMessage),
198-
Store: s,
199-
TxIndexer: txIndexer,
200-
IndexerService: indexerService,
201-
BlockIndexer: blockIndexer,
202-
hExService: headerExchangeService,
203-
bExService: blockExchangeService,
204-
proofServiceFactory: fraudProofFactory,
205-
ctx: ctx,
206-
cancel: cancel,
207-
DoneBuildingBlock: doneBuildingChannel,
173+
proxyApp: proxyApp,
174+
eventBus: eventBus,
175+
genesis: genesis,
176+
conf: conf,
177+
P2P: client,
178+
blockManager: blockManager,
179+
dalc: dalc,
180+
Mempool: mp,
181+
mempoolIDs: mpIDs,
182+
incomingTxCh: make(chan *p2p.GossipMessage),
183+
Store: s,
184+
TxIndexer: txIndexer,
185+
IndexerService: indexerService,
186+
BlockIndexer: blockIndexer,
187+
hExService: headerExchangeService,
188+
bExService: blockExchangeService,
189+
ctx: ctx,
190+
cancel: cancel,
191+
DoneBuildingBlock: doneBuildingChannel,
208192
}
209193

210194
node.BaseService = *service.NewBaseService(logger, "Node", node)
@@ -296,24 +280,12 @@ func (n *FullNode) OnStart() error {
296280
return fmt.Errorf("error while starting data availability layer client: %w", err)
297281
}
298282

299-
// since p2p pubsub and host are required to create ProofService,
300-
// we have to delay the construction until Start and use the help of ProofServiceFactory
301-
n.fraudService = n.proofServiceFactory.CreateProofService()
302-
if err := n.fraudService.AddVerifier(types.StateFraudProofType, VerifierFn(n.proxyApp)); err != nil {
303-
return fmt.Errorf("error while registering verifier for fraud service: %w", err)
304-
}
305-
if err = n.fraudService.Start(n.ctx); err != nil {
306-
return fmt.Errorf("error while starting fraud exchange service: %w", err)
307-
}
308-
n.blockManager.SetFraudProofService(n.fraudService)
309-
310283
if n.conf.Aggregator {
311284
n.Logger.Info("working in aggregator mode", "block time", n.conf.BlockTime)
312285
go n.blockManager.AggregationLoop(n.ctx, n.conf.LazyAggregator)
313286
go n.headerPublishLoop(n.ctx)
314287
go n.blockPublishLoop(n.ctx)
315288
}
316-
go n.blockManager.ProcessFraudProof(n.ctx, n.cancel)
317289
go n.blockManager.RetrieveLoop(n.ctx)
318290
go n.blockManager.SyncLoop(n.ctx, n.cancel)
319291
return nil
@@ -341,7 +313,6 @@ func (n *FullNode) OnStop() {
341313
err = multierr.Append(err, n.P2P.Close())
342314
err = multierr.Append(err, n.hExService.Stop())
343315
err = multierr.Append(err, n.bExService.Stop())
344-
err = multierr.Append(err, n.fraudService.Stop(n.ctx))
345316
n.Logger.Error("errors while stopping node:", "errors", err)
346317
}
347318

node/full_client_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,6 @@ func TestTx(t *testing.T) {
538538
mockApp.On("Commit", mock.Anything).Return(abci.ResponseCommit{})
539539
mockApp.On("DeliverTx", mock.Anything).Return(abci.ResponseDeliverTx{})
540540
mockApp.On("CheckTx", mock.Anything).Return(abci.ResponseCheckTx{})
541-
mockApp.On("GetAppHash", mock.Anything).Return(abci.ResponseGetAppHash{})
542-
mockApp.On("GenerateFraudProof", mock.Anything).Return(abci.ResponseGenerateFraudProof{})
543541

544542
err = rpc.node.Start()
545543
require.NoError(err)
@@ -842,8 +840,6 @@ func createApp(require *require.Assertions, vKeyToRemove cmcrypto.PrivKey, wg *s
842840
app.On("CheckTx", mock.Anything).Return(abci.ResponseCheckTx{})
843841
app.On("BeginBlock", mock.Anything).Return(abci.ResponseBeginBlock{})
844842
app.On("Commit", mock.Anything).Return(abci.ResponseCommit{})
845-
app.On("GetAppHash", mock.Anything).Return(abci.ResponseGetAppHash{})
846-
app.On("GenerateFraudProof", mock.Anything).Return(abci.ResponseGenerateFraudProof{})
847843

848844
pbValKey, err := encoding.PubKeyToProto(vKeyToRemove.PubKey())
849845
require.NoError(err)
@@ -934,7 +930,6 @@ func TestMempool2Nodes(t *testing.T) {
934930
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{})
935931
app.On("Commit", mock.Anything).Return(abci.ResponseCommit{})
936932
app.On("DeliverTx", mock.Anything).Return(abci.ResponseDeliverTx{})
937-
app.On("GetAppHash", mock.Anything).Return(abci.ResponseGetAppHash{})
938933

939934
ctx, cancel := context.WithCancel(context.Background())
940935
defer cancel()

0 commit comments

Comments
 (0)