Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit ea6867e

Browse files
author
GitHub
committed
Automatic update on Mon Aug 30 06:59:42 UTC 2021
1 parent c3b4af3 commit ea6867e

16 files changed

+150
-79
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/urfave/cli v1.22.3
88
go.dedis.ch/cothority/v3 v3.4.0
99
go.dedis.ch/kyber/v3 v3.0.13
10-
go.dedis.ch/onet/v3 v3.2.9
10+
go.dedis.ch/onet/v3 v3.2.10
1111
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
1212
)
1313

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
118118
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
119119
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
120120
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
121+
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
121122
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
122123
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
123124
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=

pkg/cothority/blscosi/protocol/protocol.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ func DefaultThreshold(n int) int {
9898
return n - DefaultFaultyThreshold(n)
9999
}
100100

101+
// DefaultSubLeaders returns the number of sub-leaders, which is the
102+
// cube-root of the number of nodes.
103+
func DefaultSubLeaders(nodes int) int {
104+
// As `math.Pow` calculates `8 ** (1/3) < 2`,
105+
// we add 0.0001 for the rounding error.
106+
// This works for up to 57 ** 3 = 185'193, which should be enough
107+
// nodes.
108+
return int(math.Pow(float64(nodes), 1.0/3.0) + 0.0001)
109+
}
110+
101111
// NewBlsCosi method is used to define the blscosi protocol.
102112
func NewBlsCosi(n *onet.TreeNodeInstance, vf VerificationFn, subProtocolName string, suite *pairing.SuiteBn256) (onet.ProtocolInstance, error) {
103113
nNodes := len(n.Roster().List)
@@ -173,8 +183,8 @@ func (p *BlsCosi) Start() error {
173183
}
174184

175185
if p.subTrees == nil {
176-
// the default number of subtree is the square root to
177-
// distribute the nodes evenly
186+
// the default number of subtrees is the square root of the number of
187+
// nodes to distribute the nodes evenly
178188
if err := p.SetNbrSubTree(int(math.Sqrt(float64(len(p.Roster().
179189
List))))); err != nil {
180190
p.Done()
@@ -409,7 +419,8 @@ func (p *BlsCosi) collectSignatures() (ResponseMap, error) {
409419
}
410420

411421
if p.checkFailureThreshold(numFailure) {
412-
return nil, fmt.Errorf("too many refusals (got %d), the threshold of %d cannot be achieved",
422+
return nil, fmt.Errorf("too many signature-refusals (got %d), "+
423+
"the threshold of %d cannot be achieved",
413424
numFailure, p.Threshold)
414425
}
415426

pkg/cothority/blscosi/protocol/protocol_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"flag"
66
"fmt"
7+
"math"
78
"testing"
89
"time"
910

@@ -188,6 +189,15 @@ func TestProtocol_FailingLeaves_25_9(t *testing.T) {
188189
require.NoError(t, err)
189190
}
190191

192+
func TestDefaultSubLeaders(t *testing.T) {
193+
require.Equal(t, DefaultSubLeaders(1), 1)
194+
for subleaders := 2; subleaders < 58; subleaders++ {
195+
nodes := int(math.Pow(float64(subleaders), 3.0))
196+
require.Equal(t, DefaultSubLeaders(nodes-1), subleaders-1)
197+
require.Equal(t, DefaultSubLeaders(nodes), subleaders)
198+
}
199+
}
200+
191201
func runProtocolFailingNodes(nbrNodes, nbrTrees, nbrFailure, threshold int) error {
192202
local := onet.NewLocalTest(testSuite)
193203
defer local.CloseAll()

pkg/cothority/byzcoin/api.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"math"
7+
"go.dedis.ch/cothority/v3/blscosi/protocol"
88
"math/rand"
99
"time"
1010

@@ -678,7 +678,7 @@ func (c *Client) DownloadState(byzcoinID skipchain.SkipBlockID, nonce uint64, le
678678
indexStart := 0
679679
if l > 3 {
680680
// This is the leader plus the subleaders, don't contact them
681-
indexStart = 1 + int(math.Ceil(math.Pow(float64(l), 1./3.)))
681+
indexStart = 1 + protocol.DefaultSubLeaders(l)
682682
}
683683

684684
msg := &DownloadState{
@@ -694,9 +694,12 @@ func (c *Client) DownloadState(byzcoinID skipchain.SkipBlockID, nonce uint64, le
694694
var po onet.ParallelOptions
695695
if c.options != nil {
696696
po = *c.options
697+
} else {
698+
po.Parallel = 1
699+
po.StartNode = indexStart
700+
po.DontShuffle = true
701+
po.AskNodes = 1
697702
}
698-
po.Parallel = 1
699-
po.StartNode = indexStart
700703
si, err = c.SendProtobufParallel(c.Roster.List, msg, reply, &po)
701704
err = cothority.ErrorOrNil(err, "request failed")
702705
c.noncesSI[reply.Nonce] = si

pkg/cothority/byzcoin/service.go

+54-38
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ func (s *Service) createUpgradeVersionBlock(scID skipchain.SkipBlockID, version
12581258
// and recreating it on the remote side.
12591259
// sb is a block in the byzcoin instance that we want
12601260
// to download.
1261-
func (s *Service) downloadDB(sb *skipchain.SkipBlock) error {
1261+
func (s *Service) downloadDB(sb *skipchain.SkipBlock, node int) error {
12621262
log.Lvlf2("%s: downloading DB", s.ServerIdentity())
12631263
idStr := fmt.Sprintf("%x", sb.SkipChainID())
12641264

@@ -1284,6 +1284,9 @@ func (s *Service) downloadDB(sb *skipchain.SkipBlock) error {
12841284
// Then start downloading the stateTrie over the network.
12851285
cl := NewClient(sb.SkipChainID(), *sb.Roster)
12861286
cl.DontContact(s.ServerIdentity())
1287+
if err := cl.UseNode(node); err != nil {
1288+
return xerrors.Errorf("While setting node: %v", err)
1289+
}
12871290
var db *bbolt.DB
12881291
var bucketName []byte
12891292
var nonce uint64
@@ -1395,37 +1398,53 @@ func (s *Service) catchupAll() error {
13951398

13961399
log.Lvlf2("Our latest block: %d / %x", sb.Index, sb.Hash)
13971400

1398-
cl := skipchain.NewClient()
1399-
// Get the latest block known by the Cothority.
1400-
var reply *skipchain.GetUpdateChainReply
1401-
for i, node := range sb.Roster.List {
1402-
cl.UseNode(i)
1403-
replyTmp, err := cl.GetUpdateChain(sb.Roster, sb.Hash)
1404-
if err != nil {
1405-
log.Warn("couldn't get update from", node)
1406-
continue
1407-
}
1408-
if reply == nil || len(replyTmp.Update) > len(reply.Update) {
1409-
reply = replyTmp
1410-
}
1401+
if err := s.catchupID(scID, sb.Roster); err != nil {
1402+
return xerrors.Errorf("couldn't catchup: %v", err)
14111403
}
1404+
}
1405+
return nil
1406+
}
14121407

1413-
if reply == nil {
1414-
// Might be that the other nodes are not yet up,
1415-
// so just continue with the other chains.
1416-
// Call to s.catchup will probably also fail, so skip it.
1417-
log.Error("couldn't get a new latest block")
1408+
// catchupID forces the download of the given ID and tries its best to use
1409+
// the given roster to download all necessary info.
1410+
func (s *Service) catchupID(scID skipchain.SkipBlockID, roster *onet.Roster) error {
1411+
cl := skipchain.NewClient()
1412+
// Get the latest block known by the Cothority.
1413+
var reply *skipchain.GetUpdateChainReply
1414+
for i, node := range roster.List {
1415+
log.Lvlf2("Asking node %s for latest block", node)
1416+
cl.UseNode(i)
1417+
replyTmp, err := cl.GetUpdateChain(roster, scID)
1418+
if err != nil {
1419+
log.Warn("couldn't get update from", node)
14181420
continue
14191421
}
1420-
1421-
if len(reply.Update) == 0 {
1422-
return xerrors.New("no block found in chain update")
1422+
if reply == nil {
1423+
reply = replyTmp
1424+
} else {
1425+
latestTmp := replyTmp.Update[len(replyTmp.Update)-1]
1426+
latest := reply.Update[len(reply.Update)-1]
1427+
if latestTmp.Index > latest.Index {
1428+
reply = replyTmp
1429+
}
14231430
}
1431+
}
14241432

1425-
sb = reply.Update[len(reply.Update)-1]
1426-
log.Lvl2("Catching up with latest block:", sb.Index)
1427-
s.catchUp(sb)
1433+
if reply == nil {
1434+
// Might be that the other nodes are not yet up,
1435+
// so just continue with the other chains.
1436+
// Call to s.catchup will probably also fail, so skip it.
1437+
log.Error("couldn't get a new latest block")
1438+
return nil
14281439
}
1440+
1441+
if len(reply.Update) == 0 {
1442+
return xerrors.New("no block found in chain update")
1443+
}
1444+
1445+
sb := reply.Update[len(reply.Update)-1]
1446+
log.Lvl2("Catching up with latest block:", sb.Index)
1447+
s.catchUp(sb)
14291448
return nil
14301449
}
14311450

@@ -1498,13 +1517,13 @@ func (s *Service) catchUp(sb *skipchain.SkipBlock) {
14981517

14991518
// Load the trie.
15001519
download := false
1501-
st, err := s.getStateTrie(sb.SkipChainID())
15021520
cl := skipchain.NewClient()
15031521
cl.DontContact(s.ServerIdentity())
1522+
st, err := s.getStateTrie(sb.SkipChainID())
15041523
if err != nil {
15051524
if sb.Index < catchupDownloadAll {
15061525
// Asked to catch up on an unknown chain, but don't want to download, instead only replay
1507-
// the blocks. This is mostly useful for testing, in a real deployement the catchupDownloadAll
1526+
// the blocks. This is mostly useful for testing, in a real deployment the catchupDownloadAll
15081527
// will be smaller than any chain that is online for more than a day.
15091528
log.Warnf("%s: problem with trie, "+
15101529
"will create a new one: %+v", s.ServerIdentity(), err)
@@ -1541,10 +1560,14 @@ func (s *Service) catchUp(sb *skipchain.SkipBlock) {
15411560

15421561
// Check if we are updating the right index.
15431562
if download {
1544-
log.Lvl2(s.ServerIdentity(), "Downloading whole DB for catching up")
1545-
err := s.downloadDB(sb)
1546-
if err != nil {
1547-
log.Error("Error while downloading trie:", err)
1563+
for i := range sb.Roster.List {
1564+
log.Lvl2(s.ServerIdentity(), "Downloading whole DB for catching up")
1565+
err := s.downloadDB(sb, i)
1566+
if err != nil {
1567+
log.Error("Error while downloading trie:", err)
1568+
} else {
1569+
return
1570+
}
15481571
}
15491572

15501573
// Note: in that case we don't get the previous blocks and therefore we can't
@@ -3126,13 +3149,6 @@ func newService(c *onet.Context) (onet.Service, error) {
31263149
return nil, xerrors.Errorf("unknown db version number %v", ver)
31273150
}
31283151

3129-
go func() {
3130-
// initialize the stats of the storage
3131-
if err := s.stateChangeStorage.calculateSize(); err != nil {
3132-
log.Errorf("couldn't calculate size: %v", err)
3133-
}
3134-
}()
3135-
31363152
if _, err := s.startAllChains(); err != nil {
31373153
return nil, xerrors.Errorf("starting chains: %v", err)
31383154
}

pkg/cothority/byzcoin/service_test.go

+25-1
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ func TestService_DownloadState(t *testing.T) {
21322132
servers, _, _ := b.Local.MakeSRS(cothority.Suite, 1, ByzCoinID)
21332133
services := b.Local.GetServices(servers, ByzCoinID)
21342134
service := services[0].(*Service)
2135-
err := service.downloadDB(b.Genesis)
2135+
err := service.downloadDB(b.Genesis, 0)
21362136
require.NoError(t, err)
21372137
st, err := service.getStateTrie(b.Genesis.Hash)
21382138
require.NoError(t, err)
@@ -2632,6 +2632,30 @@ func TestService_GetUpdates(t *testing.T) {
26322632
require.False(t, gur.Proofs[1].Match(invID[:]))
26332633
}
26342634

2635+
// Tests if it can add a byzcoin-instance to a given node.
2636+
func TestService_catchupID(t *testing.T) {
2637+
t.Skip("This is a manual test for the DEDIS chain")
2638+
2639+
b := newBCTRun(t, nil)
2640+
defer b.CloseAll()
2641+
2642+
dedisChain, err := hex.DecodeString("9cc36071ccb902a1de7e0d21a2c176d73894b1cf88ae4cc2ba4c95cd76f474f3")
2643+
require.NoError(t, err)
2644+
dedisRoster := onet.NewRoster([]*network.ServerIdentity{
2645+
{
2646+
URL: "https://conode.c4dt.org",
2647+
Public: cothority.Suite.Point(),
2648+
},
2649+
})
2650+
cl := skipchain.NewClient()
2651+
gcr, err := cl.GetUpdateChain(dedisRoster, dedisChain)
2652+
require.NoError(t, err)
2653+
dedisRoster = gcr.Update[len(gcr.Update)-1].Roster
2654+
2655+
err = b.Services[0].catchupID(dedisChain, dedisRoster)
2656+
require.NoError(t, err)
2657+
}
2658+
26352659
func createBadConfigTx(b *BCTest, intervalBad,
26362660
szBad bool) (ClientTransaction, ChainConfig) {
26372661
switch {

pkg/cothority/byzcoinx/byzcoinx.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package byzcoinx
88
import (
99
"errors"
1010
"fmt"
11-
"math"
1211
"time"
1312

1413
"go.dedis.ch/cothority/v3/blscosi/bdnproto"
@@ -133,11 +132,18 @@ func (bft *ByzCoinX) initCosiProtocol(phase phase) (*protocol.BlsCosi, error) {
133132
// For each of the prepare and commit phase we get half of the time.
134133
cosiProto.Timeout = bft.Timeout / 2
135134

136-
if bft.SubleaderFailures > 0 {
137-
// Only update the parameter if it is defined, else keep the default
138-
// value.
139-
cosiProto.SubleaderFailures = bft.SubleaderFailures
135+
if bft.SubleaderFailures == 0 && bft.Tree().Size() > 1 {
136+
// There can be as many failures as the biggest subtree has leafs.
137+
// The number of leafs is the following:
138+
// ceil( ( nodes - root - subleaders ) / subleaders )
139+
// which equals to
140+
// ( nodes - root - subleaders + subleaders - 1 ) / subleaders
141+
// which equals to
142+
// ( nodes - root - 1 )
143+
bft.SubleaderFailures = (bft.Tree().Size() - 2) /
144+
bft.nSubtrees
140145
}
146+
cosiProto.SubleaderFailures = bft.SubleaderFailures
141147

142148
return cosiProto, cosiProto.SetNbrSubTree(bft.nSubtrees)
143149
}
@@ -214,9 +220,7 @@ func NewByzCoinX(n *onet.TreeNodeInstance, prepCosiProtoName, commitCosiProtoNam
214220
publics: n.Publics(),
215221
suite: suite,
216222
verifier: verifier,
217-
// We set nSubtrees to the cube root of n to evenly distribute the load,
218-
// i.e. depth (=3) = log_f n, where f is the fan-out (branching factor).
219-
nSubtrees: int(math.Pow(float64(len(n.List())), 1.0/3.0)),
223+
nSubtrees: protocol.DefaultSubLeaders(len(n.List())),
220224
}, nil
221225
}
222226

pkg/cothority/byzcoinx/byzcoinx_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ func runProtocol(t *testing.T, nbrHosts int, nbrFault int, refuseIndex int, prot
199199
bftCosiProto.Threshold = nbrHosts - nbrFault
200200
log.Lvl3("Added counter", counters.size()-1, refuseIndex)
201201

202-
require.Equal(t, bftCosiProto.nSubtrees, int(math.Pow(float64(nbrHosts), 1.0/3.0)))
202+
require.True(t, int(math.Pow(float64(bftCosiProto.nSubtrees),
203+
3.0)) <= nbrHosts)
203204

204205
// kill the leafs first
205206
nbrFault = min(nbrFault, len(servers))

pkg/cothority/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
github.com/syndtr/goleveldb v1.0.0 // indirect
4747
github.com/urfave/cli v1.22.3
4848
go.dedis.ch/kyber/v3 v3.0.13
49-
go.dedis.ch/onet/v3 v3.2.9
49+
go.dedis.ch/onet/v3 v3.2.10
5050
go.dedis.ch/protobuf v1.0.11
5151
go.etcd.io/bbolt v1.3.4
5252
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect

pkg/cothority/go.sum

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
127127
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
128128
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
129129
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
130-
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
130+
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
131131
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
132132
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
133133
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
@@ -254,8 +254,8 @@ go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhs
254254
go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg=
255255
go.dedis.ch/kyber/v3 v3.0.13 h1:s5Lm8p2/CsTMueQHCN24gPpZ4couBBeKU7r2Yl6r32o=
256256
go.dedis.ch/kyber/v3 v3.0.13/go.mod h1:kXy7p3STAurkADD+/aZcsznZGKVHEqbtmdIzvPfrs1U=
257-
go.dedis.ch/onet/v3 v3.2.9 h1:JwSjsWLCNhXIL8vFkelhMAXappyQoVXSJ1XXpTKBC3w=
258-
go.dedis.ch/onet/v3 v3.2.9/go.mod h1:uYgAS2Jr2h3wGctG+C/lokYY1o8rRqTN+taoiK5jdb8=
257+
go.dedis.ch/onet/v3 v3.2.10 h1:922Do54I7qxANwTuGcLEcOIzXH8n0FuEnZlmS37bmjU=
258+
go.dedis.ch/onet/v3 v3.2.10/go.mod h1:2TpqrnrRcefCXQuoU5OPmDtUJZGLvIVc1ZKW9NpOTsY=
259259
go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo=
260260
go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4=
261261
go.dedis.ch/protobuf v1.0.11 h1:FTYVIEzY/bfl37lu3pR4lIj+F9Vp1jE8oh91VmxKgLo=

pkg/onet/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995 // indirect
1111
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e // indirect
1212
github.com/google/uuid v1.1.2
13-
github.com/gorilla/websocket v1.4.0
13+
github.com/gorilla/websocket v1.4.1
1414
github.com/honeycombio/beeline-go v0.4.11
1515
github.com/honeycombio/libhoney-go v1.12.3 // indirect
1616
github.com/klauspost/compress v1.10.3 // indirect

0 commit comments

Comments
 (0)