Skip to content

Commit f395e26

Browse files
committed
Merge branch 'tilen/contract_fetch' into 'main'
Automatic fetching of FastUpdater contract address. See merge request flarenetwork/fast-updates!34
2 parents 6c655d1 + 5d799d3 commit f395e26

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

go-client/client/client.go

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,15 @@ func CreateFastUpdatesClient(cfg *config.Config, valuesProvider provider.ValuesP
105105
fastUpdatesClient.transactionAccounts[i].Address = crypto.PubkeyToAddress(*publicKeyECDSA)
106106
}
107107

108-
fastUpdatesClient.fastUpdater, err = fast_updater.NewFastUpdater(
109-
common.HexToAddress(cfg.Client.FastUpdaterAddress), fastUpdatesClient.chainClient,
110-
)
111-
if err != nil {
112-
return nil, fmt.Errorf("CreateFastUpdatesClient: NewFastUpdater: %w", err)
108+
if cfg.Client.FastUpdaterAddress != "" {
109+
fastUpdatesClient.fastUpdater, err = fast_updater.NewFastUpdater(
110+
common.HexToAddress(cfg.Client.FastUpdaterAddress), fastUpdatesClient.chainClient,
111+
)
112+
if err != nil {
113+
return nil, fmt.Errorf("CreateFastUpdatesClient: NewFastUpdater: %w", err)
114+
}
113115
}
116+
114117
fastUpdatesClient.IncentiveManager, err = incentive.NewIncentive(
115118
common.HexToAddress(cfg.Client.IncentiveManagerAddress), fastUpdatesClient.chainClient,
116119
)
@@ -134,6 +137,11 @@ func CreateFastUpdatesClient(cfg *config.Config, valuesProvider provider.ValuesP
134137
}
135138
}
136139

140+
err = fastUpdatesClient.UpdateFastUpdaterContractAddress()
141+
if err != nil {
142+
return nil, err
143+
}
144+
137145
fastUpdatesClient.flareSystemMock, err = mock.NewMock(
138146
common.HexToAddress(cfg.Client.MockAddress), fastUpdatesClient.chainClient,
139147
)
@@ -209,6 +217,11 @@ func (client *FastUpdatesClient) Run(startBlock, endBlock uint64) error {
209217
logger.Info("Fetched feed ids: %v", client.allFeeds)
210218

211219
for {
220+
err = client.UpdateFastUpdaterContractAddress()
221+
if err != nil {
222+
logger.Error("Failed attempt in updating the FastUpdater contract address: %s", err)
223+
}
224+
212225
if blockNum%refreshFeedsBlockInterval == 0 {
213226
client.allFeeds, err = client.GetCurrentFeedIds()
214227
if err != nil {
@@ -295,7 +308,6 @@ func (client *FastUpdatesClient) Run(startBlock, endBlock uint64) error {
295308
}
296309
}
297310

298-
299311
func (client *FastUpdatesClient) GetBlockScoreCutoffWithRepeats(blockNum uint64) (*big.Int, error) {
300312
var cutoff *big.Int
301313
var err error
@@ -320,3 +332,27 @@ func (client *FastUpdatesClient) WaitToEmptyRequests() {
320332
func (client *FastUpdatesClient) Stop() {
321333
client.transactionQueue.StopQueue()
322334
}
335+
336+
func (client *FastUpdatesClient) UpdateFastUpdaterContractAddress() error {
337+
if client.submission == nil {
338+
return nil
339+
}
340+
341+
newAddress, err := client.GetFastUpdaterContractAddress()
342+
if err != nil {
343+
return err
344+
}
345+
if newAddress != common.HexToAddress(client.params.FastUpdaterAddress) {
346+
client.fastUpdater, err = fast_updater.NewFastUpdater(
347+
newAddress, client.chainClient,
348+
)
349+
if err != nil {
350+
return err
351+
}
352+
353+
client.params.FastUpdaterAddress = newAddress.Hex()
354+
logger.Info("Updated the FastUpdater address to %s", client.params.FastUpdaterAddress)
355+
}
356+
357+
return nil
358+
}

go-client/client/client_requests.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/ethereum/go-ethereum/accounts/abi/bind"
11+
"github.com/ethereum/go-ethereum/common"
1112
"github.com/ethereum/go-ethereum/core/types"
1213
"github.com/pkg/errors"
1314

@@ -297,3 +298,15 @@ func (client *FastUpdatesClient) submitUpdates(updateProof *sortition.UpdateProo
297298

298299
return nil
299300
}
301+
302+
func (client *FastUpdatesClient) GetFastUpdaterContractAddress() (common.Address, error) {
303+
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Duration(config.CallTimeoutMillisDefault)*time.Millisecond)
304+
ops := &bind.CallOpts{Context: ctx}
305+
fastUpdaterContractAddress, err := client.submission.SubmitAndPassContract(ops)
306+
cancelFunc()
307+
if err != nil {
308+
return common.Address{}, err
309+
}
310+
311+
return fastUpdaterContractAddress, nil
312+
}

0 commit comments

Comments
 (0)