Skip to content

Commit 0bec6d5

Browse files
authored
Introduce gpbft.Instant to capture precise progress moment (#698)
In a number of places, namely rebroadcast request and progress we need information a precise moment in GPBFT progress. Prior to changes here the changes were communicated as three separate values, which was cumbersome to work with as the usage of this information increased with rebroadcast. Introduce `Instant` as a struct to capture precise instant in GPBFT progress and reflect changes across `Progress` as well as `RequestRebroadcast`. Relates to #691 (comment)
1 parent 23ce86a commit 0bec6d5

File tree

14 files changed

+178
-197
lines changed

14 files changed

+178
-197
lines changed

emulator/host.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func (h *driverHost) RequestBroadcast(mb *gpbft.MessageBuilder) error {
5454
return nil
5555
}
5656

57-
func (h *driverHost) RequestRebroadcast(instance, round uint64, phase gpbft.Phase) error {
58-
message, found := h.messages.Get(instance, round, phase)
57+
func (h *driverHost) RequestRebroadcast(instant gpbft.Instant) error {
58+
message, found := h.messages.Get(instant)
5959
if found {
6060
h.receivedBroadcasts = append(h.receivedBroadcasts, message)
6161
}

emulator/message_cache.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,25 @@ package emulator
22

33
import "github.com/filecoin-project/go-f3/gpbft"
44

5-
type MessageKey struct {
6-
Instance, Round uint64
7-
Phase gpbft.Phase
8-
}
9-
105
// MessageCache is a repository of messages keyed by their instance, round and
116
// phase. This cache is used for testing purposes only and has no eviction
127
// strategy. It is primarily used to store messages from self for rebroadcast.
13-
type MessageCache map[MessageKey]*gpbft.GMessage
8+
type MessageCache map[gpbft.Instant]*gpbft.GMessage
149

1510
func NewMessageCache() MessageCache {
16-
return make(map[MessageKey]*gpbft.GMessage)
11+
return make(map[gpbft.Instant]*gpbft.GMessage)
1712
}
1813

19-
func (mc MessageCache) Get(instance, round uint64, phase gpbft.Phase) (*gpbft.GMessage, bool) {
20-
msg, found := mc[MessageKey{
21-
Instance: instance,
22-
Round: round,
23-
Phase: phase,
24-
}]
14+
func (mc MessageCache) Get(instant gpbft.Instant) (*gpbft.GMessage, bool) {
15+
msg, found := mc[instant]
2516
return msg, found
2617
}
2718

2819
func (mc MessageCache) PutIfAbsent(msg *gpbft.GMessage) bool {
29-
key := MessageKey{
30-
Instance: msg.Vote.Instance,
31-
Round: msg.Vote.Round,
32-
Phase: msg.Vote.Phase,
20+
key := gpbft.Instant{
21+
ID: msg.Vote.Instance,
22+
Round: msg.Vote.Round,
23+
Phase: msg.Vote.Phase,
3324
}
3425
if _, found := mc[key]; found {
3526
return false

f3.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,9 @@ func (m *F3) GetPowerTable(ctx context.Context, ts gpbft.TipSetKey) (gpbft.Power
415415
return nil, fmt.Errorf("no known network manifest")
416416
}
417417

418-
func (m *F3) Progress() (instance, round uint64, phase gpbft.Phase) {
418+
func (m *F3) Progress() (instant gpbft.Instant) {
419419
if st := m.state.Load(); st != nil && st.runner != nil {
420-
instance, round, phase = st.runner.Progress()
420+
instant = st.runner.Progress()
421421
}
422422
return
423423
}

gpbft/api.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import (
55
"time"
66
)
77

8+
// Instant represents a particular moment in the progress of GPBFT, captured by
9+
// instance ID, round and phase.
10+
type Instant struct {
11+
ID uint64
12+
Round uint64
13+
Phase Phase
14+
}
15+
816
type MessageValidator interface {
917
// Validates a Granite message.
1018
// An invalid message can never become valid, so may be dropped.
@@ -97,7 +105,7 @@ type Network interface {
97105
// RequestRebroadcast requests that a message at given instance, round and phase
98106
// previously broadcasted via RequestBroadcast be rebroadcasted. Rebroadcast
99107
// requests for messages that have not been broadcasted are silently ignored.
100-
RequestRebroadcast(instance, round uint64, phase Phase) error
108+
RequestRebroadcast(instant Instant) error
101109
}
102110

103111
type Clock interface {

0 commit comments

Comments
 (0)