Skip to content

Commit

Permalink
latest wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mycodecrafting committed Feb 8, 2024
1 parent b618beb commit 5e3467c
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 969 deletions.
2 changes: 1 addition & 1 deletion astria/execution/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net"
"sync"

astriaGrpc "buf.build/gen/go/astria/astria/grpc/go/astria/execution/v1alpha2/executionv1alpha2grpc"
astriaGrpc "buf.build/gen/go/astria/execution-apis/grpc/go/astria/execution/v1alpha2/executionv1alpha2grpc"
"google.golang.org/grpc"
)

Expand Down
86 changes: 72 additions & 14 deletions astria/execution/v1alpha2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package execution
import (
"context"
"sync"
"time"

astriaGrpc "buf.build/gen/go/astria/astria/grpc/go/astria/execution/v1alpha2/executionv1alpha2grpc"
astriaPb "buf.build/gen/go/astria/astria/protocolbuffers/go/astria/execution/v1alpha2"
astriaGrpc "buf.build/gen/go/astria/execution-apis/grpc/go/astria/execution/v1alpha2/executionv1alpha2grpc"
astriaPb "buf.build/gen/go/astria/execution-apis/protocolbuffers/go/astria/execution/v1alpha2"
cmbytes "github.com/cometbft/cometbft/libs/bytes"
"github.com/cometbft/cometbft/libs/log"
"github.com/rollkit/rollkit/block"
"github.com/rollkit/rollkit/store"
"github.com/rollkit/rollkit/types"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/timestamppb"
)

Expand All @@ -37,21 +39,25 @@ func NewExecutionServiceServerV1Alpha2(blockManager *block.SSManager, store stor

// GetBlock retrieves a block by its identifier.
func (s *ExecutionServiceServerV1Alpha2) GetBlock(ctx context.Context, req *astriaPb.GetBlockRequest) (*astriaPb.Block, error) {
s.logger.Info("GetBlock called", "request", req)
reqJson, _ := protojson.Marshal(req)
s.logger.Info("GetBlock called", "request", reqJson)

res, err := s.getBlockFromIdentifier(ctx, req.GetIdentifier())
if err != nil {
s.logger.Error("failed finding block", err)
return nil, err
}

s.logger.Info("GetBlock completed", "request", req, "response", res)
resJson, _ := protojson.Marshal(res)
s.logger.Info("GetBlock completed", "response", resJson)
return res, nil
}

// BatchGetBlocks will return an array of Blocks given an array of block identifiers.
func (s *ExecutionServiceServerV1Alpha2) BatchGetBlocks(ctx context.Context, req *astriaPb.BatchGetBlocksRequest) (*astriaPb.BatchGetBlocksResponse, error) {
s.logger.Info("BatchGetBlocks called", "request", req)
reqJson, _ := protojson.Marshal(req)
s.logger.Info("BatchGetBlocks called", "request", reqJson)

var blocks []*astriaPb.Block

ids := req.GetIdentifiers()
Expand All @@ -69,7 +75,8 @@ func (s *ExecutionServiceServerV1Alpha2) BatchGetBlocks(ctx context.Context, req
Blocks: blocks,
}

s.logger.Info("BatchGetBlocks completed", "request", req, "response", res)
resJson, _ := protojson.Marshal(res)
s.logger.Info("BatchGetBlocks completed", "response", resJson)
return res, nil
}

Expand All @@ -81,7 +88,8 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
default:
}

s.logger.Info("ExecuteBlock called", "request", req)
reqJson, _ := protojson.Marshal(req)
s.logger.Info("ExecuteBlock called", "request", reqJson)

s.blockExecutionLock.Lock()
defer s.blockExecutionLock.Unlock()
Expand All @@ -93,31 +101,81 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *

block, err := s.blockManager.PublishBlock(ctx, types.Hash(req.PrevBlockHash), req.Timestamp.AsTime(), txs)
if err != nil {
s.logger.Error("failed to publish block to chain", "hash", block.Hash(), "prevHash", req.PrevBlockHash, "err", err)
s.logger.Error("Failed to publish block to chain", "hash", block.Hash(), "prevHash", types.Hash(req.PrevBlockHash), "err", err)
return nil, status.Error(codes.Internal, "failed to insert block to chain")
}

s.logger.Info("Published block", "height", block.Height(), "timestamp", block.Time(), "hash", block.Hash(), "parent_hash", block.LastHeader())

parentHash := block.LastHeader()
if block.Height() == 1 {
zeroHash := [32]byte{0x0}
parentHash = types.Hash(zeroHash[:])
}

res := &astriaPb.Block{
Number: uint32(block.Height()),
Hash: cmbytes.HexBytes(block.Hash()),
ParentBlockHash: cmbytes.HexBytes(block.LastHeader()),
ParentBlockHash: cmbytes.HexBytes(parentHash),
Timestamp: timestamppb.New(block.Time()),
}

s.logger.Info("ExecuteBlock completed", "request", req, "response", res)
resJson, _ := protojson.Marshal(res)
s.logger.Info("ExecuteBlock completed", "response", resJson)
return res, nil
}

// GetCommitmentState fetches the current CommitmentState of the chain.
func (s *ExecutionServiceServerV1Alpha2) GetCommitmentState(ctx context.Context, req *astriaPb.GetCommitmentStateRequest) (*astriaPb.CommitmentState, error) {
s.logger.Info("GetCommitmentState called", "request", req)
return nil, nil
reqJson, _ := protojson.Marshal(req)
s.logger.Info("GetCommitmentState called", "request", reqJson)

var res *astriaPb.CommitmentState

height := s.blockManager.GetStoreHeight()

if height == 0 {
genHash := [32]byte{0x0}
pbGenBlock := &astriaPb.Block{
Number: uint32(0),
Hash: genHash[:],
ParentBlockHash: genHash[:],
Timestamp: timestamppb.New(time.Now()),
}
res = &astriaPb.CommitmentState{
Soft: pbGenBlock,
Firm: pbGenBlock,
}
} else {
block, err := s.store.GetBlock(ctx, height)
if err != nil {
s.logger.Error("failed finding block with height", "height", height, "error", err)
return nil, err
}

pbBlock := &astriaPb.Block{
Number: uint32(block.Height()),
Hash: cmbytes.HexBytes(block.Hash()),
ParentBlockHash: cmbytes.HexBytes(block.LastHeader()),
Timestamp: timestamppb.New(block.Time()),
}

res = &astriaPb.CommitmentState{
Soft: pbBlock,
Firm: pbBlock,
}
}

resJson, _ := protojson.Marshal(res)
s.logger.Info("GetCommitmentState completed", "response", resJson)
return res, nil
}

// UpdateCommitmentState replaces the whole CommitmentState with a new CommitmentState.
func (s *ExecutionServiceServerV1Alpha2) UpdateCommitmentState(ctx context.Context, req *astriaPb.UpdateCommitmentStateRequest) (*astriaPb.CommitmentState, error) {
s.logger.Info("UpdateCommitmentState called", "request", req)
return nil, nil
reqJson, _ := protojson.Marshal(req)
s.logger.Info("UpdateCommitmentState called", "request", reqJson)
return req.CommitmentState, nil
}

func (s *ExecutionServiceServerV1Alpha2) getBlockFromIdentifier(ctx context.Context, identifier *astriaPb.BlockIdentifier) (*astriaPb.Block, error) {
Expand Down
29 changes: 9 additions & 20 deletions astria/mempool/reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ import (
"fmt"
"sync"

"github.com/rollkit/rollkit/mempool"
"github.com/rollkit/rollkit/types"

"github.com/cometbft/cometbft/libs/log"
"github.com/rollkit/rollkit/astria/sequencer"
"github.com/rollkit/rollkit/mempool"
)

type MempoolReaper struct {
c *sequencer.Client
mempool *mempool.CListMempool
logger log.Logger

mu sync.Mutex
started bool
stopCh chan struct{}
}

func NewMempoolReaper(client *sequencer.Client, mempool *mempool.CListMempool) *MempoolReaper {
func NewMempoolReaper(client *sequencer.Client, mempool *mempool.CListMempool, logger log.Logger) *MempoolReaper {
return &MempoolReaper{
c: client,
mempool: mempool,
logger: logger,
started: false,
stopCh: make(chan struct{}),
}
Expand All @@ -47,10 +48,12 @@ func (mr *MempoolReaper) Reap() {
case <-mr.stopCh:
return
default:
mempoolTx := tx0.Value.(*mempoolTx)
mempoolTx := tx0.Value.(*mempool.MempoolTx)

mr.logger.Info("reaped tx from mempool", "tx", mempoolTx.Tx())

// submit to shared sequencer
res, err := mr.c.BroadcastTx(mempoolTx.tx)
res, err := mr.c.BroadcastTx(mempoolTx.Tx())
if err != nil {
panic(fmt.Sprintf("error sending message: %s\n", err))
}
Expand Down Expand Up @@ -95,17 +98,3 @@ func (mr *MempoolReaper) Stop() error {
mr.started = false
return nil
}

// copied from rollkit clist_mempool.go
//--------------------------------------------------------------------------------

// mempoolTx is a transaction that successfully ran
type mempoolTx struct {
height uint64 // height that this tx had been validated in
gasWanted int64 // amount of gas this tx states it will require
tx types.Tx //

// ids of peers who've sent us this tx (as a map for quick lookups).
// senders: PeerID -> bool
senders sync.Map
}
4 changes: 3 additions & 1 deletion astria/sequencer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
astriaPb "buf.build/gen/go/astria/astria/protocolbuffers/go/astria/sequencer/v1alpha1"
"github.com/astriaorg/go-sequencer-client/client"
tendermintPb "github.com/cometbft/cometbft/rpc/core/types"
"google.golang.org/protobuf/encoding/protojson"
)

// SequencerClient is a client for interacting with the sequencer.
Expand Down Expand Up @@ -51,7 +52,8 @@ func (c *Client) BroadcastTx(tx []byte) (*tendermintPb.ResultBroadcastTx, error)
return nil, err
}

fmt.Printf("submitting tx to sequencer: %s\n", tx)
signedJson, _ := protojson.Marshal(signed)
fmt.Printf("submitting tx to sequencer: %s\n", signedJson)

resp, err := c.Client.BroadcastTxSync(context.Background(), signed)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions block/ss_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func NewSSManager(

exec := state.NewBlockExecutor(proposerAddress, genesis.ChainID, mempool, proxyApp, eventBus, logger, execMetrics)
if s.LastBlockHeight+1 == uint64(genesis.InitialHeight) {
logger.Info("Initializing chain")
res, err := exec.InitChain(genesis)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (
DefaultListenAddress = "/ip4/0.0.0.0/tcp/7676"
// Version is the current rollkit version
// Please keep updated with each new release
Version = "0.12.0"
Version = "0.13.0"
)

// DefaultNodeConfig keeps default values of NodeConfig
Expand Down
14 changes: 4 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,15 @@ require (
)

require (
buf.build/gen/go/astria/astria/protocolbuffers/go v1.32.0-20240208041217-cec081a8099b.1
buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240207231045-2f6384a93a8d.2
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.32.0-20240207231045-2f6384a93a8d.1
github.com/astriaorg/go-sequencer-client v0.0.0-20231201013457-0df599de8e74
github.com/celestiaorg/go-header v0.5.2
github.com/ipfs/go-ds-badger4 v0.1.5
)

require (
buf.build/gen/go/astria/astria/grpc/go v1.3.0-20240207143250-56389ebbf26d.2 // indirect
buf.build/gen/go/astria/astria/protocolbuffers/go v1.31.0-20231130012811-2fd7e6d46ebd.2 // indirect
buf.build/gen/go/cosmos/cosmos-proto/protocolbuffers/go v1.31.0-20211202220400-1935555c206d.2 // indirect
buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.31.0-20230719110346-aa25660f4ff7.2 // indirect
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.31.0-20230509103710-5e5b9fdd0180.2 // indirect
buf.build/gen/go/cosmos/ibc/protocolbuffers/go v1.31.0-20230913112312-7ab44ae956a0.2 // indirect
buf.build/gen/go/penumbra-zone/penumbra/protocolbuffers/go v1.31.0-20231120132728-bc443669626d.2 // indirect
github.com/astriaorg/go-sequencer-client v0.0.0-20231201013457-0df599de8e74 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
Expand Down Expand Up @@ -184,8 +180,6 @@ require (
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.0 // indirect
gonum.org/v1/gonum v0.12.0 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 5e3467c

Please sign in to comment.