Skip to content

Commit 0e96538

Browse files
authored
Publish last accepted height through chits (#3441)
Signed-off-by: Yacov Manevich <yacov.manevich@avalabs.org>
1 parent f45245a commit 0e96538

File tree

19 files changed

+229
-113
lines changed

19 files changed

+229
-113
lines changed

message/messagemock/outbound_message_builder.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

message/outbound_msg_builder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ type OutboundMsgBuilder interface {
154154
preferredID ids.ID,
155155
preferredIDAtHeight ids.ID,
156156
acceptedID ids.ID,
157+
acceptedHeight uint64,
157158
) (OutboundMessage, error)
158159

159160
AppRequest(
@@ -639,6 +640,7 @@ func (b *outMsgBuilder) Chits(
639640
preferredID ids.ID,
640641
preferredIDAtHeight ids.ID,
641642
acceptedID ids.ID,
643+
acceptedHeight uint64,
642644
) (OutboundMessage, error) {
643645
return b.builder.createOutbound(
644646
&p2p.Message{
@@ -649,6 +651,7 @@ func (b *outMsgBuilder) Chits(
649651
PreferredId: preferredID[:],
650652
PreferredIdAtHeight: preferredIDAtHeight[:],
651653
AcceptedId: acceptedID[:],
654+
AcceptedHeight: acceptedHeight,
652655
},
653656
},
654657
},

proto/p2p/p2p.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ message Chits {
371371
bytes accepted_id = 4;
372372
// ID of the currently preferred block at the requested height
373373
bytes preferred_id_at_height = 5;
374+
// Last accepted block's height
375+
uint64 accepted_height = 6;
374376
}
375377

376378
// AppRequest is a VM-defined request.

proto/pb/p2p/p2p.pb.go

Lines changed: 50 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snow/engine/common/commonmock/sender.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snow/engine/common/engine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ type ChitsHandler interface {
330330
preferredID ids.ID,
331331
preferredIDAtHeight ids.ID,
332332
acceptedID ids.ID,
333+
acceptedHeight uint64,
333334
) error
334335

335336
// Notify this engine that a Query request it issued has failed.

snow/engine/common/no_ops_handlers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func NewNoOpChitsHandler(log logging.Logger) ChitsHandler {
237237
return &noOpChitsHandler{log: log}
238238
}
239239

240-
func (nop *noOpChitsHandler) Chits(_ context.Context, nodeID ids.NodeID, requestID uint32, preferredID, preferredIDAtHeight, acceptedID ids.ID) error {
240+
func (nop *noOpChitsHandler) Chits(_ context.Context, nodeID ids.NodeID, requestID uint32, preferredID, preferredIDAtHeight, acceptedID ids.ID, acceptedHeight uint64) error {
241241
nop.log.Debug("dropping request",
242242
zap.String("reason", "unhandled by this gear"),
243243
zap.Stringer("messageOp", message.ChitsOp),
@@ -246,6 +246,7 @@ func (nop *noOpChitsHandler) Chits(_ context.Context, nodeID ids.NodeID, request
246246
zap.Stringer("preferredID", preferredID),
247247
zap.Stringer("preferredIDAtHeight", preferredIDAtHeight),
248248
zap.Stringer("acceptedID", acceptedID),
249+
zap.Uint64("acceptedHeight", acceptedHeight),
249250
)
250251
return nil
251252
}

snow/engine/common/sender.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ type QuerySender interface {
161161
preferredID ids.ID,
162162
preferredIDAtHeight ids.ID,
163163
acceptedID ids.ID,
164+
acceptedHeight uint64,
164165
)
165166
}
166167

snow/engine/common/traced_engine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (e *tracedEngine) PushQuery(ctx context.Context, nodeID ids.NodeID, request
245245
return e.engine.PushQuery(ctx, nodeID, requestID, container, requestedHeight)
246246
}
247247

248-
func (e *tracedEngine) Chits(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredID ids.ID, preferredIDAtHeight ids.ID, acceptedID ids.ID) error {
248+
func (e *tracedEngine) Chits(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredID ids.ID, preferredIDAtHeight ids.ID, acceptedID ids.ID, acceptedHeight uint64) error {
249249
ctx, span := e.tracer.Start(ctx, "tracedEngine.Chits", oteltrace.WithAttributes(
250250
attribute.Stringer("nodeID", nodeID),
251251
attribute.Int64("requestID", int64(requestID)),
@@ -255,7 +255,7 @@ func (e *tracedEngine) Chits(ctx context.Context, nodeID ids.NodeID, requestID u
255255
))
256256
defer span.End()
257257

258-
return e.engine.Chits(ctx, nodeID, requestID, preferredID, preferredIDAtHeight, acceptedID)
258+
return e.engine.Chits(ctx, nodeID, requestID, preferredID, preferredIDAtHeight, acceptedID, acceptedHeight)
259259
}
260260

261261
func (e *tracedEngine) QueryFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32) error {

snow/engine/common/tracker/accepted.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,28 @@ type Accepted interface {
1818
validators.SetCallbackListener
1919

2020
// SetLastAccepted updates the latest accepted block for [nodeID] to
21-
// [blockID]. If [nodeID] is not currently a validator, this is a noop.
22-
SetLastAccepted(nodeID ids.NodeID, blockID ids.ID)
21+
// [blockID], with a corresponding height.
22+
// If [nodeID] is not currently a validator, this is a noop.
23+
SetLastAccepted(nodeID ids.NodeID, blockID ids.ID, height uint64)
2324
// LastAccepted returns the latest known accepted block of [nodeID]. If
2425
// [nodeID]'s last accepted block was never unknown, false will be returned.
25-
LastAccepted(nodeID ids.NodeID) (ids.ID, bool)
26+
LastAccepted(nodeID ids.NodeID) (ids.ID, uint64, bool)
27+
}
28+
29+
type idHeight struct {
30+
id ids.ID
31+
height uint64
2632
}
2733

2834
type accepted struct {
29-
lock sync.RWMutex
30-
validators set.Set[ids.NodeID]
31-
frontier map[ids.NodeID]ids.ID
35+
lock sync.RWMutex
36+
validators set.Set[ids.NodeID]
37+
lastAccepted map[ids.NodeID]idHeight
3238
}
3339

3440
func NewAccepted() Accepted {
3541
return &accepted{
36-
frontier: make(map[ids.NodeID]ids.ID),
42+
lastAccepted: make(map[ids.NodeID]idHeight),
3743
}
3844
}
3945

@@ -49,24 +55,27 @@ func (a *accepted) OnValidatorRemoved(nodeID ids.NodeID, _ uint64) {
4955
defer a.lock.Unlock()
5056

5157
a.validators.Remove(nodeID)
52-
delete(a.frontier, nodeID)
58+
delete(a.lastAccepted, nodeID)
5359
}
5460

5561
func (*accepted) OnValidatorWeightChanged(_ ids.NodeID, _, _ uint64) {}
5662

57-
func (a *accepted) SetLastAccepted(nodeID ids.NodeID, frontier ids.ID) {
63+
func (a *accepted) SetLastAccepted(nodeID ids.NodeID, id ids.ID, height uint64) {
5864
a.lock.Lock()
5965
defer a.lock.Unlock()
6066

6167
if a.validators.Contains(nodeID) {
62-
a.frontier[nodeID] = frontier
68+
a.lastAccepted[nodeID] = idHeight{
69+
id: id,
70+
height: height,
71+
}
6372
}
6473
}
6574

66-
func (a *accepted) LastAccepted(nodeID ids.NodeID) (ids.ID, bool) {
75+
func (a *accepted) LastAccepted(nodeID ids.NodeID) (ids.ID, uint64, bool) {
6776
a.lock.RLock()
6877
defer a.lock.RUnlock()
6978

70-
acceptedID, ok := a.frontier[nodeID]
71-
return acceptedID, ok
79+
acceptedAndHeight, ok := a.lastAccepted[nodeID]
80+
return acceptedAndHeight.id, acceptedAndHeight.height, ok
7281
}

0 commit comments

Comments
 (0)