Skip to content

Commit 34c2600

Browse files
authored
fix: use log block number for refresh session iD (#111)
<!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> ## Related Issue Or Context <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Otherwise, describe context and motivation for change herre --> Closes: #<issue> ## How Has This Been Tested? Testing details. <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have ensured that all acceptance criteria (or expected behavior) from issue are met - [ ] I have updated the documentation locally and in docs. - [ ] I have added tests to cover my changes. - [ ] I have ensured that all the checks are passing and green, I've signed the CLA bot
1 parent e264d1b commit 34c2600

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

.github/workflows/mocks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
go-version: "^1.23"
2424

25-
- run: go install go.uber.org/mock/[email protected].0
25+
- run: go install go.uber.org/mock/[email protected]
2626

2727
- run: make genmocks
2828

chains/evm/calls/events/listener.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ func (l *Listener) FetchKeygenEvents(ctx context.Context, contractAddress common
4545
return logs, nil
4646
}
4747

48-
func (l *Listener) FetchRefreshEvents(ctx context.Context, contractAddress common.Address, startBlock *big.Int, endBlock *big.Int) ([]*Refresh, error) {
48+
func (l *Listener) FetchRefreshEvents(ctx context.Context, contractAddress common.Address, startBlock *big.Int, endBlock *big.Int) (*Refresh, ethTypes.Log, error) {
4949
logs, err := l.client.FetchEventLogs(ctx, contractAddress, string(KeyRefreshSig), startBlock, endBlock)
5050
if err != nil {
51-
return nil, err
51+
return nil, ethTypes.Log{}, err
5252
}
53-
refreshEvents := make([]*Refresh, 0)
5453

5554
for _, re := range logs {
5655
r, err := l.UnpackRefresh(l.abi, re.Data)
@@ -59,10 +58,10 @@ func (l *Listener) FetchRefreshEvents(ctx context.Context, contractAddress commo
5958
continue
6059
}
6160

62-
refreshEvents = append(refreshEvents, r)
61+
return r, re, nil
6362
}
6463

65-
return refreshEvents, nil
64+
return nil, ethTypes.Log{}, nil
6665
}
6766

6867
func (l *Listener) UnpackRefresh(abi abi.ABI, data []byte) (*Refresh, error) {

chains/evm/listener/tss.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
type EventListener interface {
2828
FetchKeygenEvents(ctx context.Context, address common.Address, startBlock *big.Int, endBlock *big.Int) ([]types.Log, error)
29-
FetchRefreshEvents(ctx context.Context, address common.Address, startBlock *big.Int, endBlock *big.Int) ([]*events.Refresh, error)
29+
FetchRefreshEvents(ctx context.Context, address common.Address, startBlock *big.Int, endBlock *big.Int) (*events.Refresh, types.Log, error)
3030
}
3131

3232
type KeygenEventHandler struct {
@@ -143,22 +143,17 @@ func (eh *RefreshEventHandler) HandleEvents(
143143
startBlock *big.Int,
144144
endBlock *big.Int,
145145
) error {
146-
refreshEvents, err := eh.eventListener.FetchRefreshEvents(
146+
refreshEvent, l, err := eh.eventListener.FetchRefreshEvents(
147147
context.Background(), eh.bridgeAddress, startBlock, endBlock,
148148
)
149149
if err != nil {
150150
return fmt.Errorf("unable to fetch keygen events because of: %+v", err)
151151
}
152-
if len(refreshEvents) == 0 {
152+
if refreshEvent == nil {
153153
return nil
154154
}
155155

156-
hash := refreshEvents[len(refreshEvents)-1].Hash
157-
if hash == "" {
158-
log.Error().Msgf("Hash cannot be empty string")
159-
return nil
160-
}
161-
topology, err := eh.topologyProvider.NetworkTopology(hash)
156+
topology, err := eh.topologyProvider.NetworkTopology(refreshEvent.Hash)
162157
if err != nil {
163158
log.Error().Err(err).Msgf("Failed fetching network topology")
164159
return nil
@@ -177,7 +172,7 @@ func (eh *RefreshEventHandler) HandleEvents(
177172
)
178173

179174
resharing := resharing.NewResharing(
180-
eh.sessionID(startBlock), topology.Threshold, eh.host, eh.communication, eh.ecdsaStorer,
175+
eh.sessionID(new(big.Int).SetUint64(l.BlockNumber)), topology.Threshold, eh.host, eh.communication, eh.ecdsaStorer,
181176
)
182177
err = eh.coordinator.Execute(context.Background(), []tss.TssProcess{resharing}, make(chan interface{}, 1), peer.ID(""))
183178
if err != nil {

0 commit comments

Comments
 (0)