Skip to content
Closed
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
62 changes: 42 additions & 20 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

goheaderstore "github.com/celestiaorg/go-header/store"

execution "github.com/LastL2/go-execution-abci"
"github.com/rollkit/go-sequencing"
"github.com/rollkit/go-sequencing/proxy/grpc"
"github.com/rollkit/rollkit/config"
Expand Down Expand Up @@ -110,8 +111,6 @@ type Manager struct {

proposerKey crypto.PrivKey

executor *state.BlockExecutor

dalc *da.DAClient
// daHeight is the height of the latest processed DA block
daHeight uint64
Expand Down Expand Up @@ -157,6 +156,7 @@ type Manager struct {
seqClient *grpc.Client
lastBatchHash []byte
bq *BatchQueue
execClient *execution.ABCIExecutionClient
}

// getInitialState tries to load lastState from Store, and if it's not available it reads GenesisDoc.
Expand Down Expand Up @@ -242,16 +242,16 @@ func NewManager(
// allow buffer for the block header and protocol encoding
maxBlobSize -= blockProtocolOverhead

exec := state.NewBlockExecutor(proposerAddress, genesis.ChainID, mempool, mempoolReaper, proxyApp, eventBus, maxBlobSize, logger, execMetrics)
execClient := execution.NewABCIExecutionClient(proposerAddress, genesis.ChainID, mempool, mempoolReaper, proxyApp, eventBus, maxBlobSize, logger, execMetrics, store, genesis, &s)
if s.LastBlockHeight+1 == uint64(genesis.InitialHeight) { //nolint:gosec
res, err := exec.InitChain(genesis)
stateRoot, _, err := execClient.InitChain(genesis.GenesisTime, uint64(genesis.InitialHeight), genesis.ChainID)
if err != nil {
return nil, err
}
if err := updateState(&s, res); err != nil {
// TO-DO updateState needs to be decoupled from ABCI
if err := updateState(&s, stateRoot); err != nil {
return nil, err
}

if err := store.UpdateState(context.Background(), s); err != nil {
return nil, err
}
Expand All @@ -273,7 +273,6 @@ func NewManager(
genesis: genesis,
lastState: s,
store: store,
executor: exec,
dalc: dalc,
daHeight: s.DAHeight,
// channels are buffered to avoid blocking on input/output operations, buffer sizes are arbitrary
Expand All @@ -296,6 +295,7 @@ func NewManager(
isProposer: isProposer,
seqClient: seqClient,
bq: NewBatchQueue(),
execClient: execClient,
}
agg.init(context.Background())
return agg, nil
Expand Down Expand Up @@ -726,7 +726,7 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error {
hHeight := h.Height()
m.logger.Info("Syncing header and data", "height", hHeight)
// Validate the received block before applying
if err := m.executor.Validate(m.lastState, h, d); err != nil {
if err := m.execClient.Validate(m.lastState, h, d); err != nil {
return fmt.Errorf("failed to validate block: %w", err)
}
newState, responses, err := m.applyBlock(ctx, h, d)
Expand All @@ -741,7 +741,7 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error {
if err != nil {
return SaveBlockError{err}
}
_, _, err = m.executor.Commit(ctx, newState, h, d, responses)
_, _, err = m.execClient.Commit(ctx, newState, h, d, responses)
if err != nil {
return fmt.Errorf("failed to Commit: %w", err)
}
Expand Down Expand Up @@ -1141,7 +1141,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
LastDataHash: lastDataHash,
}
// Validate the created block before storing
if err := m.executor.Validate(m.lastState, header, data); err != nil {
if err := m.execClient.Validate(m.lastState, header, data); err != nil {
return fmt.Errorf("failed to validate block: %w", err)
}

Expand All @@ -1157,7 +1157,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
}

// Commit the new state and block which writes to disk on the proxy app
appHash, _, err := m.executor.Commit(ctx, newState, header, data, responses)
appHash, _, err := m.execClient.Commit(ctx, newState, header, data, responses)
if err != nil {
return err
}
Expand Down Expand Up @@ -1226,7 +1226,7 @@ func (m *Manager) processVoteExtension(ctx context.Context, header *types.Signed
return nil
}

extension, err := m.executor.ExtendVote(ctx, header, data)
extension, err := m.execClient.ExtendVote(ctx, header, data)
if err != nil {
return fmt.Errorf("error returned by ExtendVote: %w", err)
}
Expand Down Expand Up @@ -1426,25 +1426,47 @@ func (m *Manager) getLastBlockTime() time.Time {
func (m *Manager) createBlock(height uint64, lastSignature *types.Signature, lastHeaderHash types.Hash, extendedCommit abci.ExtendedCommitInfo, txs cmtypes.Txs, timestamp time.Time) (*types.SignedHeader, *types.Data, error) {
m.lastStateMtx.RLock()
defer m.lastStateMtx.RUnlock()
return m.executor.CreateBlock(height, lastSignature, extendedCommit, lastHeaderHash, m.lastState, txs, timestamp)
return m.execClient.CreateBlock(height, lastSignature, extendedCommit, lastHeaderHash, m.lastState, txs, timestamp)
}

func (m *Manager) applyBlock(ctx context.Context, header *types.SignedHeader, data *types.Data) (types.State, *abci.ResponseFinalizeBlock, error) {
m.lastStateMtx.RLock()
defer m.lastStateMtx.RUnlock()
return m.executor.ApplyBlock(ctx, m.lastState, header, data)
return m.execClient.ApplyBlock(ctx, m.lastState, header, data)
}

func updateState(s *types.State, res *abci.ResponseInitChain) error {
func updateState(s *types.State, stateRoot []byte) error {
initChainResponse := &abci.ResponseInitChain{
AppHash: stateRoot,
ConsensusParams: &cmproto.ConsensusParams{
Block: &cmproto.BlockParams{
MaxBytes: s.ConsensusParams.Block.MaxBytes,
MaxGas: s.ConsensusParams.Block.MaxGas,
},
Evidence: &cmproto.EvidenceParams{
MaxAgeNumBlocks: s.ConsensusParams.Evidence.MaxAgeNumBlocks,
MaxAgeDuration: s.ConsensusParams.Evidence.MaxAgeDuration,
MaxBytes: s.ConsensusParams.Evidence.MaxBytes,
},
Validator: &cmproto.ValidatorParams{
PubKeyTypes: s.ConsensusParams.Validator.PubKeyTypes,
},
Version: &cmproto.VersionParams{
App: s.ConsensusParams.Version.App,
},
},
Validators: cmtypes.TM2PB.ValidatorUpdates(s.Validators),
}

// If the app did not return an app hash, we keep the one set from the genesis doc in
// the state. We don't set appHash since we don't want the genesis doc app hash
// recorded in the genesis block. We should probably just remove GenesisDoc.AppHash.
if len(res.AppHash) > 0 {
s.AppHash = res.AppHash
if len(initChainResponse.AppHash) > 0 {
s.AppHash = initChainResponse.AppHash
}

if res.ConsensusParams != nil {
params := res.ConsensusParams
if initChainResponse.ConsensusParams != nil {
params := initChainResponse.ConsensusParams
if params.Block != nil {
s.ConsensusParams.Block.MaxBytes = params.Block.MaxBytes
s.ConsensusParams.Block.MaxGas = params.Block.MaxGas
Expand All @@ -1467,7 +1489,7 @@ func updateState(s *types.State, res *abci.ResponseInitChain) error {
// We update the last results hash with the empty hash, to conform with RFC-6962.
s.LastResultsHash = merkle.HashFromByteSlices(nil)

vals, err := cmtypes.PB2TM.ValidatorUpdates(res.Validators)
vals, err := cmtypes.PB2TM.ValidatorUpdates(initChainResponse.Validators)
if err != nil {
return err
}
Expand Down
41 changes: 23 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
module github.com/rollkit/rollkit

go 1.22
go 1.22.7

toolchain go1.22.2
toolchain go1.22.8

retract v0.12.0 // Published by accident

replace (
github.com/LastL2/go-execution => github.com/LastL2/go-execution v0.0.0-20241025044830-6028e95ddb3a
github.com/LastL2/go-execution-abci => github.com/LastL2/go-execution-abci v0.0.0-20241025051413-29b6d20dab76
)

require (
github.com/celestiaorg/utils v0.1.0
github.com/cometbft/cometbft v0.38.12
github.com/cometbft/cometbft v0.38.13
github.com/cosmos/gogoproto v1.7.0
github.com/go-kit/kit v0.13.0
github.com/gogo/protobuf v1.3.2
Expand Down Expand Up @@ -36,6 +41,7 @@ require (

require (
github.com/BurntSushi/toml v1.4.0
github.com/LastL2/go-execution-abci v0.0.0-00010101000000-000000000000
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/celestiaorg/go-header v0.6.2
github.com/ipfs/go-ds-badger4 v0.1.5
Expand All @@ -45,29 +51,28 @@ require (

require (
github.com/DataDog/zstd v1.4.5 // indirect
github.com/LastL2/go-execution v0.0.0-00010101000000-000000000000 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect
github.com/celestiaorg/go-libp2p-messenger v0.2.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.1 // indirect
github.com/cockroachdb/pebble v1.1.2 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft-db v0.11.0 // indirect
github.com/cometbft/cometbft-db v0.14.1 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/badger/v4 v4.2.1-0.20231013074411-fb1b00959581 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/elastic/gosigar v0.14.3 // indirect
Expand All @@ -85,8 +90,8 @@ require (
github.com/golang/glog v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gopacket v1.1.19 // indirect
Expand Down Expand Up @@ -114,7 +119,7 @@ require (
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
Expand All @@ -127,14 +132,14 @@ require (
github.com/libp2p/go-netroute v0.2.1 // indirect
github.com/libp2p/go-reuseport v0.4.0 // indirect
github.com/libp2p/go-yamux/v4 v4.0.1 // indirect
github.com/linxGnu/grocksdb v1.8.12 // indirect
github.com/linxGnu/grocksdb v1.8.14 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/miekg/dns v1.1.62 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/minio/highwayhash v1.0.3 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
Expand All @@ -153,7 +158,7 @@ require (
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
github.com/pion/datachannel v1.5.8 // indirect
github.com/pion/dtls/v2 v2.2.12 // indirect
github.com/pion/ice/v2 v2.3.34 // indirect
Expand All @@ -173,7 +178,7 @@ require (
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/common v0.59.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.46.0 // indirect
Expand All @@ -184,7 +189,7 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sasha-s/go-deadlock v0.3.5 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
Expand All @@ -195,7 +200,7 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/wlynxg/anet v0.0.4 // indirect
go.etcd.io/bbolt v1.3.10 // indirect
go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
Expand All @@ -212,7 +217,7 @@ require (
golang.org/x/text v0.18.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
gonum.org/v1/gonum v0.15.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading