forked from btcsuite/btcd
-
Notifications
You must be signed in to change notification settings - Fork 5
/
estimatefee.go
749 lines (596 loc) · 20.1 KB
/
estimatefee.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
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
// Copyright (c) 2016 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package mempool
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"math"
"math/rand"
"sort"
"strings"
"sync"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/mining"
"github.com/btcsuite/btcutil"
)
// TODO incorporate Alex Morcos' modifications to Gavin's initial model
// https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2014-October/006824.html
const (
// estimateFeeDepth is the maximum number of blocks before a transaction
// is confirmed that we want to track.
estimateFeeDepth = 25
// estimateFeeBinSize is the number of txs stored in each bin.
estimateFeeBinSize = 100
// estimateFeeMaxReplacements is the max number of replacements that
// can be made by the txs found in a given block.
estimateFeeMaxReplacements = 10
// DefaultEstimateFeeMaxRollback is the default number of rollbacks
// allowed by the fee estimator for orphaned blocks.
DefaultEstimateFeeMaxRollback = 2
// DefaultEstimateFeeMinRegisteredBlocks is the default minimum
// number of blocks which must be observed by the fee estimator before
// it will provide fee estimations.
DefaultEstimateFeeMinRegisteredBlocks = 3
bytePerKb = 1000
btcPerSatoshi = 1E-8
)
var (
// EstimateFeeDatabaseKey is the key that we use to
// store the fee estimator in the database.
EstimateFeeDatabaseKey = []byte("estimatefee")
)
// SatoshiPerByte is number with units of satoshis per byte.
type SatoshiPerByte float64
// BtcPerKilobyte is number with units of bitcoins per kilobyte.
type BtcPerKilobyte float64
// ToBtcPerKb returns a float value that represents the given
// SatoshiPerByte converted to satoshis per kb.
func (rate SatoshiPerByte) ToBtcPerKb() BtcPerKilobyte {
// If our rate is the error value, return that.
if rate == SatoshiPerByte(-1.0) {
return -1.0
}
return BtcPerKilobyte(float64(rate) * bytePerKb * btcPerSatoshi)
}
// Fee returns the fee for a transaction of a given size for
// the given fee rate.
func (rate SatoshiPerByte) Fee(size uint32) btcutil.Amount {
// If our rate is the error value, return that.
if rate == SatoshiPerByte(-1) {
return btcutil.Amount(-1)
}
return btcutil.Amount(float64(rate) * float64(size))
}
// NewSatoshiPerByte creates a SatoshiPerByte from an Amount and a
// size in bytes.
func NewSatoshiPerByte(fee btcutil.Amount, size uint32) SatoshiPerByte {
return SatoshiPerByte(float64(fee) / float64(size))
}
// observedTransaction represents an observed transaction and some
// additional data required for the fee estimation algorithm.
type observedTransaction struct {
// A transaction hash.
hash chainhash.Hash
// The fee per byte of the transaction in satoshis.
feeRate SatoshiPerByte
// The block height when it was observed.
observed int32
// The height of the block in which it was mined.
// If the transaction has not yet been mined, it is zero.
mined int32
}
func (o *observedTransaction) Serialize(w io.Writer) {
binary.Write(w, binary.BigEndian, o.hash)
binary.Write(w, binary.BigEndian, o.feeRate)
binary.Write(w, binary.BigEndian, o.observed)
binary.Write(w, binary.BigEndian, o.mined)
}
func deserializeObservedTransaction(r io.Reader) (*observedTransaction, error) {
ot := observedTransaction{}
// The first 32 bytes should be a hash.
binary.Read(r, binary.BigEndian, &ot.hash)
// The next 8 are SatoshiPerByte
binary.Read(r, binary.BigEndian, &ot.feeRate)
// And next there are two uint32's.
binary.Read(r, binary.BigEndian, &ot.observed)
binary.Read(r, binary.BigEndian, &ot.mined)
return &ot, nil
}
// registeredBlock has the hash of a block and the list of transactions
// it mined which had been previously observed by the FeeEstimator. It
// is used if Rollback is called to reverse the effect of registering
// a block.
type registeredBlock struct {
hash chainhash.Hash
transactions []*observedTransaction
}
func (rb *registeredBlock) serialize(w io.Writer, txs map[*observedTransaction]uint32) {
binary.Write(w, binary.BigEndian, rb.hash)
binary.Write(w, binary.BigEndian, uint32(len(rb.transactions)))
for _, o := range rb.transactions {
binary.Write(w, binary.BigEndian, txs[o])
}
}
// FeeEstimator manages the data necessary to create
// fee estimations. It is safe for concurrent access.
type FeeEstimator struct {
maxRollback uint32
binSize int32
// The maximum number of replacements that can be made in a single
// bin per block. Default is estimateFeeMaxReplacements
maxReplacements int32
// The minimum number of blocks that can be registered with the fee
// estimator before it will provide answers.
minRegisteredBlocks uint32
// The last known height.
lastKnownHeight int32
// The number of blocks that have been registered.
numBlocksRegistered uint32
mtx sync.RWMutex
observed map[chainhash.Hash]*observedTransaction
bin [estimateFeeDepth][]*observedTransaction
// The cached estimates.
cached []SatoshiPerByte
// Transactions that have been removed from the bins. This allows us to
// revert in case of an orphaned block.
dropped []*registeredBlock
}
// NewFeeEstimator creates a FeeEstimator for which at most maxRollback blocks
// can be unregistered and which returns an error unless minRegisteredBlocks
// have been registered with it.
func NewFeeEstimator(maxRollback, minRegisteredBlocks uint32) *FeeEstimator {
return &FeeEstimator{
maxRollback: maxRollback,
minRegisteredBlocks: minRegisteredBlocks,
lastKnownHeight: mining.UnminedHeight,
binSize: estimateFeeBinSize,
maxReplacements: estimateFeeMaxReplacements,
observed: make(map[chainhash.Hash]*observedTransaction),
dropped: make([]*registeredBlock, 0, maxRollback),
}
}
// ObserveTransaction is called when a new transaction is observed in the mempool.
func (ef *FeeEstimator) ObserveTransaction(t *TxDesc) {
ef.mtx.Lock()
defer ef.mtx.Unlock()
// If we haven't seen a block yet we don't know when this one arrived,
// so we ignore it.
if ef.lastKnownHeight == mining.UnminedHeight {
return
}
hash := *t.Tx.Hash()
if _, ok := ef.observed[hash]; !ok {
size := uint32(GetTxVirtualSize(t.Tx))
ef.observed[hash] = &observedTransaction{
hash: hash,
feeRate: NewSatoshiPerByte(btcutil.Amount(t.Fee), size),
observed: t.Height,
mined: mining.UnminedHeight,
}
}
}
// RegisterBlock informs the fee estimator of a new block to take into account.
func (ef *FeeEstimator) RegisterBlock(block *btcutil.Block) error {
ef.mtx.Lock()
defer ef.mtx.Unlock()
// The previous sorted list is invalid, so delete it.
ef.cached = nil
height := block.Height()
if height != ef.lastKnownHeight+1 && ef.lastKnownHeight != mining.UnminedHeight {
return fmt.Errorf("intermediate block not recorded; current height is %d; new height is %d",
ef.lastKnownHeight, height)
}
// Update the last known height.
ef.lastKnownHeight = height
ef.numBlocksRegistered++
// Randomly order txs in block.
transactions := make(map[*btcutil.Tx]struct{})
for _, t := range block.Transactions() {
transactions[t] = struct{}{}
}
// Count the number of replacements we make per bin so that we don't
// replace too many.
var replacementCounts [estimateFeeDepth]int
// Keep track of which txs were dropped in case of an orphan block.
dropped := ®isteredBlock{
hash: *block.Hash(),
transactions: make([]*observedTransaction, 0, 100),
}
// Go through the txs in the block.
for t := range transactions {
hash := *t.Hash()
// Have we observed this tx in the mempool?
o, ok := ef.observed[hash]
if !ok {
continue
}
// Put the observed tx in the oppropriate bin.
blocksToConfirm := height - o.observed - 1
// This shouldn't happen if the fee estimator works correctly,
// but return an error if it does.
if o.mined != mining.UnminedHeight {
log.Error("Estimate fee: transaction ", hash.String(), " has already been mined")
return errors.New("Transaction has already been mined")
}
// This shouldn't happen but check just in case to avoid
// an out-of-bounds array index later.
if blocksToConfirm >= estimateFeeDepth {
continue
}
// Make sure we do not replace too many transactions per min.
if replacementCounts[blocksToConfirm] == int(ef.maxReplacements) {
continue
}
o.mined = height
replacementCounts[blocksToConfirm]++
bin := ef.bin[blocksToConfirm]
// Remove a random element and replace it with this new tx.
if len(bin) == int(ef.binSize) {
// Don't drop transactions we have just added from this same block.
l := int(ef.binSize) - replacementCounts[blocksToConfirm]
drop := rand.Intn(l)
dropped.transactions = append(dropped.transactions, bin[drop])
bin[drop] = bin[l-1]
bin[l-1] = o
} else {
bin = append(bin, o)
}
ef.bin[blocksToConfirm] = bin
}
// Go through the mempool for txs that have been in too long.
for hash, o := range ef.observed {
if o.mined == mining.UnminedHeight && height-o.observed >= estimateFeeDepth {
delete(ef.observed, hash)
}
}
// Add dropped list to history.
if ef.maxRollback == 0 {
return nil
}
if uint32(len(ef.dropped)) == ef.maxRollback {
ef.dropped = append(ef.dropped[1:], dropped)
} else {
ef.dropped = append(ef.dropped, dropped)
}
return nil
}
// LastKnownHeight returns the height of the last block which was registered.
func (ef *FeeEstimator) LastKnownHeight() int32 {
ef.mtx.Lock()
defer ef.mtx.Unlock()
return ef.lastKnownHeight
}
// Rollback unregisters a recently registered block from the FeeEstimator.
// This can be used to reverse the effect of an orphaned block on the fee
// estimator. The maximum number of rollbacks allowed is given by
// maxRollbacks.
//
// Note: not everything can be rolled back because some transactions are
// deleted if they have been observed too long ago. That means the result
// of Rollback won't always be exactly the same as if the last block had not
// happened, but it should be close enough.
func (ef *FeeEstimator) Rollback(hash *chainhash.Hash) error {
ef.mtx.Lock()
defer ef.mtx.Unlock()
// Find this block in the stack of recent registered blocks.
var n int
for n = 1; n <= len(ef.dropped); n++ {
if ef.dropped[len(ef.dropped)-n].hash.IsEqual(hash) {
break
}
}
if n > len(ef.dropped) {
return errors.New("no such block was recently registered")
}
for i := 0; i < n; i++ {
ef.rollback()
}
return nil
}
// rollback rolls back the effect of the last block in the stack
// of registered blocks.
func (ef *FeeEstimator) rollback() {
// The previous sorted list is invalid, so delete it.
ef.cached = nil
// pop the last list of dropped txs from the stack.
last := len(ef.dropped) - 1
if last == -1 {
// Cannot really happen because the exported calling function
// only rolls back a block already known to be in the list
// of dropped transactions.
return
}
dropped := ef.dropped[last]
// where we are in each bin as we replace txs?
var replacementCounters [estimateFeeDepth]int
// Go through the txs in the dropped block.
for _, o := range dropped.transactions {
// Which bin was this tx in?
blocksToConfirm := o.mined - o.observed - 1
bin := ef.bin[blocksToConfirm]
var counter = replacementCounters[blocksToConfirm]
// Continue to go through that bin where we left off.
for {
if counter >= len(bin) {
// Panic, as we have entered an unrecoverable invalid state.
panic(errors.New("illegal state: cannot rollback dropped transaction"))
}
prev := bin[counter]
if prev.mined == ef.lastKnownHeight {
prev.mined = mining.UnminedHeight
bin[counter] = o
counter++
break
}
counter++
}
replacementCounters[blocksToConfirm] = counter
}
// Continue going through bins to find other txs to remove
// which did not replace any other when they were entered.
for i, j := range replacementCounters {
for {
l := len(ef.bin[i])
if j >= l {
break
}
prev := ef.bin[i][j]
if prev.mined == ef.lastKnownHeight {
prev.mined = mining.UnminedHeight
newBin := append(ef.bin[i][0:j], ef.bin[i][j+1:l]...)
// TODO This line should prevent an unintentional memory
// leak but it causes a panic when it is uncommented.
// ef.bin[i][j] = nil
ef.bin[i] = newBin
continue
}
j++
}
}
ef.dropped = ef.dropped[0:last]
// The number of blocks the fee estimator has seen is decrimented.
ef.numBlocksRegistered--
ef.lastKnownHeight--
}
// estimateFeeSet is a set of txs that can that is sorted
// by the fee per kb rate.
type estimateFeeSet struct {
feeRate []SatoshiPerByte
bin [estimateFeeDepth]uint32
}
func (b *estimateFeeSet) Len() int { return len(b.feeRate) }
func (b *estimateFeeSet) Less(i, j int) bool {
return b.feeRate[i] > b.feeRate[j]
}
func (b *estimateFeeSet) Swap(i, j int) {
b.feeRate[i], b.feeRate[j] = b.feeRate[j], b.feeRate[i]
}
// estimateFee returns the estimated fee for a transaction
// to confirm in confirmations blocks from now, given
// the data set we have collected.
func (b *estimateFeeSet) estimateFee(confirmations int) SatoshiPerByte {
if confirmations <= 0 {
return SatoshiPerByte(math.Inf(1))
}
if confirmations > estimateFeeDepth {
return 0
}
// We don't have any transactions!
if len(b.feeRate) == 0 {
return 0
}
var min, max int = 0, 0
for i := 0; i < confirmations-1; i++ {
min += int(b.bin[i])
}
max = min + int(b.bin[confirmations-1]) - 1
if max < min {
max = min
}
feeIndex := (min + max) / 2
if feeIndex >= len(b.feeRate) {
feeIndex = len(b.feeRate) - 1
}
return b.feeRate[feeIndex]
}
// newEstimateFeeSet creates a temporary data structure that
// can be used to find all fee estimates.
func (ef *FeeEstimator) newEstimateFeeSet() *estimateFeeSet {
set := &estimateFeeSet{}
capacity := 0
for i, b := range ef.bin {
l := len(b)
set.bin[i] = uint32(l)
capacity += l
}
set.feeRate = make([]SatoshiPerByte, capacity)
i := 0
for _, b := range ef.bin {
for _, o := range b {
set.feeRate[i] = o.feeRate
i++
}
}
sort.Sort(set)
return set
}
// estimates returns the set of all fee estimates from 1 to estimateFeeDepth
// confirmations from now.
func (ef *FeeEstimator) estimates() []SatoshiPerByte {
set := ef.newEstimateFeeSet()
estimates := make([]SatoshiPerByte, estimateFeeDepth)
for i := 0; i < estimateFeeDepth; i++ {
estimates[i] = set.estimateFee(i + 1)
}
return estimates
}
// EstimateFee estimates the fee per byte to have a tx confirmed a given
// number of blocks from now.
func (ef *FeeEstimator) EstimateFee(numBlocks uint32) (BtcPerKilobyte, error) {
ef.mtx.Lock()
defer ef.mtx.Unlock()
// If the number of registered blocks is below the minimum, return
// an error.
if ef.numBlocksRegistered < ef.minRegisteredBlocks {
return -1, errors.New("not enough blocks have been observed")
}
if numBlocks == 0 {
return -1, errors.New("cannot confirm transaction in zero blocks")
}
if numBlocks > estimateFeeDepth {
return -1, fmt.Errorf(
"can only estimate fees for up to %d blocks from now",
estimateFeeBinSize)
}
// If there are no cached results, generate them.
if ef.cached == nil {
ef.cached = ef.estimates()
}
return ef.cached[int(numBlocks)-1].ToBtcPerKb(), nil
}
// In case the format for the serialized version of the FeeEstimator changes,
// we use a version number. If the version number changes, it does not make
// sense to try to upgrade a previous version to a new version. Instead, just
// start fee estimation over.
const estimateFeeSaveVersion = 1
func deserializeRegisteredBlock(r io.Reader, txs map[uint32]*observedTransaction) (*registeredBlock, error) {
var lenTransactions uint32
rb := ®isteredBlock{}
binary.Read(r, binary.BigEndian, &rb.hash)
binary.Read(r, binary.BigEndian, &lenTransactions)
rb.transactions = make([]*observedTransaction, lenTransactions)
for i := uint32(0); i < lenTransactions; i++ {
var index uint32
binary.Read(r, binary.BigEndian, &index)
rb.transactions[i] = txs[index]
}
return rb, nil
}
// FeeEstimatorState represents a saved FeeEstimator that can be
// restored with data from an earlier session of the program.
type FeeEstimatorState []byte
// observedTxSet is a set of txs that can that is sorted
// by hash. It exists for serialization purposes so that
// a serialized state always comes out the same.
type observedTxSet []*observedTransaction
func (q observedTxSet) Len() int { return len(q) }
func (q observedTxSet) Less(i, j int) bool {
return strings.Compare(q[i].hash.String(), q[j].hash.String()) < 0
}
func (q observedTxSet) Swap(i, j int) {
q[i], q[j] = q[j], q[i]
}
// Save records the current state of the FeeEstimator to a []byte that
// can be restored later.
func (ef *FeeEstimator) Save() FeeEstimatorState {
ef.mtx.Lock()
defer ef.mtx.Unlock()
// TODO figure out what the capacity should be.
w := bytes.NewBuffer(make([]byte, 0))
binary.Write(w, binary.BigEndian, uint32(estimateFeeSaveVersion))
// Insert basic parameters.
binary.Write(w, binary.BigEndian, &ef.maxRollback)
binary.Write(w, binary.BigEndian, &ef.binSize)
binary.Write(w, binary.BigEndian, &ef.maxReplacements)
binary.Write(w, binary.BigEndian, &ef.minRegisteredBlocks)
binary.Write(w, binary.BigEndian, &ef.lastKnownHeight)
binary.Write(w, binary.BigEndian, &ef.numBlocksRegistered)
// Put all the observed transactions in a sorted list.
var txCount uint32
ots := make([]*observedTransaction, len(ef.observed))
for hash := range ef.observed {
ots[txCount] = ef.observed[hash]
txCount++
}
sort.Sort(observedTxSet(ots))
txCount = 0
observed := make(map[*observedTransaction]uint32)
binary.Write(w, binary.BigEndian, uint32(len(ef.observed)))
for _, ot := range ots {
ot.Serialize(w)
observed[ot] = txCount
txCount++
}
// Save all the right bins.
for _, list := range ef.bin {
binary.Write(w, binary.BigEndian, uint32(len(list)))
for _, o := range list {
binary.Write(w, binary.BigEndian, observed[o])
}
}
// Dropped transactions.
binary.Write(w, binary.BigEndian, uint32(len(ef.dropped)))
for _, registered := range ef.dropped {
registered.serialize(w, observed)
}
// Commit the tx and return.
return FeeEstimatorState(w.Bytes())
}
// RestoreFeeEstimator takes a FeeEstimatorState that was previously
// returned by Save and restores it to a FeeEstimator
func RestoreFeeEstimator(data FeeEstimatorState) (*FeeEstimator, error) {
r := bytes.NewReader([]byte(data))
// Check version
var version uint32
err := binary.Read(r, binary.BigEndian, &version)
if err != nil {
return nil, err
}
if version != estimateFeeSaveVersion {
return nil, fmt.Errorf("Incorrect version: expected %d found %d", estimateFeeSaveVersion, version)
}
ef := &FeeEstimator{
observed: make(map[chainhash.Hash]*observedTransaction),
}
// Read basic parameters.
binary.Read(r, binary.BigEndian, &ef.maxRollback)
binary.Read(r, binary.BigEndian, &ef.binSize)
binary.Read(r, binary.BigEndian, &ef.maxReplacements)
binary.Read(r, binary.BigEndian, &ef.minRegisteredBlocks)
binary.Read(r, binary.BigEndian, &ef.lastKnownHeight)
binary.Read(r, binary.BigEndian, &ef.numBlocksRegistered)
// Read transactions.
var numObserved uint32
observed := make(map[uint32]*observedTransaction)
binary.Read(r, binary.BigEndian, &numObserved)
for i := uint32(0); i < numObserved; i++ {
ot, err := deserializeObservedTransaction(r)
if err != nil {
return nil, err
}
observed[i] = ot
ef.observed[ot.hash] = ot
}
// Read bins.
for i := 0; i < estimateFeeDepth; i++ {
var numTransactions uint32
binary.Read(r, binary.BigEndian, &numTransactions)
bin := make([]*observedTransaction, numTransactions)
for j := uint32(0); j < numTransactions; j++ {
var index uint32
binary.Read(r, binary.BigEndian, &index)
var exists bool
bin[j], exists = observed[index]
if !exists {
return nil, fmt.Errorf("Invalid transaction reference %d", index)
}
}
ef.bin[i] = bin
}
// Read dropped transactions.
var numDropped uint32
binary.Read(r, binary.BigEndian, &numDropped)
ef.dropped = make([]*registeredBlock, numDropped)
for i := uint32(0); i < numDropped; i++ {
var err error
ef.dropped[int(i)], err = deserializeRegisteredBlock(r, observed)
if err != nil {
return nil, err
}
}
return ef, nil
}