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

Add Etna P-chain metrics #3458

Draft
wants to merge 11 commits into
base: implement-acp-77-logging
Choose a base branch
from
38 changes: 20 additions & 18 deletions vms/platformvm/block/executor/acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ func (a *acceptor) ApricotAtomicBlock(b *block.ApricotAtomicBlock) error {
blkID := b.ID()
defer a.free(blkID)

if err := a.commonAccept(b); err != nil {
return err
}

blkState, ok := a.blkIDToState[blkID]
if !ok {
return fmt.Errorf("%w %s", errMissingBlockState, blkID)
}

if err := a.commonAccept(blkState); err != nil {
return err
}

// Update the state to reflect the changes made in [onAcceptState].
if err := blkState.onAcceptState.Apply(a.state); err != nil {
return err
Expand Down Expand Up @@ -132,11 +132,7 @@ func (a *acceptor) optionBlock(b block.Block, blockType string) error {
}()

// Note that the parent must be accepted first.
if err := a.commonAccept(parentState.statelessBlock); err != nil {
return err
}

if err := a.commonAccept(b); err != nil {
if err := a.commonAccept(parentState); err != nil {
return err
}

Expand All @@ -150,6 +146,11 @@ func (a *acceptor) optionBlock(b block.Block, blockType string) error {
if !ok {
return fmt.Errorf("%w %s", errMissingBlockState, blkID)
}

if err := a.commonAccept(blkState); err != nil {
return err
}

if err := blkState.onAcceptState.Apply(a.state); err != nil {
return err
}
Expand Down Expand Up @@ -219,15 +220,15 @@ func (a *acceptor) standardBlock(b block.Block, blockType string) error {
blkID := b.ID()
defer a.free(blkID)

if err := a.commonAccept(b); err != nil {
return err
}

blkState, ok := a.blkIDToState[blkID]
if !ok {
return fmt.Errorf("%w %s", errMissingBlockState, blkID)
}

if err := a.commonAccept(blkState); err != nil {
return err
}

// Update the state to reflect the changes made in [onAcceptState].
if err := blkState.onAcceptState.Apply(a.state); err != nil {
return err
Expand Down Expand Up @@ -264,17 +265,18 @@ func (a *acceptor) standardBlock(b block.Block, blockType string) error {
return nil
}

func (a *acceptor) commonAccept(b block.Block) error {
blkID := b.ID()
func (a *acceptor) commonAccept(b *blockState) error {
blk := b.statelessBlock
blkID := blk.ID()

if err := a.metrics.MarkAccepted(b); err != nil {
if err := a.metrics.MarkAccepted(b.metrics); err != nil {
return fmt.Errorf("failed to accept block %s: %w", blkID, err)
}

a.backend.lastAccepted = blkID
a.state.SetLastAccepted(blkID)
a.state.SetHeight(b.Height())
a.state.AddStatelessBlock(b)
a.state.SetHeight(blk.Height())
a.state.AddStatelessBlock(blk)
a.validators.OnAcceptedBlockID(blkID)
return nil
}
46 changes: 21 additions & 25 deletions vms/platformvm/block/executor/acceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ func TestAcceptorVisitAtomicBlock(t *testing.T) {
)
require.NoError(err)

// Set expected calls on the state.
// We should error after [commonAccept] is called.
s.EXPECT().SetLastAccepted(blk.ID()).Times(1)
s.EXPECT().SetHeight(blk.Height()).Times(1)
s.EXPECT().AddStatelessBlock(blk).Times(1)

err = acceptor.ApricotAtomicBlock(blk)
require.ErrorIs(err, errMissingBlockState)

Expand All @@ -127,8 +121,12 @@ func TestAcceptorVisitAtomicBlock(t *testing.T) {
childID := ids.GenerateTestID()
atomicRequests := make(map[ids.ID]*atomic.Requests)
acceptor.backend.blkIDToState[blk.ID()] = &blockState{
statelessBlock: blk,
onAcceptState: onAcceptState,
atomicRequests: atomicRequests,
metrics: metrics.Block{
Block: blk,
},
}
// Give [blk] a child.
childOnAcceptState := state.NewMockDiff(ctrl)
Expand Down Expand Up @@ -196,12 +194,6 @@ func TestAcceptorVisitStandardBlock(t *testing.T) {
)
require.NoError(err)

// Set expected calls on the state.
// We should error after [commonAccept] is called.
s.EXPECT().SetLastAccepted(blk.ID()).Times(1)
s.EXPECT().SetHeight(blk.Height()).Times(1)
s.EXPECT().AddStatelessBlock(blk).Times(1)

err = acceptor.BanffStandardBlock(blk)
require.ErrorIs(err, errMissingBlockState)

Expand All @@ -211,12 +203,16 @@ func TestAcceptorVisitStandardBlock(t *testing.T) {
atomicRequests := make(map[ids.ID]*atomic.Requests)
calledOnAcceptFunc := false
acceptor.backend.blkIDToState[blk.ID()] = &blockState{
onAcceptState: onAcceptState,
statelessBlock: blk,
onAcceptState: onAcceptState,
onAcceptFunc: func() {
calledOnAcceptFunc = true
},

atomicRequests: atomicRequests,
metrics: metrics.Block{
Block: blk,
},
}
// Give [blk] a child.
childOnAcceptState := state.NewMockDiff(ctrl)
Expand Down Expand Up @@ -308,10 +304,6 @@ func TestAcceptorVisitCommitBlock(t *testing.T) {
parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1),
s.EXPECT().SetHeight(blk.Height()-1).Times(1),
s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1),

s.EXPECT().SetLastAccepted(blkID).Times(1),
s.EXPECT().SetHeight(blk.Height()).Times(1),
s.EXPECT().AddStatelessBlock(blk).Times(1),
)

err = acceptor.ApricotCommitBlock(blk)
Expand All @@ -322,12 +314,16 @@ func TestAcceptorVisitCommitBlock(t *testing.T) {
// Set [blk]'s state in the map as though it had been verified.
acceptor.backend.blkIDToState[parentID] = parentState
acceptor.backend.blkIDToState[blkID] = &blockState{
onAcceptState: parentState.onCommitState,
onAcceptFunc: parentState.onAcceptFunc,
statelessBlock: blk,
onAcceptState: parentState.onCommitState,
onAcceptFunc: parentState.onAcceptFunc,

inputs: parentState.inputs,
timestamp: parentOnCommitState.GetTimestamp(),
atomicRequests: parentState.atomicRequests,
metrics: metrics.Block{
Block: blk,
},
}

batch := databasemock.NewBatch(ctrl)
Expand Down Expand Up @@ -418,10 +414,6 @@ func TestAcceptorVisitAbortBlock(t *testing.T) {
parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1),
s.EXPECT().SetHeight(blk.Height()-1).Times(1),
s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1),

s.EXPECT().SetLastAccepted(blkID).Times(1),
s.EXPECT().SetHeight(blk.Height()).Times(1),
s.EXPECT().AddStatelessBlock(blk).Times(1),
)

err = acceptor.ApricotAbortBlock(blk)
Expand All @@ -432,12 +424,16 @@ func TestAcceptorVisitAbortBlock(t *testing.T) {
// Set [blk]'s state in the map as though it had been verified.
acceptor.backend.blkIDToState[parentID] = parentState
acceptor.backend.blkIDToState[blkID] = &blockState{
onAcceptState: parentState.onAbortState,
onAcceptFunc: parentState.onAcceptFunc,
statelessBlock: blk,
onAcceptState: parentState.onAbortState,
onAcceptFunc: parentState.onAcceptFunc,

inputs: parentState.inputs,
timestamp: parentOnAbortState.GetTimestamp(),
atomicRequests: parentState.atomicRequests,
metrics: metrics.Block{
Block: blk,
},
}

batch := databasemock.NewBatch(ctrl)
Expand Down
2 changes: 2 additions & 0 deletions vms/platformvm/block/executor/block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/vms/platformvm/block"
"github.com/ava-labs/avalanchego/vms/platformvm/metrics"
"github.com/ava-labs/avalanchego/vms/platformvm/state"
)

Expand All @@ -32,4 +33,5 @@ type blockState struct {
timestamp time.Time
atomicRequests map[ids.ID]*atomic.Requests
verifiedHeights set.Set[uint64]
metrics metrics.Block
}
Loading
Loading