Skip to content

Commit e83f9f5

Browse files
authored
Merge branch 'main' into manav/fix_batch_validation
2 parents 0ae49c1 + beb4e92 commit e83f9f5

15 files changed

Lines changed: 109 additions & 114 deletions

File tree

block/manager.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
const (
3131
// defaultDABlockTime is used only if DABlockTime is not configured for manager
32-
defaultDABlockTime = 15 * time.Second
32+
defaultDABlockTime = 6 * time.Second
3333

3434
// defaultBlockTime is used only if BlockTime is not configured for manager
3535
defaultBlockTime = 1 * time.Second
@@ -586,15 +586,6 @@ func (m *Manager) publishBlockInternal(ctx context.Context) error {
586586
}
587587
}
588588

589-
newState, err := m.applyBlock(ctx, header, data)
590-
if err != nil {
591-
if ctx.Err() != nil {
592-
return err
593-
}
594-
// if call to applyBlock fails, we halt the node, see https://github.com/cometbft/cometbft/pull/496
595-
panic(err)
596-
}
597-
598589
signature, err = m.getSignature(header.Header)
599590
if err != nil {
600591
return err
@@ -604,8 +595,17 @@ func (m *Manager) publishBlockInternal(ctx context.Context) error {
604595
header.Signature = signature
605596

606597
if err := header.ValidateBasic(); err != nil {
607-
// TODO(tzdybal): I think this is could be even a panic, because if this happens, header is FUBAR
608-
m.logger.Error("header validation error", "error", err)
598+
// If this ever happens, for recovery, check for a mismatch between the configured signing key and the proposer address in the genesis file
599+
panic(fmt.Errorf("critical: newly produced header failed validation: %w", err))
600+
}
601+
602+
newState, err := m.applyBlock(ctx, header, data)
603+
if err != nil {
604+
if ctx.Err() != nil {
605+
return err
606+
}
607+
// if call to applyBlock fails, we halt the node, see https://github.com/cometbft/cometbft/pull/496
608+
panic(err)
609609
}
610610

611611
// append metadata to Data before validating and saving

da/client.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

da/cmd/local-da/README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Local DA
22

3-
Local DA implements the [go-da][go-da] interface over a Local Data Availability service.
3+
Local DA implements the [da][da] interface over a Local Data Availability service.
44

55
It is intended to be used for testing DA layers without having to set up the actual services.
66

@@ -15,28 +15,41 @@ make build
1515
./build/local-da
1616
```
1717

18-
should output
18+
This will start the Local DA service with default settings, listening on `localhost:7980` and with a default maximum blob size.
19+
20+
The output should look similar to this (the timestamp and maxBlobSize might vary):
1921

2022
```sh
21-
2024/04/11 12:23:34 Listening on: localhost:7980
23+
11:07AM INF NewLocalDA: initialized LocalDA module=local-da
24+
11:07AM INF Listening on host=localhost maxBlobSize=1974272 module=da port=7980
25+
11:07AM INF server started listening on=localhost:7980 module=da
2226
```
2327

24-
Which exposes the [go-da] interface over JSONRPC and can be accessed with an HTTP client like [xh][xh]:
28+
Which exposes the [da] interface over JSONRPC and can be accessed with an HTTP client like [xh][xh]:
29+
30+
#### Flags
31+
32+
You can customize the behavior of the `local-da` binary using the following flags:
2533

26-
You can also run local-da with a `-listen-all` flag which will make the process listen on 0.0.0.0 so that it can be accessed from other machines.
34+
* `-port <port>`: Specifies the listening port. Default: `7980`.
35+
* `-host <host>`: Specifies the listening address. Default: `localhost`.
36+
* `-listen-all`: If set, the service listens on all network interfaces (`0.0.0.0`) instead of just `localhost`. This allows access from other machines.
37+
* `-max-blob-size <bytes>`: Sets the maximum blob size in bytes that the DA service will accept. Default: `1974272` (which is `64 * 64 * 482`).
38+
39+
**Example with flags:**
40+
41+
To run `local-da` on port `8000`, accessible from any IP, with a max blob size of `1000000` bytes:
2742

2843
```sh
29-
$ ./build/local-da -listen-all
30-
2024/04/11 12:23:34 Listening on: 0.0.0.0:7980
44+
./build/local-da -port 8000 -listen-all -max-blob-size 1000000
3145
```
3246

33-
### Docker
34-
35-
You can also run the local-da service using docker:
47+
Output:
3648

3749
```sh
38-
make docker-build
39-
docker run --rm -p 7980:7980 local-da
50+
11:07AM INF NewLocalDA: initialized LocalDA module=local-da
51+
11:07AM INF Listening on host=0.0.0.0 maxBlobSize=1974272 module=da port=8000
52+
11:07AM INF server started listening on=0.0.0.0:8000 module=da
4053
```
4154

4255
### MaxBlobSize
@@ -93,9 +106,9 @@ output:
93106

94107
## References
95108

96-
[1] [go-da][go-da]
109+
[1] [da][ da]
97110

98111
[2] [xh][xh]
99112

100-
[go-da]: https://github.com/rollkit/go-da
113+
[da]: https://github.com/rollkit/rollkit/blob/main/core/da/da.go#L11
101114
[xh]: https://github.com/ducaale/xh

da/jsonrpc/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package jsonrpc
22

33
import (
44
"context"
5+
"encoding/hex"
56
"errors"
67
"fmt"
78
"net/http"
@@ -246,7 +247,12 @@ func newClient(ctx context.Context, logger log.Logger, addr string, authHeader h
246247
var multiCloser multiClientCloser
247248
var client Client
248249
client.DA.Logger = logger
249-
client.DA.Namespace = []byte(namespace)
250+
namespaceBytes, err := hex.DecodeString(namespace)
251+
if err != nil {
252+
return nil, fmt.Errorf("failed to decode namespace: %w", err)
253+
}
254+
client.DA.Namespace = namespaceBytes
255+
logger.Info("Creating new client", "namespace", namespace)
250256
errs := getKnownErrorsMapping()
251257
for name, module := range moduleMap(&client) {
252258
closer, err := jsonrpc.NewMergeClient(ctx, addr, name, []interface{}{module}, authHeader, jsonrpc.WithErrors(errs))

da/jsonrpc/proxy_test.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"errors"
7+
"fmt"
78
"sync"
89
"testing"
910
"time"
@@ -45,7 +46,7 @@ func TestProxy(t *testing.T) {
4546
}
4647
}()
4748

48-
client, err := proxy.NewClient(context.Background(), logger, ClientURL, "", "test")
49+
client, err := proxy.NewClient(context.Background(), logger, ClientURL, "", "74657374")
4950
require.NoError(t, err)
5051
RunDATestSuite(t, &client.DA)
5152
}
@@ -167,25 +168,34 @@ func GetIDsTest(t *testing.T, d coreda.DA) {
167168
// ConcurrentReadWriteTest tests the use of mutex lock in DummyDA by calling separate methods that use `d.data` and making sure there's no race conditions
168169
func ConcurrentReadWriteTest(t *testing.T, d coreda.DA) {
169170
var wg sync.WaitGroup
170-
wg.Add(2)
171+
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
172+
defer cancel()
171173

172-
ctx := context.TODO()
174+
writeDone := make(chan struct{})
173175

176+
wg.Add(1)
174177
go func() {
175178
defer wg.Done()
176-
for i := uint64(1); i <= 100; i++ {
177-
ret, err := d.GetIDs(ctx, i, []byte("test"))
178-
if err != nil {
179-
assert.Empty(t, ret.IDs)
180-
}
179+
for i := uint64(1); i <= 50; i++ {
180+
_, err := d.Submit(ctx, []coreda.Blob{[]byte(fmt.Sprintf("test-%d", i))}, 0, []byte{})
181+
assert.NoError(t, err)
181182
}
183+
close(writeDone)
182184
}()
183185

186+
wg.Add(1)
184187
go func() {
185188
defer wg.Done()
186-
for i := uint64(1); i <= 100; i++ {
187-
_, err := d.Submit(ctx, []coreda.Blob{[]byte("test")}, 0, []byte{})
188-
assert.NoError(t, err)
189+
for {
190+
select {
191+
case <-writeDone:
192+
return
193+
default:
194+
ret, err := d.GetIDs(ctx, 1, []byte("test"))
195+
if err != nil {
196+
assert.Empty(t, ret.IDs)
197+
}
198+
}
189199
}
190200
}()
191201

node/full.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
"github.com/rollkit/rollkit/pkg/sync"
3232
)
3333

34-
// prefixes used in KV store to separate main node data from DALC data
35-
var mainPrefix = "0"
34+
// prefixes used in KV store to separate rollkit data from execution environment data (if the same data base is reused)
35+
var RollkitPrefix = "0"
3636

3737
const (
3838
// genesisChunkSize is the maximum size, in bytes, of each
@@ -84,7 +84,7 @@ func newFullNode(
8484
) (fn *FullNode, err error) {
8585
seqMetrics, _ := metricsProvider(genesis.ChainID)
8686

87-
mainKV := newPrefixKV(database, mainPrefix)
87+
mainKV := newPrefixKV(database, RollkitPrefix)
8888
headerSyncService, err := initHeaderSyncService(mainKV, nodeConfig, genesis, p2pClient, logger)
8989
if err != nil {
9090
return nil, err
@@ -539,5 +539,5 @@ func (n *FullNode) GetLogger() log.Logger {
539539
}
540540

541541
func newPrefixKV(kvStore ds.Batching, prefix string) ds.Batching {
542-
return (ktds.Wrap(kvStore, ktds.PrefixTransform{Prefix: ds.NewKey(prefix)}).Children()[0]).(ds.Batching)
542+
return ktds.Wrap(kvStore, ktds.PrefixTransform{Prefix: ds.NewKey(prefix)})
543543
}

pkg/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,9 @@ func LoadFromViper(inputViper *viper.Viper) (Config, error) {
352352
// then override with settings from input viper (higher precedence)
353353
for _, key := range inputViper.AllKeys() {
354354
// Handle special case for prefixed keys
355-
if strings.HasPrefix(key, "rollkit.") {
355+
if after, ok := strings.CutPrefix(key, "rollkit."); ok {
356356
// Strip the prefix for the merged viper
357-
strippedKey := strings.TrimPrefix(key, "rollkit.")
357+
strippedKey := after
358358
mergedViper.Set(strippedKey, inputViper.Get(key))
359359
} else {
360360
mergedViper.Set(key, inputViper.Get(key))

pkg/store/prefix_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,4 @@ func TestPrefixKVBatch(t *testing.T) {
106106
prefixbatchkv2, _ := badgerPrefixkv.NewTransaction(t.Context(), false)
107107
err = prefixbatchkv2.Delete(t.Context(), ds.NewKey("key1"))
108108
require.NoError(err)
109-
110109
}

rollups/evm/single/cmd/run.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"path/filepath"
77

8-
"github.com/rollkit/rollkit/da"
8+
"github.com/rollkit/rollkit/da/jsonrpc"
99
"github.com/rollkit/rollkit/sequencers/single"
1010
"github.com/rs/zerolog"
1111

@@ -50,7 +50,7 @@ var RunCmd = &cobra.Command{
5050

5151
logger := rollcmd.SetupLogger(nodeConfig.Log)
5252

53-
daJrpc, err := da.NewClient(logger, nodeConfig.DA.Address, nodeConfig.DA.AuthToken, nodeConfig.DA.Namespace)
53+
daJrpc, err := jsonrpc.NewClient(context.Background(), logger, nodeConfig.DA.Address, nodeConfig.DA.AuthToken, nodeConfig.DA.Namespace)
5454
if err != nil {
5555
return err
5656
}
@@ -69,7 +69,7 @@ var RunCmd = &cobra.Command{
6969
context.Background(),
7070
logger,
7171
datastore,
72-
daJrpc,
72+
&daJrpc.DA,
7373
[]byte(nodeConfig.ChainID),
7474
nodeConfig.Node.BlockTime.Duration,
7575
singleMetrics,
@@ -89,7 +89,7 @@ var RunCmd = &cobra.Command{
8989
return err
9090
}
9191

92-
return rollcmd.StartNode(logger, cmd, executor, sequencer, daJrpc, nodeKey, p2pClient, datastore, nodeConfig)
92+
return rollcmd.StartNode(logger, cmd, executor, sequencer, &daJrpc.DA, nodeKey, p2pClient, datastore, nodeConfig)
9393
},
9494
}
9595

rollups/evm/single/docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ services:
3939
- rollkit-network
4040

4141
rollkit-evm-single:
42-
image: ghcr.io/rollkit/rollkit-evm-single:v0.1.2
42+
image: ghcr.io/rollkit/rollkit-evm-single:v0.1.3
4343
depends_on:
4444
reth:
4545
condition: service_started
@@ -55,9 +55,9 @@ services:
5555
- EVM_GENESIS_HASH=0x0a962a0d163416829894c89cb604ae422323bcdf02d7ea08b94d68d3e026a380
5656
- EVM_BLOCK_TIME=1s
5757
- EVM_SIGNER_PASSPHRASE=secret
58-
# - ROLLKIT_DA_ADDRESS=<da_address>
59-
# - ROLLKIT_DA_AUTH_TOKEN=<da_auth_token>
60-
# - ROLLKIT_DA_NAMESPACE=<da_namespace>
58+
# - DA_ADDRESS=http://localhost:26658
59+
# - DA_AUTH_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJwdWJsaWMiLCJyZWFkIiwid3JpdGUiXSwiTm9uY2UiOiJQcEswTmhyWi9IY05NWkVtUG9sSXNpRTRDcUpMdE9mbWtBMW0zMWFUaEswPSIsIkV4cGlyZXNBdCI6IjAwMDEtMDEtMDFUMDA6MDA6MDBaIn0.gaWh6tS6Rel1XFYclDkapNnZlaZVjrikCRNBxSDkCGk
60+
# - DA_NAMESPACE=00000000000000000000000000000000000000000008e5f679bf7116c1
6161
networks:
6262
- rollkit-network
6363

0 commit comments

Comments
 (0)