@@ -8,10 +8,13 @@ import (
8
8
"slices"
9
9
"time"
10
10
11
+ "github.com/ChainSafe/gossamer/lib/crypto/ed25519"
12
+
11
13
"github.com/ChainSafe/gossamer/dot/network"
12
14
"github.com/ChainSafe/gossamer/dot/network/messages"
13
15
"github.com/ChainSafe/gossamer/dot/peerset"
14
16
"github.com/ChainSafe/gossamer/dot/types"
17
+ "github.com/ChainSafe/gossamer/internal/primitives/consensus/grandpa"
15
18
"github.com/ChainSafe/gossamer/lib/blocktree"
16
19
"github.com/ChainSafe/gossamer/lib/grandpa/warpsync"
17
20
"github.com/ChainSafe/gossamer/lib/runtime/storage"
@@ -35,6 +38,7 @@ type StateSyncStrategy struct {
35
38
reqMaker network.RequestMaker
36
39
blockReqMaker network.RequestMaker
37
40
blockState BlockState
41
+ grandpaState GrandpaState
38
42
storage StorageState
39
43
stateRequestProvider * StateRequestProvider
40
44
finalityGadget FinalityGadget
@@ -52,6 +56,7 @@ type StateSyncStrategyConfig struct {
52
56
Telemetry Telemetry
53
57
BadBlocks []string
54
58
BlockState BlockState
59
+ GrandpaState GrandpaState
55
60
Peers * peerViewSet
56
61
ReqMaker network.RequestMaker
57
62
BlockReqMaker network.RequestMaker
@@ -72,6 +77,7 @@ func NewStateSyncStrategy(
72
77
peers : cfg .Peers ,
73
78
badBlocks : cfg .BadBlocks ,
74
79
blockState : cfg .BlockState ,
80
+ grandpaState : cfg .GrandpaState ,
75
81
targetHeader : targetHeader ,
76
82
warpSyncResult : cfg .WarpSyncResult ,
77
83
reqMaker : cfg .ReqMaker ,
@@ -348,16 +354,33 @@ func (s *StateSyncStrategy) setBlockAsFullSyncStartingBlock() error {
348
354
}
349
355
350
356
/*
351
- TODO: solve this later
357
+ TODO: solve this - we need to marshal encode the justification
352
358
err = s.blockState.SetJustification(blockHeader.Hash(), *justification)
353
359
if err != nil {
354
360
return fmt.Errorf("setting justification for block number %d: %w", blockHeader.Number, err)
355
- }*/
361
+ }
362
+ */
363
+
364
+ err = s .grandpaState .SetAuthorities (uint64 (s .warpSyncResult .SetId ),
365
+ grandpaVotersFromAuthorities (s .warpSyncResult .AuthorityList ))
366
+ if err != nil {
367
+ return fmt .Errorf ("setting new authorities set: %w" , err )
368
+ }
356
369
357
- logger .Infof ("block finalized successfully %s" , s .targetHeader .Hash ())
358
- // TODO:
359
- // update authorities set
360
370
return nil
361
371
}
362
372
373
+ func grandpaVotersFromAuthorities (authorities grandpa.AuthorityList ) []types.GrandpaVoter {
374
+ voters := make ([]types.GrandpaVoter , len (authorities ))
375
+
376
+ for _ , auth := range authorities {
377
+ voters = append (voters , types.GrandpaVoter {
378
+ Key : ed25519 .PublicKey (auth .AuthorityID [:]),
379
+ ID : uint64 (auth .AuthorityWeight ),
380
+ })
381
+ }
382
+
383
+ return voters
384
+ }
385
+
363
386
var _ Strategy = (* StateSyncStrategy )(nil )
0 commit comments