Skip to content

Commit

Permalink
Improve functions naming
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-zimnoch committed Nov 29, 2023
1 parent 4d3b027 commit 9d65110
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
33 changes: 16 additions & 17 deletions pkg/tbtc/coordination.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,18 @@ func (ce *coordinationExecutor) coordinate(

execLogger.Info("starting coordination")

seed, err := ce.coordinationSeed(window.coordinationBlock)
seed, err := ce.getSeed(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)
leader := ce.getLeader(seed)

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

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

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

Expand All @@ -382,7 +382,7 @@ func (ce *coordinationExecutor) coordinate(
if leader == ce.operatorAddress {
execLogger.Info("executing leader's routine")

proposal, err = ce.leaderRoutine(
proposal, err = ce.executeLeaderRoutine(
ctx,
window.coordinationBlock,
actionsChecklist,
Expand All @@ -398,7 +398,7 @@ func (ce *coordinationExecutor) coordinate(
} else {
execLogger.Info("executing follower's routine")

proposal, faults, err = ce.followerRoutine(
proposal, faults, err = ce.executeFollowerRoutine(
ctx,
leader,
window.coordinationBlock,
Expand Down Expand Up @@ -436,9 +436,8 @@ func (ce *coordinationExecutor) coordinate(
return result, nil
}

// coordinationSeed computes the coordination seed for the given coordination
// window.
func (ce *coordinationExecutor) coordinationSeed(
// getSeed computes the coordination seed for the given coordination window.
func (ce *coordinationExecutor) getSeed(
coordinationBlock uint64,
) ([32]byte, error) {
walletPublicKeyHash := ce.walletPublicKeyHash()
Expand All @@ -460,9 +459,9 @@ func (ce *coordinationExecutor) coordinationSeed(
), nil
}

// coordinationLeader returns the address of the coordination leader for the
// given coordination seed.
func (ce *coordinationExecutor) coordinationLeader(seed [32]byte) chain.Address {
// getLeader returns the address of the coordination leader for the given
// coordination seed.
func (ce *coordinationExecutor) getLeader(seed [32]byte) chain.Address {
// First, take all operators backing the wallet.
allOperators := chain.Addresses(ce.coordinatedWallet.signingGroupOperators)

Expand Down Expand Up @@ -498,10 +497,10 @@ func (ce *coordinationExecutor) coordinationLeader(seed [32]byte) chain.Address
return uniqueOperators[0]
}

// actionsChecklist returns a list of wallet actions that should be checked
// getActionsChecklist returns a list of wallet actions that should be checked
// for the given coordination window. Returns nil for incorrect coordination
// windows whose index is 0.
func (ce *coordinationExecutor) actionsChecklist(
func (ce *coordinationExecutor) getActionsChecklist(
windowIndex uint64,
seed [32]byte,
) []WalletActionType {
Expand Down Expand Up @@ -545,10 +544,10 @@ func (ce *coordinationExecutor) actionsChecklist(
return actions
}

// leaderRoutine executes the leader's routine for the given coordination
// executeLeaderRoutine executes the leader's routine for the given coordination
// window. The routine generates a proposal and broadcasts it to the followers.
// It returns the generated proposal or an error if the routine failed.
func (ce *coordinationExecutor) leaderRoutine(
func (ce *coordinationExecutor) executeLeaderRoutine(
ctx context.Context,
coordinationBlock uint64,
actionsChecklist []WalletActionType,
Expand Down Expand Up @@ -585,11 +584,11 @@ func (ce *coordinationExecutor) leaderRoutine(
return proposal, nil
}

// followerRoutine executes the follower's routine for the given coordination
// executeFollowerRoutine executes the follower's routine for the given coordination
// window. The routine listens for the coordination message from the leader and
// validates it. If the leader's proposal is valid, it returns the received
// proposal. Returns an error if the routine failed.
func (ce *coordinationExecutor) followerRoutine(
func (ce *coordinationExecutor) executeFollowerRoutine(
ctx context.Context,
leader chain.Address,
coordinationBlock uint64,
Expand Down
24 changes: 12 additions & 12 deletions pkg/tbtc/coordination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ loop:
)
}

func TestCoordinationExecutor_CoordinationSeed(t *testing.T) {
func TestCoordinationExecutor_GetSeed(t *testing.T) {
coordinationBlock := uint64(900)

localChain := Connect()
Expand Down Expand Up @@ -478,7 +478,7 @@ func TestCoordinationExecutor_CoordinationSeed(t *testing.T) {
coordinatedWallet: coordinatedWallet,
}

seed, err := executor.coordinationSeed(coordinationBlock)
seed, err := executor.getSeed(coordinationBlock)
if err != nil {
t.Fatal(err)
}
Expand All @@ -494,7 +494,7 @@ func TestCoordinationExecutor_CoordinationSeed(t *testing.T) {
)
}

func TestCoordinationExecutor_CoordinationLeader(t *testing.T) {
func TestCoordinationExecutor_GetLeader(t *testing.T) {
seedBytes, err := hex.DecodeString(
"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
)
Expand Down Expand Up @@ -526,7 +526,7 @@ func TestCoordinationExecutor_CoordinationLeader(t *testing.T) {
coordinatedWallet: coordinatedWallet,
}

leader := executor.coordinationLeader(seed)
leader := executor.getLeader(seed)

testutils.AssertStringsEqual(
t,
Expand All @@ -536,7 +536,7 @@ func TestCoordinationExecutor_CoordinationLeader(t *testing.T) {
)
}

func TestCoordinationExecutor_ActionsChecklist(t *testing.T) {
func TestCoordinationExecutor_GetActionsChecklist(t *testing.T) {
tests := map[string]struct {
coordinationBlock uint64
expectedChecklist []WalletActionType
Expand Down Expand Up @@ -643,7 +643,7 @@ func TestCoordinationExecutor_ActionsChecklist(t *testing.T) {
big.NewInt(int64(window.coordinationBlock) + 1).Bytes(),
)

checklist := executor.actionsChecklist(window.index(), seed)
checklist := executor.getActionsChecklist(window.index(), seed)

if diff := deep.Equal(
checklist,
Expand All @@ -661,7 +661,7 @@ func TestCoordinationExecutor_ActionsChecklist(t *testing.T) {
}
}

func TestCoordinationExecutor_LeaderRoutine(t *testing.T) {
func TestCoordinationExecutor_ExecuteLeaderRoutine(t *testing.T) {
// Uncompressed public key corresponding to the 20-byte public key hash:
// aa768412ceed10bd423c025542ca90071f9fb62d.
publicKeyHex, err := hex.DecodeString(
Expand Down Expand Up @@ -752,7 +752,7 @@ func TestCoordinationExecutor_LeaderRoutine(t *testing.T) {
cancelCtx()
})

proposal, err := executor.leaderRoutine(ctx, 900, actionsChecklist)
proposal, err := executor.executeLeaderRoutine(ctx, 900, actionsChecklist)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -791,7 +791,7 @@ func TestCoordinationExecutor_LeaderRoutine(t *testing.T) {
}
}

func TestCoordinationExecutor_FollowerRoutine(t *testing.T) {
func TestCoordinationExecutor_ExecuteFollowerRoutine(t *testing.T) {
// Uncompressed public key corresponding to the 20-byte public key hash:
// aa768412ceed10bd423c025542ca90071f9fb62d.
publicKeyHex, err := hex.DecodeString(
Expand Down Expand Up @@ -1013,7 +1013,7 @@ func TestCoordinationExecutor_FollowerRoutine(t *testing.T) {
}
}()

proposal, faults, err := executor.followerRoutine(
proposal, faults, err := executor.executeFollowerRoutine(
ctx,
leader.address,
900,
Expand Down Expand Up @@ -1062,7 +1062,7 @@ func TestCoordinationExecutor_FollowerRoutine(t *testing.T) {
}
}

func TestCoordinationExecutor_FollowerRoutine_WithIdleLeader(t *testing.T) {
func TestCoordinationExecutor_ExecuteFollowerRoutine_WithIdleLeader(t *testing.T) {
// Uncompressed public key corresponding to the 20-byte public key hash:
// aa768412ceed10bd423c025542ca90071f9fb62d.
publicKeyHex, err := hex.DecodeString(
Expand Down Expand Up @@ -1127,7 +1127,7 @@ func TestCoordinationExecutor_FollowerRoutine_WithIdleLeader(t *testing.T) {
ctx, cancelCtx := context.WithTimeout(context.Background(), 1*time.Second)
defer cancelCtx()

_, faults, err := executor.followerRoutine(
_, faults, err := executor.executeFollowerRoutine(
ctx,
leader,
900,
Expand Down

0 comments on commit 9d65110

Please sign in to comment.