Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add some metrics specifically around astria tx execution #40

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 12 additions & 2 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ var (
slotsGauge = metrics.NewRegisteredGauge("txpool/slots", nil)

reheapTimer = metrics.NewRegisteredTimer("txpool/reheap", nil)

// Metrics related to the astria ordered txs
astriaValidMeter = metrics.GetOrRegisterMeter("astria/txpool/valid", nil)
astriaParsedMeter = metrics.GetOrRegisterMeter("astria/txpool/parsed", nil)
astriaRequestedMeter = metrics.GetOrRegisterMeter("astria/txpool/requested", nil)
)

// BlockChain defines the minimal set of methods needed to back a tx pool with
Expand Down Expand Up @@ -281,6 +286,9 @@ type astriaOrdered struct {
}

func newAstriaOrdered(valid types.Transactions, parsed types.Transactions, pool *LegacyPool) *astriaOrdered {
astriaParsedMeter.Mark(int64(len(parsed)))
astriaValidMeter.Mark(int64(len(valid)))

return &astriaOrdered{
valid: valid,
parsed: parsed,
Expand All @@ -289,11 +297,13 @@ func newAstriaOrdered(valid types.Transactions, parsed types.Transactions, pool
}

func (ao *astriaOrdered) clear() {
ao.valid = *&types.Transactions{}
ao.parsed = *&types.Transactions{}
ao.valid = types.Transactions{}
ao.parsed = types.Transactions{}
}

func (pool *LegacyPool) SetAstriaOrdered(rawTxs [][]byte) {
astriaRequestedMeter.Mark(int64(len(rawTxs)))

valid := []*types.Transaction{}
parsed := []*types.Transaction{}
for idx, rawTx := range rawTxs {
Expand Down
2 changes: 2 additions & 0 deletions core/txpool/subpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,6 @@ type SubPool interface {
SetAstriaOrdered(rawTxs [][]byte)
ClearAstriaOrdered()
AstriaOrdered() *types.Transactions
AstriaOrderedTotalLen() int
AstriaOrderedValidLen() int
}
16 changes: 14 additions & 2 deletions grpc/execution/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"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"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/miner"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
Expand All @@ -37,6 +39,11 @@ type ExecutionServiceServerV1Alpha2 struct {
blockExecutionLock sync.Mutex // Lock for the NewPayload method
}

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

func NewExecutionServiceServerV1Alpha2(eth *eth.Ethereum) *ExecutionServiceServerV1Alpha2 {
bc := eth.BlockChain()

Expand Down Expand Up @@ -96,6 +103,9 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *

s.blockExecutionLock.Lock()
defer s.blockExecutionLock.Unlock()
// Deliberately called after lock, to more directly measure the time spent executing
executionStart := time.Now()
defer executeBlockTimer.UpdateSince(executionStart)

// Validate block being created has valid previous hash
prevHeadHash := common.BytesToHash(req.PrevBlockHash)
Expand Down Expand Up @@ -138,8 +148,8 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
s.eth.TxPool().ClearAstriaOrdered()

res := &astriaPb.Block{
Number: uint32(block.NumberU64()),
Hash: block.Hash().Bytes(),
Number: uint32(block.NumberU64()),
Hash: block.Hash().Bytes(),
ParentBlockHash: block.ParentHash().Bytes(),
Timestamp: &timestamppb.Timestamp{
Seconds: int64(block.Time()),
Expand Down Expand Up @@ -178,6 +188,8 @@ func (s *ExecutionServiceServerV1Alpha2) GetCommitmentState(ctx context.Context,
// CommitmentState.
func (s *ExecutionServiceServerV1Alpha2) UpdateCommitmentState(ctx context.Context, req *astriaPb.UpdateCommitmentStateRequest) (*astriaPb.CommitmentState, error) {
log.Info("UpdateCommitmentState called", "request", req)
commitmentUpdateStart := time.Now()
defer comittmentStateUpdateTimer.UpdateSince(commitmentUpdateStart)

s.commitementUpdateLock.Lock()
defer s.commitementUpdateLock.Unlock()
Expand Down
Loading