2020-05-19 14:18:07 +00:00
|
|
|
# beacon_chain
|
|
|
|
# Copyright (c) 2018-2020 Status Research & Development GmbH
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
import
|
2020-06-18 10:03:36 +00:00
|
|
|
chronicles, tables, options,
|
2020-05-19 14:18:07 +00:00
|
|
|
stew/bitops2,
|
|
|
|
metrics,
|
2020-06-18 10:03:36 +00:00
|
|
|
../spec/[datatypes, digest],
|
2020-05-19 14:18:07 +00:00
|
|
|
block_pools_types
|
|
|
|
|
2020-07-30 19:18:17 +00:00
|
|
|
export options, block_pools_types
|
2020-06-18 10:03:36 +00:00
|
|
|
|
2020-07-16 13:16:51 +00:00
|
|
|
logScope:
|
|
|
|
topics = "quarant"
|
|
|
|
|
2020-05-19 14:18:07 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
2020-07-31 14:49:06 +00:00
|
|
|
func checkMissing*(quarantine: var QuarantineRef): seq[FetchRecord] =
|
2020-05-19 14:18:07 +00:00
|
|
|
## Return a list of blocks that we should try to resolve from other client -
|
|
|
|
## to be called periodically but not too often (once per slot?)
|
|
|
|
var done: seq[Eth2Digest]
|
|
|
|
|
|
|
|
for k, v in quarantine.missing.mpairs():
|
|
|
|
if v.tries > 8:
|
|
|
|
done.add(k)
|
|
|
|
else:
|
|
|
|
inc v.tries
|
|
|
|
|
|
|
|
for k in done:
|
|
|
|
# TODO Need to potentially remove from quarantine.pending - this is currently a
|
|
|
|
# memory leak here!
|
|
|
|
quarantine.missing.del(k)
|
|
|
|
|
|
|
|
# simple (simplistic?) exponential backoff for retries..
|
|
|
|
for k, v in quarantine.missing.pairs():
|
|
|
|
if countOnes(v.tries.uint64) == 1:
|
2020-06-18 10:03:36 +00:00
|
|
|
result.add(FetchRecord(root: k))
|
|
|
|
|
2020-08-05 14:19:43 +00:00
|
|
|
func addMissing*(quarantine: var QuarantineRef, root: Eth2Digest) =
|
|
|
|
## Schedule the download a the given block
|
|
|
|
if root notin quarantine.orphans:
|
|
|
|
# If the block is in orphans, we no longer need it
|
|
|
|
discard quarantine.missing.hasKeyOrPut(root, MissingBlock())
|
2020-06-23 09:29:08 +00:00
|
|
|
|
2020-07-31 14:49:06 +00:00
|
|
|
func add*(quarantine: var QuarantineRef, dag: ChainDAGRef,
|
2020-08-05 14:19:43 +00:00
|
|
|
signedBlock: SignedBeaconBlock) =
|
2020-06-18 10:03:36 +00:00
|
|
|
## Adds block to quarantine's `orphans` and `missing` lists.
|
2020-08-05 14:19:43 +00:00
|
|
|
quarantine.orphans[signedBlock.root] = signedBlock
|
|
|
|
quarantine.missing.del(signedBlock.root)
|
2020-06-18 10:03:36 +00:00
|
|
|
|
2020-08-05 14:19:43 +00:00
|
|
|
quarantine.addMissing(signedBlock.message.parent_root)
|