Skip to content

Commit

Permalink
Improve behaviour when nodes are down (#2286)
Browse files Browse the repository at this point in the history
This PR only applies 'cl.UseNode' in the case '-multi' is used.
For simple transfers, two nodes are chosen randomly, thus avoiding
a failing transfer if one node is down.
  • Loading branch information
ineiti authored May 25, 2020
1 parent 88cb1b8 commit 7d07844
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions byzcoin/wallet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"strconv"
"time"

"go.dedis.ch/cothority/v3"
"go.dedis.ch/cothority/v3/byzcoin"
Expand Down Expand Up @@ -213,6 +215,10 @@ func transfer(c *cli.Context) error {
return err
}
balance = coin.Value
cfg.BCConfig.Roster = *resp.Proof.Latest.Roster
if err := cfg.save(); err != nil {
return fmt.Errorf("couldn't save new roster: %v", err)
}
}
if amount > balance {
return xerrors.New("your account doesn't have enough coins in it")
Expand All @@ -225,9 +231,18 @@ func transfer(c *cli.Context) error {
log.Warn("Only allowing 200 transactions at a time")
multi = 200
}
err = cl.UseNode(0)
if err != nil {
return err
if multi > 0 {
// For correct ordering of multiple transactions,
// it is important that all transactions are sent to the same node.
// Else they could be out-of-order and thus not match the correct
// counters.
node := rand.New(rand.NewSource(time.Now().UnixNano())).
Intn(len(cfg.BCConfig.Roster.List))
if err := cl.UseNode(node); err != nil {
return fmt.Errorf("couldn't set fixed node")
}
log.Info("Sending all transactions to node",
cfg.BCConfig.Roster.List[node], node)
}
for tx := 0; tx < multi; tx++ {
counters.Counters[0]++
Expand Down
2 changes: 1 addition & 1 deletion byzcoin/wallet/test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

DBG_TEST=1
DBG_SRV=2
DBG_SRV=1
DBG_BA=2

NBR_SERVERS=3
Expand Down

0 comments on commit 7d07844

Please sign in to comment.