Skip to content

Commit

Permalink
Add logging to coordinationExecutor.coordinate function
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-zimnoch committed Nov 29, 2023
1 parent d68487b commit 4d3b027
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions pkg/tbtc/coordination.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/binary"
"fmt"
"github.com/keep-network/keep-core/pkg/internal/pb"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"math/rand"
"sort"
Expand Down Expand Up @@ -320,8 +321,6 @@ func (ce *coordinationExecutor) walletPublicKeyHash() [20]byte {

// coordinate executes the coordination procedure for the given coordination
// window.
//
// TODO: Add logging.
func (ce *coordinationExecutor) coordinate(
window *coordinationWindow,
) (*coordinationResult, error) {
Expand All @@ -341,15 +340,33 @@ func (ce *coordinationExecutor) coordinate(
)
}

walletPublicKeyBytes, err := marshalPublicKey(ce.coordinatedWallet.publicKey)
if err != nil {
return nil, fmt.Errorf("cannot marshal wallet public key: [%v]", err)
}

execLogger := logger.With(
zap.Uint64("coordinationBlock", window.coordinationBlock),
zap.String("wallet", fmt.Sprintf("0x%x", walletPublicKeyBytes)),
)

execLogger.Info("starting coordination")

seed, err := ce.coordinationSeed(window.coordinationBlock)
if err != nil {
return nil, fmt.Errorf("failed to compute coordination seed: [%v]", err)
}

execLogger.Info("coordination seed is: [0x%x]", seed)

leader := ce.coordinationLeader(seed)

execLogger.Info("coordination leader is: [%s]", leader)

actionsChecklist := ce.actionsChecklist(window.index(), seed)

execLogger.Info("actions checklist is: [%v]", actionsChecklist)

// Set up a context that is cancelled when the active phase of the
// coordination window ends.
ctx, cancelCtx := withCancelOnBlock(
Expand All @@ -363,6 +380,8 @@ func (ce *coordinationExecutor) coordinate(
var faults []*coordinationFault

if leader == ce.operatorAddress {
execLogger.Info("executing leader's routine")

proposal, err = ce.leaderRoutine(
ctx,
window.coordinationBlock,
Expand All @@ -374,7 +393,11 @@ func (ce *coordinationExecutor) coordinate(
err,
)
}

execLogger.Info("broadcasted proposal: [%s]", proposal.actionType())
} else {
execLogger.Info("executing follower's routine")

proposal, faults, err = ce.followerRoutine(
ctx,
leader,
Expand All @@ -387,6 +410,12 @@ func (ce *coordinationExecutor) coordinate(
err,
)
}

execLogger.Info(
"received proposal: [%s]; observed faults: [%v]",
proposal.actionType(),
faults,
)
}

// Just in case, if the proposal is nil, set it to noop.
Expand All @@ -402,6 +431,8 @@ func (ce *coordinationExecutor) coordinate(
faults: faults,
}

execLogger.Info("coordination completed with result: [%s]", result)

return result, nil
}

Expand Down

0 comments on commit 4d3b027

Please sign in to comment.