forked from ChainSafe/gossamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.go
699 lines (568 loc) · 19.7 KB
/
block.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
// Copyright 2019 ChainSafe Systems (ON) Corp.
// This file is part of gossamer.
//
// The gossamer library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The gossamer library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the gossamer library. If not, see <http://www.gnu.org/licenses/>.
package state
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"math/big"
"sync"
"time"
"github.com/ChainSafe/chaindb"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/blocktree"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/pkg/scale"
rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
)
const (
pruneKeyBufferSize = 1000
blockPrefix = "block"
)
var (
headerPrefix = []byte("hdr") // headerPrefix + hash -> header
blockBodyPrefix = []byte("blb") // blockBodyPrefix + hash -> body
headerHashPrefix = []byte("hsh") // headerHashPrefix + encodedBlockNum -> hash
arrivalTimePrefix = []byte("arr") // arrivalTimePrefix || hash -> arrivalTime
receiptPrefix = []byte("rcp") // receiptPrefix + hash -> receipt
messageQueuePrefix = []byte("mqp") // messageQueuePrefix + hash -> message queue
justificationPrefix = []byte("jcp") // justificationPrefix + hash -> justification
errNilBlockBody = errors.New("block body is nil")
)
// BlockState contains the historical block data of the blockchain, including block headers and bodies.
// It wraps the blocktree (which contains unfinalised blocks) and the database (which contains finalised blocks).
type BlockState struct {
bt *blocktree.BlockTree
baseState *BaseState
dbPath string
db chaindb.Database
sync.RWMutex
genesisHash common.Hash
lastFinalised common.Hash
unfinalisedBlocks *sync.Map // map[common.Hash]*types.Block
// block notifiers
imported map[chan *types.Block]struct{}
finalised map[chan *types.FinalisationInfo]struct{}
finalisedLock sync.RWMutex
importedLock sync.RWMutex
runtimeUpdateSubscriptionsLock sync.RWMutex
runtimeUpdateSubscriptions map[uint32]chan<- runtime.Version
pruneKeyCh chan *types.Header
}
// NewBlockState will create a new BlockState backed by the database located at basePath
func NewBlockState(db chaindb.Database) (*BlockState, error) {
bs := &BlockState{
dbPath: db.Path(),
baseState: NewBaseState(db),
db: chaindb.NewTable(db, blockPrefix),
unfinalisedBlocks: new(sync.Map),
imported: make(map[chan *types.Block]struct{}),
finalised: make(map[chan *types.FinalisationInfo]struct{}),
pruneKeyCh: make(chan *types.Header, pruneKeyBufferSize),
runtimeUpdateSubscriptions: make(map[uint32]chan<- runtime.Version),
}
gh, err := bs.db.Get(headerHashKey(0))
if err != nil {
return nil, fmt.Errorf("cannot get block 0: %w", err)
}
genesisHash := common.NewHash(gh)
header, err := bs.GetHighestFinalisedHeader()
if err != nil {
return nil, fmt.Errorf("failed to get last finalised header: %w", err)
}
bs.genesisHash = genesisHash
bs.lastFinalised = header.Hash()
bs.bt = blocktree.NewBlockTreeFromRoot(header)
return bs, nil
}
// NewBlockStateFromGenesis initialises a BlockState from a genesis header, saving it to the database located at basePath
func NewBlockStateFromGenesis(db chaindb.Database, header *types.Header) (*BlockState, error) {
bs := &BlockState{
bt: blocktree.NewBlockTreeFromRoot(header),
baseState: NewBaseState(db),
db: chaindb.NewTable(db, blockPrefix),
unfinalisedBlocks: new(sync.Map),
imported: make(map[chan *types.Block]struct{}),
finalised: make(map[chan *types.FinalisationInfo]struct{}),
pruneKeyCh: make(chan *types.Header, pruneKeyBufferSize),
runtimeUpdateSubscriptions: make(map[uint32]chan<- runtime.Version),
genesisHash: header.Hash(),
lastFinalised: header.Hash(),
}
if err := bs.setArrivalTime(header.Hash(), time.Now()); err != nil {
return nil, err
}
if err := bs.SetHeader(header); err != nil {
return nil, err
}
if err := bs.db.Put(headerHashKey(header.Number.Uint64()), header.Hash().ToBytes()); err != nil {
return nil, err
}
if err := bs.SetBlockBody(header.Hash(), types.NewBody([]types.Extrinsic{})); err != nil {
return nil, err
}
bs.genesisHash = header.Hash()
bs.lastFinalised = header.Hash()
if err := bs.db.Put(highestRoundAndSetIDKey, roundAndSetIDToBytes(0, 0)); err != nil {
return nil, err
}
// set the latest finalised head to the genesis header
if err := bs.SetFinalisedHash(bs.genesisHash, 0, 0); err != nil {
return nil, err
}
return bs, nil
}
// encodeBlockNumber encodes a block number as big endian uint64
func encodeBlockNumber(number uint64) []byte {
enc := make([]byte, 8) // encoding results in 8 bytes
binary.BigEndian.PutUint64(enc, number)
return enc
}
// headerKey = headerPrefix + hash
func headerKey(hash common.Hash) []byte {
return append(headerPrefix, hash.ToBytes()...)
}
// headerHashKey = headerHashPrefix + num (uint64 big endian)
func headerHashKey(number uint64) []byte {
return append(headerHashPrefix, encodeBlockNumber(number)...)
}
// blockBodyKey = blockBodyPrefix + hash
func blockBodyKey(hash common.Hash) []byte {
return append(blockBodyPrefix, hash.ToBytes()...)
}
// arrivalTimeKey = arrivalTimePrefix + hash
func arrivalTimeKey(hash common.Hash) []byte {
return append(arrivalTimePrefix, hash.ToBytes()...)
}
// GenesisHash returns the hash of the genesis block
func (bs *BlockState) GenesisHash() common.Hash {
return bs.genesisHash
}
func (bs *BlockState) storeUnfinalisedBlock(block *types.Block) {
bs.unfinalisedBlocks.Store(block.Header.Hash(), block)
}
func (bs *BlockState) hasUnfinalisedBlock(hash common.Hash) bool {
_, has := bs.unfinalisedBlocks.Load(hash)
return has
}
func (bs *BlockState) getUnfinalisedHeader(hash common.Hash) (*types.Header, bool) {
block, has := bs.getUnfinalisedBlock(hash)
if !has {
return nil, false
}
return &block.Header, true
}
func (bs *BlockState) getUnfinalisedBlock(hash common.Hash) (*types.Block, bool) {
block, has := bs.unfinalisedBlocks.Load(hash)
if !has {
return nil, false
}
// TODO: dot/core tx re-org test seems to abort here due to block body being invalid?
return block.(*types.Block), true
}
func (bs *BlockState) getAndDeleteUnfinalisedBlock(hash common.Hash) (*types.Block, bool) {
block, has := bs.unfinalisedBlocks.LoadAndDelete(hash)
if !has {
return nil, false
}
return block.(*types.Block), true
}
// HasHeader returns if the db contains a header with the given hash
func (bs *BlockState) HasHeader(hash common.Hash) (bool, error) {
if bs.hasUnfinalisedBlock(hash) {
return true, nil
}
return bs.db.Has(headerKey(hash))
}
// GetHeader returns a BlockHeader for a given hash
func (bs *BlockState) GetHeader(hash common.Hash) (*types.Header, error) {
header, has := bs.getUnfinalisedHeader(hash)
if has {
return header, nil
}
result := types.NewEmptyHeader()
if bs.db == nil {
return nil, fmt.Errorf("database is nil")
}
if has, _ := bs.HasHeader(hash); !has {
return nil, chaindb.ErrKeyNotFound
}
data, err := bs.db.Get(headerKey(hash))
if err != nil {
return nil, err
}
err = scale.Unmarshal(data, result)
if err != nil {
return nil, err
}
if result.Empty() {
return nil, chaindb.ErrKeyNotFound
}
result.Hash()
return result, nil
}
// GetHashByNumber returns the block hash on our best chain with the given number
func (bs *BlockState) GetHashByNumber(num *big.Int) (common.Hash, error) {
hash, err := bs.bt.GetHashByNumber(num)
if err == nil {
return hash, nil
} else if !errors.Is(err, blocktree.ErrNumLowerThanRoot) {
return common.Hash{}, fmt.Errorf("failed to get hash from blocktree: %w", err)
}
// if error is ErrNumLowerThanRoot, number has already been finalised, so check db
bh, err := bs.db.Get(headerHashKey(num.Uint64()))
if err != nil {
return common.Hash{}, fmt.Errorf("cannot get block %d: %w", num, err)
}
return common.NewHash(bh), nil
}
// GetHeaderByNumber returns the block header on our best chain with the given number
func (bs *BlockState) GetHeaderByNumber(num *big.Int) (*types.Header, error) {
hash, err := bs.GetHashByNumber(num)
if err != nil {
return nil, err
}
return bs.GetHeader(hash)
}
// GetBlockByNumber returns the block on our best chain with the given number
func (bs *BlockState) GetBlockByNumber(num *big.Int) (*types.Block, error) {
hash, err := bs.GetHashByNumber(num)
if err != nil {
return nil, err
}
block, err := bs.GetBlockByHash(hash)
if err != nil {
return nil, err
}
return block, nil
}
// GetBlockByHash returns a block for a given hash
func (bs *BlockState) GetBlockByHash(hash common.Hash) (*types.Block, error) {
bs.RLock()
defer bs.RUnlock()
block, has := bs.getUnfinalisedBlock(hash)
if has {
return block, nil
}
header, err := bs.GetHeader(hash)
if err != nil {
return nil, err
}
blockBody, err := bs.GetBlockBody(hash)
if err != nil {
return nil, err
}
return &types.Block{Header: *header, Body: *blockBody}, nil
}
// GetBlockHash returns block hash for a given block number
// TODO: remove in favour of GetHashByNumber
func (bs *BlockState) GetBlockHash(num *big.Int) (common.Hash, error) {
return bs.GetHashByNumber(num)
}
// SetHeader will set the header into DB
func (bs *BlockState) SetHeader(header *types.Header) error {
bh, err := scale.Marshal(*header)
if err != nil {
return err
}
return bs.db.Put(headerKey(header.Hash()), bh)
}
// HasBlockBody returns true if the db contains the block body
func (bs *BlockState) HasBlockBody(hash common.Hash) (bool, error) {
bs.RLock()
defer bs.RUnlock()
if bs.hasUnfinalisedBlock(hash) {
return true, nil
}
return bs.db.Has(blockBodyKey(hash))
}
// GetBlockBody will return Body for a given hash
func (bs *BlockState) GetBlockBody(hash common.Hash) (*types.Body, error) {
block, has := bs.getUnfinalisedBlock(hash)
if has {
return &block.Body, nil
}
data, err := bs.db.Get(blockBodyKey(hash))
if err != nil {
return nil, err
}
return types.NewBodyFromBytes(data)
}
// SetBlockBody will add a block body to the db
func (bs *BlockState) SetBlockBody(hash common.Hash, body *types.Body) error {
encodedBody, err := scale.Marshal(*body)
if err != nil {
return err
}
return bs.db.Put(blockBodyKey(hash), encodedBody)
}
// CompareAndSetBlockData will compare empty fields and set all elements in a block data to db
func (bs *BlockState) CompareAndSetBlockData(bd *types.BlockData) error {
hasReceipt, _ := bs.HasReceipt(bd.Hash)
if bd.Receipt != nil && !hasReceipt {
err := bs.SetReceipt(bd.Hash, *bd.Receipt)
if err != nil {
return err
}
}
hasMessageQueue, _ := bs.HasMessageQueue(bd.Hash)
if bd.MessageQueue != nil && !hasMessageQueue {
err := bs.SetMessageQueue(bd.Hash, *bd.MessageQueue)
if err != nil {
return err
}
}
return nil
}
// AddBlock adds a block to the blocktree and the DB with arrival time as current unix time
func (bs *BlockState) AddBlock(block *types.Block) error {
bs.Lock()
defer bs.Unlock()
return bs.AddBlockWithArrivalTime(block, time.Now())
}
// AddBlockWithArrivalTime adds a block to the blocktree and the DB with the given arrival time
func (bs *BlockState) AddBlockWithArrivalTime(block *types.Block, arrivalTime time.Time) error {
if block.Body == nil {
return errNilBlockBody
}
// add block to blocktree
if err := bs.bt.AddBlock(&block.Header, arrivalTime); err != nil {
return err
}
bs.storeUnfinalisedBlock(block)
go bs.notifyImported(block)
return nil
}
// AddBlockToBlockTree adds the given block to the blocktree. It does not write it to the database.
// TODO: remove this func and usage from sync (after sync refactor?)
func (bs *BlockState) AddBlockToBlockTree(block *types.Block) error {
bs.Lock()
defer bs.Unlock()
arrivalTime, err := bs.GetArrivalTime(block.Header.Hash())
if err != nil {
arrivalTime = time.Now()
}
bs.storeUnfinalisedBlock(block)
return bs.bt.AddBlock(&block.Header, arrivalTime)
}
// GetAllBlocksAtNumber returns all unfinalised blocks with the given number
func (bs *BlockState) GetAllBlocksAtNumber(num *big.Int) ([]common.Hash, error) {
header, err := bs.GetHeaderByNumber(num)
if err != nil {
return nil, err
}
return bs.GetAllBlocksAtDepth(header.ParentHash), nil
}
// GetAllBlocksAtDepth returns all hashes with the depth of the given hash plus one
func (bs *BlockState) GetAllBlocksAtDepth(hash common.Hash) []common.Hash {
return bs.bt.GetAllBlocksAtNumber(hash)
}
func (bs *BlockState) isBlockOnCurrentChain(header *types.Header) (bool, error) {
bestBlock, err := bs.BestBlockHeader()
if err != nil {
return false, err
}
// if the new block is ahead of our best block, then it is on our current chain.
if header.Number.Cmp(bestBlock.Number) > 0 {
return true, nil
}
is, err := bs.IsDescendantOf(header.Hash(), bestBlock.Hash())
if err != nil {
return false, err
}
if !is {
return false, nil
}
return true, nil
}
// BestBlockHash returns the hash of the head of the current chain
func (bs *BlockState) BestBlockHash() common.Hash {
if bs.bt == nil {
return common.Hash{}
}
return bs.bt.DeepestBlockHash()
}
// BestBlockHeader returns the block header of the current head of the chain
func (bs *BlockState) BestBlockHeader() (*types.Header, error) {
return bs.GetHeader(bs.BestBlockHash())
}
// BestBlockStateRoot returns the state root of the current head of the chain
func (bs *BlockState) BestBlockStateRoot() (common.Hash, error) {
header, err := bs.GetHeader(bs.BestBlockHash())
if err != nil {
return common.Hash{}, err
}
return header.StateRoot, nil
}
// GetBlockStateRoot returns the state root of the given block hash
func (bs *BlockState) GetBlockStateRoot(bhash common.Hash) (
hash common.Hash, err error) {
header, err := bs.GetHeader(bhash)
if err != nil {
return hash, err
}
return header.StateRoot, nil
}
// BestBlockNumber returns the block number of the current head of the chain
func (bs *BlockState) BestBlockNumber() (*big.Int, error) {
header, err := bs.GetHeader(bs.BestBlockHash())
if err != nil {
return nil, err
}
if header == nil {
return nil, fmt.Errorf("failed to get best block header")
}
return header.Number, nil
}
// BestBlock returns the current head of the chain
func (bs *BlockState) BestBlock() (*types.Block, error) {
return bs.GetBlockByHash(bs.BestBlockHash())
}
// GetSlotForBlock returns the slot for a block
func (bs *BlockState) GetSlotForBlock(hash common.Hash) (uint64, error) {
header, err := bs.GetHeader(hash)
if err != nil {
return 0, err
}
return types.GetSlotFromHeader(header)
}
// SubChain returns the sub-blockchain between the starting hash and the ending hash using the block tree
func (bs *BlockState) SubChain(start, end common.Hash) ([]common.Hash, error) {
if bs.bt == nil {
return nil, fmt.Errorf("blocktree is nil")
}
return bs.bt.SubBlockchain(start, end)
}
// IsDescendantOf returns true if child is a descendant of parent, false otherwise.
// it returns an error if parent or child are not in the blocktree.
func (bs *BlockState) IsDescendantOf(parent, child common.Hash) (bool, error) {
if bs.bt == nil {
return false, fmt.Errorf("blocktree is nil")
}
return bs.bt.IsDescendantOf(parent, child)
}
// HighestCommonAncestor returns the block with the highest number that is an ancestor of both a and b
func (bs *BlockState) HighestCommonAncestor(a, b common.Hash) (common.Hash, error) {
return bs.bt.HighestCommonAncestor(a, b)
}
// Leaves returns the leaves of the blocktree as an array
func (bs *BlockState) Leaves() []common.Hash {
return bs.bt.Leaves()
}
// BlocktreeAsString returns the blocktree as a string
func (bs *BlockState) BlocktreeAsString() string {
return bs.bt.String()
}
// GetArrivalTime returns the arrival time in nanoseconds since the Unix epoch of a block given its hash
func (bs *BlockState) GetArrivalTime(hash common.Hash) (time.Time, error) {
at, err := bs.bt.GetArrivalTime(hash)
if err == nil {
return at, nil
}
arrivalTime, err := bs.db.Get(arrivalTimeKey(hash))
if err != nil {
return time.Time{}, err
}
ns := binary.LittleEndian.Uint64(arrivalTime)
return time.Unix(0, int64(ns)), nil
}
func (bs *BlockState) setArrivalTime(hash common.Hash, arrivalTime time.Time) error {
buf := make([]byte, 8)
binary.LittleEndian.PutUint64(buf, uint64(arrivalTime.UnixNano()))
return bs.db.Put(arrivalTimeKey(hash), buf)
}
// HandleRuntimeChanges handles the update in runtime.
func (bs *BlockState) HandleRuntimeChanges(newState *rtstorage.TrieState, rt runtime.Instance, bHash common.Hash) error {
currCodeHash, err := newState.LoadCodeHash()
if err != nil {
return err
}
codeHash := rt.GetCodeHash()
if bytes.Equal(codeHash[:], currCodeHash[:]) {
bs.StoreRuntime(bHash, rt)
return nil
}
logger.Info("🔄 detected runtime code change, upgrading...", "block", bHash, "previous code hash", codeHash, "new code hash", currCodeHash)
code := newState.LoadCode()
if len(code) == 0 {
return errors.New("new :code is empty")
}
codeSubBlockHash := bs.baseState.LoadCodeSubstitutedBlockHash()
if !codeSubBlockHash.Equal(common.Hash{}) {
newVersion, err := rt.CheckRuntimeVersion(code) //nolint
if err != nil {
return err
}
// only update runtime during code substitution if runtime SpecVersion is updated
previousVersion, _ := rt.Version()
if previousVersion.SpecVersion() == newVersion.SpecVersion() {
logger.Info("not upgrading runtime code during code substitution")
bs.StoreRuntime(bHash, rt)
return nil
}
logger.Info("🔄 detected runtime code change, upgrading...", "block", bHash,
"previous code hash", codeHash, "new code hash", currCodeHash,
"previous spec version", previousVersion.SpecVersion(), "new spec version", newVersion.SpecVersion())
}
rtCfg := &wasmer.Config{
Imports: wasmer.ImportsNodeRuntime,
}
rtCfg.Storage = newState
rtCfg.Keystore = rt.Keystore()
rtCfg.NodeStorage = rt.NodeStorage()
rtCfg.Network = rt.NetworkService()
rtCfg.CodeHash = currCodeHash
if rt.Validator() {
rtCfg.Role = 4
}
instance, err := wasmer.NewInstance(code, rtCfg)
if err != nil {
return err
}
bs.StoreRuntime(bHash, instance)
err = bs.baseState.StoreCodeSubstitutedBlockHash(common.Hash{})
if err != nil {
return fmt.Errorf("failed to update code substituted block hash: %w", err)
}
newVersion, err := rt.Version()
if err != nil {
return fmt.Errorf("failed to retrieve runtime version: %w", err)
}
go bs.notifyRuntimeUpdated(newVersion)
return nil
}
// GetRuntime gets the runtime for the corresponding block hash.
func (bs *BlockState) GetRuntime(hash *common.Hash) (runtime.Instance, error) {
if hash == nil {
rt, err := bs.bt.GetBlockRuntime(bs.BestBlockHash())
if err != nil {
return nil, err
}
return rt, nil
}
return bs.bt.GetBlockRuntime(*hash)
}
// StoreRuntime stores the runtime for corresponding block hash.
func (bs *BlockState) StoreRuntime(hash common.Hash, rt runtime.Instance) {
bs.bt.StoreRuntime(hash, rt)
}
// GetNonFinalisedBlocks get all the blocks in the blocktree
func (bs *BlockState) GetNonFinalisedBlocks() []common.Hash {
return bs.bt.GetAllBlocks()
}