diff --git a/go-client/README.md b/go-client/README.md index 1976175..b4ec9df 100644 --- a/go-client/README.md +++ b/go-client/README.md @@ -50,6 +50,8 @@ flare_system_manager = "0x919b4b4B561C72c990DC868F751328eF127c45F4" incentive_manager_address = "0x919b4b4B561C72c990DC868F751328eF127c45F4" # parameter defining when a fast update can be submitted submission_window = 10 +# url of the off-chain data provider +value_provider_url = "http://127.0.0.1:3101/feed-values/0" [transactions] gas_limit = 8000000 diff --git a/go-client/client/client.go b/go-client/client/client.go index 65822eb..b6e687d 100644 --- a/go-client/client/client.go +++ b/go-client/client/client.go @@ -4,6 +4,7 @@ import ( "crypto/ecdsa" "fmt" "math/big" + "time" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -53,6 +54,7 @@ type UpdatesStats struct { const ( refreshFeedsBlockInterval = 100 + cutoffRepeats = 10 ) func CreateFastUpdatesClient(cfg *config.Config, valuesProvider provider.ValuesProvider) (*FastUpdatesClient, error) { @@ -244,9 +246,10 @@ func (client *FastUpdatesClient) Run(startBlock, endBlock uint64) error { } logger.Info("new epoch, my weight weight %d, current block %d", weight, blockNum) } - cutoff, err := client.GetBlockScoreCutoff(big.NewInt(int64(blockNum))) // todo + + cutoff, err := client.GetBlockScoreCutoffWithRepeats(blockNum) if err != nil { - return fmt.Errorf("Run: GetCurrentScoreCutoff for block %d: %w", blockNum, err) + return fmt.Errorf("Run: GetBlockScoreCutoffWithRepeats: %w", err) } updateProofs, err := sortition.FindUpdateProofs(client.key, seed, cutoff, big.NewInt(int64(blockNum)), weight) @@ -292,6 +295,24 @@ func (client *FastUpdatesClient) Run(startBlock, endBlock uint64) error { } } + +func (client *FastUpdatesClient) GetBlockScoreCutoffWithRepeats(blockNum uint64) (*big.Int, error) { + var cutoff *big.Int + var err error + for i := 0; i < cutoffRepeats; i++ { + cutoff, err = client.GetBlockScoreCutoff(big.NewInt(int64(blockNum))) + if err == nil { + break + } + if blockNum <= client.transactionQueue.CurrentBlockNum-uint64(client.params.SubmissionWindow)+1 || i == cutoffRepeats-1 { + return nil, fmt.Errorf("Run: GetCurrentScoreCutoff for block %d: %w", blockNum, err) + } + time.Sleep(200 * time.Millisecond) + } + + return cutoff, err +} + func (client *FastUpdatesClient) WaitToEmptyRequests() { client.transactionQueue.WaitToEmptyQueue() } diff --git a/go-client/client/client_test.go b/go-client/client/client_test.go index b603bd2..d382812 100644 --- a/go-client/client/client_test.go +++ b/go-client/client/client_test.go @@ -19,10 +19,10 @@ import ( func TestClient(t *testing.T) { chainNode := os.Getenv("CHAIN_NODE") chainAddress := "" - valueProviderBaseUrl := "" + valueProviderUrl := "" if chainNode == "docker_ganache" { chainAddress = "http://ganache:8545" - valueProviderBaseUrl = "http://value-provider:3101" + valueProviderUrl = "http://value-provider:3101/feed-values/0" } else { // running a ganache node and an external provider that returns fixed values for testing logger.Info("starting a ganache chain node and data provider") @@ -34,7 +34,7 @@ func TestClient(t *testing.T) { go cmd.Run() //nolint:errcheck chainAddress = "http://127.0.0.1:8545" - valueProviderBaseUrl = "http://localhost:3101" + valueProviderUrl = "http://localhost:3101/feed-values/0" } // set chain parameters @@ -80,7 +80,7 @@ func TestClient(t *testing.T) { cfg.Client.MockAddress = contracts.Mock.Hex() cfg.Client.IncentiveManagerAddress = contracts.IncentiveManager.Hex() - updatesProvider := provider.NewHttpValueProvider(valueProviderBaseUrl) + updatesProvider := provider.NewHttpValueProvider(valueProviderUrl) client, err := client.CreateFastUpdatesClient(&cfg, updatesProvider) if err != nil { @@ -131,15 +131,11 @@ func TestClient(t *testing.T) { downDockerContainers() if client.Stats.NumUpdates == 0 { - if err != nil { - t.Fatal("no updates submitted") - } + t.Fatal("no updates submitted") } if client.Stats.NumSuccessfulUpdates == 0 { - if err != nil { - t.Fatal("no successful update") - } + t.Fatal("no successful update") } for i, val := range feeds {