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 a metrics gauge for built block slot #3048

Merged
merged 36 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c1182a5
initial version.
tsachiherman May 23, 2024
86da9b1
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman May 23, 2024
8765910
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman May 28, 2024
453fa82
prepare.
tsachiherman May 31, 2024
2080759
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman May 31, 2024
88db71e
update
tsachiherman May 31, 2024
ecf3f90
update
tsachiherman Jun 3, 2024
2b68605
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman Jun 3, 2024
d9cad44
rename
tsachiherman Jun 3, 2024
3747e86
rollback unwanted changes.
tsachiherman Jun 3, 2024
6d5cccd
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman Jun 3, 2024
c3c03c6
update per cr
tsachiherman Jun 4, 2024
af7b92c
update per CR.
tsachiherman Jun 4, 2024
83639ed
update per cr
tsachiherman Jun 4, 2024
2a885a2
update pr
tsachiherman Jun 4, 2024
3c17ddb
rollback unwanted changes.
tsachiherman Jun 4, 2024
ac28f28
fix regression in unit test.
tsachiherman Jun 4, 2024
289e2c9
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman Jun 4, 2024
e62aa39
make linter happy.
tsachiherman Jun 4, 2024
198e77b
fix proposerBuildSlotGauge.Set in case we're not the next proposer wi…
tsachiherman Jun 5, 2024
5c5804b
Update vms/proposervm/block.go
tsachiherman Jun 6, 2024
fa47a7c
Update vms/proposervm/post_fork_block.go
tsachiherman Jun 6, 2024
8feb86c
Update vms/proposervm/vm.go
tsachiherman Jun 6, 2024
6562348
Update vms/proposervm/vm.go
tsachiherman Jun 6, 2024
24c9fc6
Update vms/proposervm/vm.go
tsachiherman Jun 6, 2024
f77c4fd
Update vms/proposervm/vm.go
tsachiherman Jun 6, 2024
65aa579
Update vms/proposervm/vm.go
tsachiherman Jun 6, 2024
8d8480a
Update vms/proposervm/block.go
tsachiherman Jun 6, 2024
ebfe48b
make nicer
tsachiherman Jun 6, 2024
d2c6045
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman Jun 6, 2024
bd2d17d
update
tsachiherman Jun 6, 2024
46d1eeb
Merge branch 'master' into tsachi/report-proposer-slot
tsachiherman Jun 6, 2024
8da20a6
reduce diff
StephenButtolph Jun 6, 2024
10af2bb
Merge branch 'master' into tsachi/report-proposer-slot
StephenButtolph Jun 6, 2024
bb2309b
fix merge
StephenButtolph Jun 6, 2024
72ffa86
fix merge again
StephenButtolph Jun 6, 2024
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
2 changes: 2 additions & 0 deletions vms/proposervm/batched_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (vm *VM) BatchedParseBlock(ctx context.Context, blks [][]byte) ([]snowman.B
vm: vm,
innerBlk: innerBlks[innerBlocksIndex],
status: status,
slot: unspecifiedSlotIndex,
},
}
} else {
Expand All @@ -154,6 +155,7 @@ func (vm *VM) BatchedParseBlock(ctx context.Context, blks [][]byte) ([]snowman.B
vm: vm,
innerBlk: innerBlks[innerBlocksIndex],
status: status,
slot: unspecifiedSlotIndex,
},
}
}
Expand Down
25 changes: 22 additions & 3 deletions vms/proposervm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
const (
// allowable block issuance in the future
maxSkew = 10 * time.Second

// unspecifiedSlotIndex defines the default value being used for a proposal slot index, prior of being populated
// by the actual slot index. Given that the slot index is zero base, we would want to use an "invalid" value as
// non-zero.
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
unspecifiedSlotIndex = ^uint64(0)
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
)

var (
Expand Down Expand Up @@ -75,6 +80,9 @@ type postForkCommonComponents struct {
vm *VM
innerBlk snowman.Block
status choices.Status
// slot is used to store the selected slot for this block. It's being used during Accept, and populated
// during verifyPostDurangoBlockDelay.
slot uint64
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
}

// Return the inner block's height
Expand Down Expand Up @@ -269,6 +277,7 @@ func (p *postForkCommonComponents) buildChild(
vm: p.vm,
innerBlk: innerBlock,
status: choices.Processing,
slot: unspecifiedSlotIndex,
},
}

Expand Down Expand Up @@ -366,15 +375,17 @@ func (p *postForkCommonComponents) verifyPostDurangoBlockDelay(
var (
blkTimestamp = blk.Timestamp()
blkHeight = blk.Height()
currentSlot = proposer.TimeToSlot(parentTimestamp, blkTimestamp)
proposerID = blk.Proposer()
)
// populate the slot for the block.
blk.slot = proposer.TimeToSlot(parentTimestamp, blkTimestamp)

// find the expected proposer
expectedProposerID, err := p.vm.Windower.ExpectedProposer(
ctx,
blkHeight,
parentPChainHeight,
currentSlot,
blk.slot,
)
switch {
case errors.Is(err, proposer.ErrAnyoneCanPropose):
Expand All @@ -389,7 +400,7 @@ func (p *postForkCommonComponents) verifyPostDurangoBlockDelay(
case expectedProposerID == proposerID:
return true, nil // block should be signed
default:
return false, fmt.Errorf("%w: slot %d expects %s", errUnexpectedProposer, currentSlot, expectedProposerID)
return false, fmt.Errorf("%w: slot %d expects %s", errUnexpectedProposer, blk.slot, expectedProposerID)
}
}

Expand Down Expand Up @@ -504,3 +515,11 @@ func (p *postForkCommonComponents) shouldBuildSignedBlockPreDurango(
p.vm.notifyInnerBlockReady()
return false, fmt.Errorf("%w: delay %s < minDelay %s", errProposerWindowNotStarted, delay, minDelay)
}

// writeAcceptedSlotMetrics use the previously stored slot index and add that to the
// metrics managed by the vm.
func (p *postForkCommonComponents) writeAcceptedSlotMetrics() {
if p.slot != unspecifiedSlotIndex {
p.vm.acceptedBlocksSlotHistogram.Observe(float64(p.slot))
}
}
7 changes: 6 additions & 1 deletion vms/proposervm/post_fork_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ func (b *postForkBlock) Accept(ctx context.Context) error {
if err := b.acceptOuterBlk(); err != nil {
return err
}
return b.acceptInnerBlk(ctx)
if err := b.acceptInnerBlk(ctx); err != nil {
return err
}
b.writeAcceptedSlotMetrics()
return nil
}

func (b *postForkBlock) acceptOuterBlk() error {
Expand Down Expand Up @@ -106,6 +110,7 @@ func (b *postForkBlock) Options(ctx context.Context) ([2]snowman.Block, error) {
vm: b.vm,
innerBlk: innerOption,
status: innerOption.Status(),
slot: unspecifiedSlotIndex,
},
}
}
Expand Down
6 changes: 5 additions & 1 deletion vms/proposervm/post_fork_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func (b *postForkOption) Accept(ctx context.Context) error {
if err := b.acceptOuterBlk(); err != nil {
return err
}
return b.acceptInnerBlk(ctx)
if err := b.acceptInnerBlk(ctx); err != nil {
return err
}
b.writeAcceptedSlotMetrics()
return nil
}

func (b *postForkOption) acceptOuterBlk() error {
Expand Down
1 change: 1 addition & 0 deletions vms/proposervm/pre_fork_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func (b *preForkBlock) buildChild(ctx context.Context) (Block, error) {
vm: b.vm,
innerBlk: innerBlock,
status: choices.Processing,
slot: unspecifiedSlotIndex,
},
}

Expand Down
51 changes: 50 additions & 1 deletion vms/proposervm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ type VM struct {

// lastAcceptedHeight is set to the last accepted PostForkBlock's height.
lastAcceptedHeight uint64

// proposerBuildSlotGauge is the metric gauge used when reporting the current slot block build built.
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
proposerBuildSlotGauge prometheus.Gauge

// acceptedBlocksSlotHistogram is the metric histogram that is being updated once a block gets accepted with it's corresponding slot.
// note that this histogram is being updated by postForkCommonComponents.writeAcceptedSlotMetrics.
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
acceptedBlocksSlotHistogram prometheus.Histogram
}

// New performs best when [minBlkDelay] is whole seconds. This is because block
Expand Down Expand Up @@ -133,6 +140,7 @@ func (vm *VM) Initialize(
// TODO: Add a helper for this metrics override, it is performed in multiple
// places.
registerer := prometheus.NewRegistry()

if err := chainCtx.Metrics.Register("proposervm", registerer); err != nil {
return err
}
Expand Down Expand Up @@ -220,6 +228,34 @@ func (vm *VM) Initialize(
default:
return err
}

vm.proposerBuildSlotGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "block_building_slot",
Help: "the post-durango slot in which the block was built",
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
})

if err = registerer.Register(vm.proposerBuildSlotGauge); err != nil {
return err
}

vm.acceptedBlocksSlotHistogram = prometheus.NewHistogram(
prometheus.HistogramOpts{
Name: "accepted_blocks_slot_histogram",
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
Help: "the post-durango slot in which the block was accepted at",
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
// define the following ranges:
// (-inf, 0]
// (0, 1]
// (1, 2]
// (2, inf)
// the usage of ".5" before was to ensure we work around the limitation
// of comparing floating point of the same numerical value.
Buckets: []float64{0.5, 1.5, 2.5},
},
)
if err = registerer.Register(vm.acceptedBlocksSlotHistogram); err != nil {
return err
}
return nil
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -305,14 +341,16 @@ func (vm *VM) SetPreference(ctx context.Context, preferred ids.ID) error {
childBlockHeight = blk.Height() + 1
parentTimestamp = blk.Timestamp()
nextStartTime time.Time
proposalSlot = unspecifiedSlotIndex
)
if vm.IsDurangoActivated(parentTimestamp) {
currentTime := vm.Clock.Time().Truncate(time.Second)
proposalSlot = proposer.TimeToSlot(parentTimestamp, currentTime)
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
nextStartTime, err = vm.getPostDurangoSlotTime(
ctx,
childBlockHeight,
pChainHeight,
proposer.TimeToSlot(parentTimestamp, currentTime),
proposalSlot,
parentTimestamp,
)
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
} else {
Expand All @@ -334,6 +372,13 @@ func (vm *VM) SetPreference(ctx context.Context, preferred ids.ID) error {
// until the P-chain's height has advanced.
return nil
}

// if we're done bootstrapping, and we have a proposal window slot, update
// the metrics accordingly.
if (proposalSlot != unspecifiedSlotIndex) && (vm.consensusState == snow.NormalOp) {
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
vm.proposerBuildSlotGauge.Set(float64(proposalSlot))
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
}

vm.Scheduler.SetBuildBlockTime(nextStartTime)

vm.ctx.Log.Debug("set preference",
Expand Down Expand Up @@ -536,6 +581,7 @@ func (vm *VM) parsePostForkBlock(ctx context.Context, b []byte) (PostForkBlock,
vm: vm,
innerBlk: innerBlk,
status: choices.Processing,
slot: unspecifiedSlotIndex,
},
}
} else {
Expand All @@ -545,6 +591,7 @@ func (vm *VM) parsePostForkBlock(ctx context.Context, b []byte) (PostForkBlock,
vm: vm,
innerBlk: innerBlk,
status: choices.Processing,
slot: unspecifiedSlotIndex,
},
}
}
Expand Down Expand Up @@ -590,6 +637,7 @@ func (vm *VM) getPostForkBlock(ctx context.Context, blkID ids.ID) (PostForkBlock
vm: vm,
innerBlk: innerBlk,
status: status,
slot: unspecifiedSlotIndex,
},
}, nil
}
Expand All @@ -599,6 +647,7 @@ func (vm *VM) getPostForkBlock(ctx context.Context, blkID ids.ID) (PostForkBlock
vm: vm,
innerBlk: innerBlk,
status: status,
slot: unspecifiedSlotIndex,
},
}, nil
}
Expand Down
Loading