Skip to content

Commit

Permalink
Merge pull request #41 from astriaorg/joroshiba/genesis-info
Browse files Browse the repository at this point in the history
feat: implement new genesis endpoint
  • Loading branch information
joroshiba authored Feb 13, 2024
2 parents 75206fb + e6a601c commit af9f7e4
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"strings"
"time"

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"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/ethereum/go-ethereum
go 1.21

require (
buf.build/gen/go/astria/astria/grpc/go v1.3.0-20231213194648-0685137780d3.2
buf.build/gen/go/astria/astria/protocolbuffers/go v1.31.0-20231213194648-0685137780d3.2
buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240209225522-97e3bc68f856.2
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.32.0-20240209225522-97e3bc68f856.1
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0
github.com/Microsoft/go-winio v0.6.1
github.com/VictoriaMetrics/fastcache v1.12.1
Expand Down Expand Up @@ -73,7 +73,7 @@ require (
golang.org/x/time v0.3.0
golang.org/x/tools v0.13.0
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.31.0
google.golang.org/protobuf v1.32.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down
38 changes: 7 additions & 31 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
buf.build/gen/go/astria/astria/grpc/go v1.3.0-20231213194648-0685137780d3.2 h1:BjTKxda1u3xdJXS1LYA5R0OfT46bZp5ji+1yg7/JQHQ=
buf.build/gen/go/astria/astria/grpc/go v1.3.0-20231213194648-0685137780d3.2/go.mod h1:sDLOOS2EuERVuqV4+gpqjYjq65+Ebb+SIt5Dxics7wQ=
buf.build/gen/go/astria/astria/protocolbuffers/go v1.28.1-20231213194648-0685137780d3.4/go.mod h1:a2nDGgMECtFWAbBm06prW70xA/jP8X44wz9jpii2cxo=
buf.build/gen/go/astria/astria/protocolbuffers/go v1.31.0-20231213194648-0685137780d3.2 h1:F4Ogo0F7A19d90esHhjYuPVrvQejwLkIMLpDDDYlDrk=
buf.build/gen/go/astria/astria/protocolbuffers/go v1.31.0-20231213194648-0685137780d3.2/go.mod h1:OPKBvxqrsHTBen+bbkQT/beHK/aSznSulzR+JeDSUKw=
buf.build/gen/go/cosmos/cosmos-proto/grpc/go v1.3.0-20211202220400-1935555c206d.2/go.mod h1:AS+jUupCTrSz+T88+ZsW4cOQwkYftIjjMzqXoK0hp3k=
buf.build/gen/go/cosmos/cosmos-proto/protocolbuffers/go v1.28.1-20211202220400-1935555c206d.4/go.mod h1:eLpHyQeVRAtShjbHVpIla0w/42RZAdaaTpBErMv/6sc=
buf.build/gen/go/cosmos/cosmos-proto/protocolbuffers/go v1.31.0-20211202220400-1935555c206d.2/go.mod h1:yHKMbegvhfMbDGsQp/q7tECJTfZf0wrgTRcH1glgEQk=
buf.build/gen/go/cosmos/cosmos-sdk/grpc/go v1.3.0-20230522115704-e7a85cef453e.2/go.mod h1:cZOEXwhGC2HYgN4DJvbdZNEWGnghUlN7ZwkyJKKqw/g=
buf.build/gen/go/cosmos/cosmos-sdk/grpc/go v1.3.0-20230719110346-aa25660f4ff7.2/go.mod h1:u82E8x7rLqs3igb0i4Ul1fFwx384I7oJnmn4FmclOTw=
buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.28.1-20230522115704-e7a85cef453e.4/go.mod h1:WwWRz97saFM8fwl9UcqhFzQOvN+8QkZwa4AAL37pqaA=
buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.28.1-20230719110346-aa25660f4ff7.4/go.mod h1:RFHPh4mUMobZH69MX2BCwzRVG+JNUfAp9J2fIiYylcA=
buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.31.0-20230522115704-e7a85cef453e.2/go.mod h1:d16Ahcn3H831Oe+NnNOWuXkV3aTiPOBZvUAZaHYECkU=
buf.build/gen/go/cosmos/cosmos-sdk/protocolbuffers/go v1.31.0-20230719110346-aa25660f4ff7.2/go.mod h1:vg3BLbBJ3Vl9Wu7GE6BmxYq1+VMU4Yg8cv9YG7qF2AQ=
buf.build/gen/go/cosmos/gogo-proto/grpc/go v1.3.0-20221020125208-34d970b699f8.2/go.mod h1:PKPJRNiORF0FABGYEXbc1iTG+rzNA/4JUfDGkaFPskA=
buf.build/gen/go/cosmos/gogo-proto/grpc/go v1.3.0-20230509103710-5e5b9fdd0180.2/go.mod h1:VLlOf39tq7bgN9oEwG9ElFuzSHlDRrlp6be0GQW9oCw=
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.28.1-20221020125208-34d970b699f8.4/go.mod h1:yABYnsmLNsRsuOb4SD5Xr511HUTzjhrc5KD1nFHIiNs=
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.28.1-20230509103710-5e5b9fdd0180.4/go.mod h1:yABYnsmLNsRsuOb4SD5Xr511HUTzjhrc5KD1nFHIiNs=
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.31.0-20221020125208-34d970b699f8.2/go.mod h1:rTzewyj2LANV2IIuGZnKMsvbIEVAguDwBvMdxD1pa3k=
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.31.0-20230509103710-5e5b9fdd0180.2/go.mod h1:rTzewyj2LANV2IIuGZnKMsvbIEVAguDwBvMdxD1pa3k=
buf.build/gen/go/cosmos/ibc/grpc/go v1.3.0-20230913112312-7ab44ae956a0.2/go.mod h1:BO30VkuVfhMtQHD6CSpVR2Q646XCJuwlrTp/OkgJxYg=
buf.build/gen/go/cosmos/ibc/protocolbuffers/go v1.28.1-20230913112312-7ab44ae956a0.4/go.mod h1:0kwZox/T/DuD4YiSHSn76mEPEFraCnaWwdkuhHrcr/s=
buf.build/gen/go/cosmos/ibc/protocolbuffers/go v1.31.0-20230913112312-7ab44ae956a0.2/go.mod h1:piKWSxT4f990Ium90hWQnNwuqxhsoYxhPtZYcOz2vNs=
buf.build/gen/go/cosmos/ics23/grpc/go v1.3.0-20221207100654-55085f7c710a.2/go.mod h1:gUin8BTHrs/dRa0bdSHBb0twUODf4pUk4R9tPhOsPmc=
buf.build/gen/go/cosmos/ics23/protocolbuffers/go v1.28.1-20221207100654-55085f7c710a.4/go.mod h1:bASIBnznZv/r+XmEKQvGR5+1D+VkRjQG3K0mtlNL4l0=
buf.build/gen/go/cosmos/ics23/protocolbuffers/go v1.31.0-20221207100654-55085f7c710a.2/go.mod h1:1V7tFOxP2P2x8G0oasO+VqSHN0Bhly5I/e+2vENGomQ=
buf.build/gen/go/penumbra-zone/penumbra/grpc/go v1.3.0-20231120132728-bc443669626d.2/go.mod h1:f02cXVjnFw1swHvdrTWUfuH29d4UEl7mgVUg581vtXU=
buf.build/gen/go/penumbra-zone/penumbra/protocolbuffers/go v1.28.1-20231120132728-bc443669626d.4/go.mod h1:mbqAF6Y8Bzzf8D+vY21ktscpxes7AusdpvIW/slzsdI=
buf.build/gen/go/penumbra-zone/penumbra/protocolbuffers/go v1.31.0-20231120132728-bc443669626d.2/go.mod h1:h82VMeit0Ae3VmGvS6QH6yJx9GPHM3y4y0x1JU3Vyyc=
buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240209225522-97e3bc68f856.2 h1:mK0jVG2+QlJrPKsgL46KKh2ZqHc8lyexQP3TUcOvvNU=
buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240209225522-97e3bc68f856.2/go.mod h1:soA8k5qokjmp9DmV6jdcWndlVdSYjfa8KJZgsJrvixc=
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.28.1-20240209225522-97e3bc68f856.4/go.mod h1:5wxRDkWimPnuhDUA4pFBaHMtrViNJAHguLU1Wq8T6x8=
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.32.0-20240209225522-97e3bc68f856.1 h1:6iyjwuNE2uuRikxiDVr56RvDJ+OE3g32v1V1zk5yIjI=
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.32.0-20240209225522-97e3bc68f856.1/go.mod h1:m409hJcO0kExqrFoQS8fQ7yXHuuM8JRTEYB+09WWVy0=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
Expand Down Expand Up @@ -1679,8 +1655,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
57 changes: 53 additions & 4 deletions grpc/execution/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ package execution

import (
"context"
"crypto/sha256"
"fmt"
"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"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
Expand Down Expand Up @@ -40,8 +41,25 @@ type ExecutionServiceServerV1Alpha2 struct {
}

var (
getGenesisInfoRequestCount = metrics.GetOrRegisterCounter("astria/execution/get_genesis_info_requests", nil)
getGenesisInfoSuccessCount = metrics.GetOrRegisterCounter("astria/execution/get_genesis_info_success", nil)
getBlockRequestCount = metrics.GetOrRegisterCounter("astria/execution/get_block_requests", nil)
getBlockSuccessCount = metrics.GetOrRegisterCounter("astria/execution/get_block_success", nil)
batchGetBlockRequestCount = metrics.GetOrRegisterCounter("astria/execution/batch_get_block_requests", nil)
batchGetBlockSuccessCount = metrics.GetOrRegisterCounter("astria/execution/batch_get_block_success", nil)
executeBlockRequestCount = metrics.GetOrRegisterCounter("astria/execution/execute_block_requests", nil)
executeBlockSuccessCount = metrics.GetOrRegisterCounter("astria/execution/execute_block_success", nil)
getCommitmentStateRequestCount = metrics.GetOrRegisterCounter("astria/execution/get_commitment_state_requests", nil)
getCommitmentStateSuccessCount = metrics.GetOrRegisterCounter("astria/execution/get_commitment_state_success", nil)
updateCommitmentStateRequestCount = metrics.GetOrRegisterCounter("astria/execution/update_commitment_state_requests", nil)
updateCommitmentStateSuccessCount = metrics.GetOrRegisterCounter("astria/execution/update_commitment_state_success", nil)

softCommitmentHeight = metrics.GetOrRegisterGauge("astria/execution/soft_commitment_height", nil)
firmCommitmentHeight = metrics.GetOrRegisterGauge("astria/execution/firm_commitment_height", nil)
totalExecutedTxCount = metrics.GetOrRegisterCounter("astria/execution/total_executed_tx", nil)

executeBlockTimer = metrics.GetOrRegisterTimer("astria/execution/execute_block_time", nil)
comittmentStateUpdateTimer = metrics.GetOrRegisterTimer("astria/execution/committment_state_update_time", nil)
commitmentStateUpdateTimer = metrics.GetOrRegisterTimer("astria/execution/commitment", nil)
)

func NewExecutionServiceServerV1Alpha2(eth *eth.Ethereum) *ExecutionServiceServerV1Alpha2 {
Expand All @@ -57,9 +75,28 @@ func NewExecutionServiceServerV1Alpha2(eth *eth.Ethereum) *ExecutionServiceServe
}
}

func (s *ExecutionServiceServerV1Alpha2) GetGenesisInfo(ctx context.Context, req *astriaPb.GetGenesisInfoRequest) (*astriaPb.GenesisInfo, error) {
log.Info("GetGenesisInfo called", "request", req)
getGenesisInfoRequestCount.Inc(1)

rollupId := sha256.Sum256([]byte(s.bc.Config().AstriaRollupName))

res := &astriaPb.GenesisInfo{
RollupId: rollupId[:],
SequencerGenesisBlockHeight: s.bc.Config().AstriaSequencerInitialHeight,
CelestiaBaseBlockHeight: s.bc.Config().AstriaCelestiaInitialHeight,
CelestiaBlockVariance: s.bc.Config().AstriaCelestiaHeightVariance,
}

log.Info("GetGenesisInfo completed", "response", res)
getGenesisInfoSuccessCount.Inc(1)
return res, nil
}

// GetBlock will return a block given an identifier.
func (s *ExecutionServiceServerV1Alpha2) GetBlock(ctx context.Context, req *astriaPb.GetBlockRequest) (*astriaPb.Block, error) {
log.Info("GetBlock called", "request", req)
getBlockRequestCount.Inc(1)

res, err := s.getBlockFromIdentifier(req.GetIdentifier())
if err != nil {
Expand All @@ -68,13 +105,15 @@ func (s *ExecutionServiceServerV1Alpha2) GetBlock(ctx context.Context, req *astr
}

log.Info("GetBlock completed", "request", req, "response", res)
getBlockSuccessCount.Inc(1)
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) {
log.Info("BatchGetBlocks called", "request", req)
batchGetBlockRequestCount.Inc(1)
var blocks []*astriaPb.Block

ids := req.GetIdentifiers()
Expand All @@ -93,13 +132,15 @@ func (s *ExecutionServiceServerV1Alpha2) BatchGetBlocks(ctx context.Context, req
}

log.Info("BatchGetBlocks completed", "request", req, "response", res)
batchGetBlockSuccessCount.Inc(1)
return res, nil
}

// ExecuteBlock drives deterministic derivation of a rollup block from sequencer
// block data
func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *astriaPb.ExecuteBlockRequest) (*astriaPb.Block, error) {
log.Info("ExecuteBlock called", "request", req)
executeBlockRequestCount.Inc(1)

s.blockExecutionLock.Lock()
defer s.blockExecutionLock.Unlock()
Expand Down Expand Up @@ -157,12 +198,15 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
}

log.Info("ExecuteBlock completed", "request", req, "response", res)
totalExecutedTxCount.Inc(int64(len(block.Transactions())))
executeBlockSuccessCount.Inc(1)
return res, nil
}

// GetCommitmentState fetches the current CommitmentState of the chain.
func (s *ExecutionServiceServerV1Alpha2) GetCommitmentState(ctx context.Context, req *astriaPb.GetCommitmentStateRequest) (*astriaPb.CommitmentState, error) {
log.Info("GetCommitmentState called", "request", req)
getCommitmentStateRequestCount.Inc(1)

softBlock, err := ethHeaderToExecutionBlock(s.bc.CurrentSafeBlock())
if err != nil {
Expand All @@ -181,15 +225,17 @@ func (s *ExecutionServiceServerV1Alpha2) GetCommitmentState(ctx context.Context,
}

log.Info("GetCommitmentState completed", "request", req, "response", res)
getCommitmentStateSuccessCount.Inc(1)
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) {
log.Info("UpdateCommitmentState called", "request", req)
updateCommitmentStateRequestCount.Inc(1)
commitmentUpdateStart := time.Now()
defer comittmentStateUpdateTimer.UpdateSince(commitmentUpdateStart)
defer commitmentStateUpdateTimer.UpdateSince(commitmentUpdateStart)

s.commitementUpdateLock.Lock()
defer s.commitementUpdateLock.Unlock()
Expand Down Expand Up @@ -244,6 +290,9 @@ func (s *ExecutionServiceServerV1Alpha2) UpdateCommitmentState(ctx context.Conte
}

log.Info("UpdateCommitmentState completed", "request", req)
softCommitmentHeight.Update(int64(softBlock.NumberU64()))
firmCommitmentHeight.Update(int64(firmBlock.NumberU64()))
updateCommitmentStateSuccessCount.Inc(1)
return req.CommitmentState, nil
}

Expand Down
2 changes: 1 addition & 1 deletion node/grpcstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,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"
"github.com/ethereum/go-ethereum/log"
"google.golang.org/grpc"
)
Expand Down
16 changes: 9 additions & 7 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,12 @@ type ChainConfig struct {
IsDevMode bool `json:"isDev,omitempty"`

// Astria Specific Configuration
AstriaOverrideGenesisExtraData bool `json:"astriaOverrideGenesisExtraData,omitempty"`
AstriaExtraDataOverride hexutil.Bytes `json:"astriaExtraDataOverride,omitempty"`
AstriaSequencerInitialHeight *big.Int `json:"astriaDequencerInitialHeight,omitempty"`
AstriaDataAvailabilityInitialHeight *big.Int `json:"astriaDataAvailabilityInitialHeight,omitempty"`
AstriaDataAvailabilityHeightVariance *big.Int `json:"astriaDataAvailabilityHeightVariance,omitempty"`
AstriaOverrideGenesisExtraData bool `json:"astriaOverrideGenesisExtraData,omitempty"`
AstriaExtraDataOverride hexutil.Bytes `json:"astriaExtraDataOverride,omitempty"`
AstriaRollupName string `json:"astriaRollupName,omitempty"`
AstriaSequencerInitialHeight uint32 `json:"astriaSequencerInitialHeight"`
AstriaCelestiaInitialHeight uint32 `json:"astriaCelestiaInitialHeight"`
AstriaCelestiaHeightVariance uint32 `json:"astriaCelestiaHeightVariance,omitempty"`
}

func (c *ChainConfig) AstriaExtraData() []byte {
Expand All @@ -351,9 +352,10 @@ func (c *ChainConfig) AstriaExtraData() []byte {

// create default extradata
extra, _ := rlp.EncodeToBytes([]interface{}{
c.AstriaRollupName,
c.AstriaSequencerInitialHeight,
c.AstriaDataAvailabilityInitialHeight,
c.AstriaDataAvailabilityHeightVariance,
c.AstriaCelestiaInitialHeight,
c.AstriaCelestiaHeightVariance,
})
if uint64(len(extra)) > MaximumExtraDataSize {
log.Warn("Miner extra data exceed limit", "extra", hexutil.Bytes(extra), "limit", MaximumExtraDataSize)
Expand Down

0 comments on commit af9f7e4

Please sign in to comment.