Skip to content

Commit

Permalink
fix: fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Aug 2, 2024
1 parent 3791377 commit 5532745
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
4 changes: 1 addition & 3 deletions node/pkg/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aggregator
import (
"context"
"encoding/json"
"sync"

"time"

Expand Down Expand Up @@ -97,15 +96,14 @@ func (n *Aggregator) HandleTriggerMessage(ctx context.Context, msg raft.Message)
defer n.cleanUpRoundData(triggerMessage.RoundID - 10)

var value int64
localAggregateRaw, ok := n.LatestLocalAggregates.Load(n.ID)
localAggregate, ok := n.LatestLocalAggregates.Load(n.ID)
if !ok {
log.Error().Str("Player", "Aggregator").Msg("failed to get latest local aggregate")
// set value to -1 rather than returning error
// it is to proceed further steps even if current node fails to get latest local aggregate
// if not enough messages collected from HandleSyncReplyMessage, it will hang in certain round
value = -1
} else {
localAggregate := localAggregateRaw.(types.LocalAggregate)
value = localAggregate.Value
}

Expand Down
34 changes: 16 additions & 18 deletions node/pkg/aggregator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
const (
AGREEMENT_QUORUM = 0.5

RoundSync raft.MessageType = "roundSync"
SyncReply raft.MessageType = "syncReply"
Trigger raft.MessageType = "trigger"
PriceData raft.MessageType = "priceData"
ProofMsg raft.MessageType = "proof"
Expand Down Expand Up @@ -69,12 +67,12 @@ type Aggregator struct {
Config
Raft *raft.Raft

LatestLocalAggregates *LatestLocalAggregates
roundPrices *RoundPrices
roundProofs *RoundProofs
LatestLocalAggregates *LatestLocalAggregates
roundPrices *RoundPrices
roundProofs *RoundProofs

RoundID int32
Signer *helper.Signer
RoundID int32
Signer *helper.Signer

nodeCtx context.Context
nodeCancel context.CancelFunc
Expand All @@ -100,6 +98,17 @@ type TriggerMessage struct {
Timestamp time.Time `json:"timestamp"`
}

type LatestLocalAggregates struct {
LocalAggregateMap map[int32]types.LocalAggregate
mu sync.RWMutex
}

func NewLatestLocalAggregates() *LatestLocalAggregates {
return &LatestLocalAggregates{
LocalAggregateMap: map[int32]types.LocalAggregate{},
}
}

func (r *RoundPrices) push(round int32, value int64) {
r.mu.Lock()
defer r.mu.Unlock()
Expand Down Expand Up @@ -172,17 +181,6 @@ func (r *RoundProofs) delete(round int32) {
delete(r.proofs, round)
}

type LatestLocalAggregates struct {
LocalAggregateMap map[int32]types.LocalAggregate
mu sync.RWMutex
}

func NewLatestLocalAggregates() *LatestLocalAggregates {
return &LatestLocalAggregates{
LocalAggregateMap: map[int32]types.LocalAggregate{},
}
}

func (a *LatestLocalAggregates) Load(id int32) (types.LocalAggregate, bool) {
a.mu.RLock()
defer a.mu.RUnlock()
Expand Down

0 comments on commit 5532745

Please sign in to comment.