remove clique unused code
This commit is contained in:
parent
b16b35caea
commit
93725bdc02
|
@ -27,17 +27,6 @@ import
|
||||||
eth/[keys, rlp],
|
eth/[keys, rlp],
|
||||||
stew/[keyed_queue, results]
|
stew/[keyed_queue, results]
|
||||||
|
|
||||||
const
|
|
||||||
enableCliqueAsyncLock* = ##\
|
|
||||||
## Async locks are currently unused by `Clique` but were part of the Go
|
|
||||||
## reference implementation. The unused code fragment from the reference
|
|
||||||
## implementation are buried in the file `clique_unused.nim` and not used
|
|
||||||
## otherwise.
|
|
||||||
defined(clique_async_lock)
|
|
||||||
|
|
||||||
when enableCliqueAsyncLock:
|
|
||||||
import chronos
|
|
||||||
|
|
||||||
type
|
type
|
||||||
RawSignature* = array[RawSignatureSize, byte]
|
RawSignature* = array[RawSignatureSize, byte]
|
||||||
|
|
||||||
|
@ -70,9 +59,6 @@ type
|
||||||
## Ethereum address of the current signing key
|
## Ethereum address of the current signing key
|
||||||
|
|
||||||
signFn*: CliqueSignerFn ## Signer function to authorize hashes with
|
signFn*: CliqueSignerFn ## Signer function to authorize hashes with
|
||||||
stopSealReq*: bool ## Stop running `seal()` function
|
|
||||||
stopVHeaderReq*: bool ## Stop running `verifyHeader()` function
|
|
||||||
# signatures => see CliqueCfg
|
|
||||||
|
|
||||||
cfg: CliqueCfg ##\
|
cfg: CliqueCfg ##\
|
||||||
## Common engine parameters to fine tune behaviour
|
## Common engine parameters to fine tune behaviour
|
||||||
|
@ -102,10 +88,6 @@ type
|
||||||
## before have been vetted already regardless of the current branch. So
|
## before have been vetted already regardless of the current branch. So
|
||||||
## the nearest `epoch` header is used.
|
## the nearest `epoch` header is used.
|
||||||
|
|
||||||
when enableCliqueAsyncLock:
|
|
||||||
asyncLock: AsyncLock ##\
|
|
||||||
## Protects the signer fields
|
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
|
@ -122,8 +104,6 @@ proc newClique*(cfg: CliqueCfg): Clique =
|
||||||
result = Clique(cfg: cfg,
|
result = Clique(cfg: cfg,
|
||||||
snapshot: cfg.newSnapshot(BlockHeader()),
|
snapshot: cfg.newSnapshot(BlockHeader()),
|
||||||
proposals: initTable[EthAddress,bool]())
|
proposals: initTable[EthAddress,bool]())
|
||||||
when enableCliqueAsyncLock:
|
|
||||||
result.asyncLock = newAsyncLock()
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public debug/pretty print
|
# Public debug/pretty print
|
||||||
|
@ -197,29 +177,6 @@ proc `applySnapsMinBacklog=`*(c: Clique; value: bool) =
|
||||||
## Setter
|
## Setter
|
||||||
c.applySnapsMinBacklog = value
|
c.applySnapsMinBacklog = value
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Public lock/unlock
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
when enableCliqueAsyncLock:
|
|
||||||
proc lock*(c: Clique) {.gcsafe, raises: [Defect,CatchableError].} =
|
|
||||||
## Lock descriptor
|
|
||||||
waitFor c.asyncLock.acquire
|
|
||||||
|
|
||||||
proc unLock*(c: Clique) {.gcsafe, raises: [Defect,AsyncLockError].} =
|
|
||||||
## Unlock descriptor
|
|
||||||
c.asyncLock.release
|
|
||||||
|
|
||||||
template doExclusively*(c: Clique; action: untyped) =
|
|
||||||
## Handy helper
|
|
||||||
c.lock
|
|
||||||
action
|
|
||||||
c.unlock
|
|
||||||
|
|
||||||
else:
|
|
||||||
template doExclusively*(c: Clique; action: untyped) =
|
|
||||||
action
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -38,36 +38,10 @@ import
|
||||||
logScope:
|
logScope:
|
||||||
topics = "clique PoA Mining"
|
topics = "clique PoA Mining"
|
||||||
|
|
||||||
type
|
|
||||||
CliqueSyncDefect* = object of Defect
|
|
||||||
## Defect raised with lock/unlock problem
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Private Helpers
|
# Private Helpers
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
template syncExceptionWrap(action: untyped) =
|
|
||||||
try:
|
|
||||||
action
|
|
||||||
except:
|
|
||||||
raise (ref CliqueSyncDefect)(msg: getCurrentException().msg)
|
|
||||||
|
|
||||||
|
|
||||||
# clique/clique.go(217): func (c *Clique) VerifyHeader(chain [..]
|
|
||||||
proc verifyHeader(c: Clique; com: CommonRef; header: BlockHeader): CliqueOkResult
|
|
||||||
{.gcsafe, raises: [Defect,CatchableError].} =
|
|
||||||
## See `clique.cliqueVerify()`
|
|
||||||
var blind: seq[BlockHeader]
|
|
||||||
c.cliqueVerifySeq(com, header, blind)
|
|
||||||
|
|
||||||
proc verifyHeader(c: Clique; com: CommonRef; header: BlockHeader;
|
|
||||||
parents: openArray[BlockHeader]): CliqueOkResult
|
|
||||||
{.gcsafe, raises: [Defect,CatchableError].} =
|
|
||||||
## See `clique.cliqueVerify()`
|
|
||||||
var list = toSeq(parents)
|
|
||||||
c.cliqueVerifySeq(com, header, list)
|
|
||||||
|
|
||||||
|
|
||||||
proc isValidVote(s: Snapshot; a: EthAddress; authorize: bool): bool =
|
proc isValidVote(s: Snapshot; a: EthAddress; authorize: bool): bool =
|
||||||
s.ballot.isValidVote(a, authorize)
|
s.ballot.isValidVote(a, authorize)
|
||||||
|
|
||||||
|
@ -106,63 +80,6 @@ proc recentBlockNumber*(s: Snapshot;
|
||||||
# Public functions
|
# Public functions
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# clique/clique.go(212): func (c *Clique) Author(header [..]
|
|
||||||
proc author*(c: Clique; header: BlockHeader): Result[EthAddress,UtilsError]
|
|
||||||
{.gcsafe, raises: [Defect,CatchableError].} =
|
|
||||||
## For the Consensus Engine, `author()` retrieves the Ethereum address of the
|
|
||||||
## account that minted the given block, which may be different from the
|
|
||||||
## header's coinbase if a consensus engine is based on signatures.
|
|
||||||
##
|
|
||||||
## This implementation returns the Ethereum address recovered from the
|
|
||||||
## signature in the header's extra-data section.
|
|
||||||
c.cfg.ecRecover(header)
|
|
||||||
|
|
||||||
|
|
||||||
# clique/clique.go(224): func (c *Clique) VerifyHeader(chain [..]
|
|
||||||
proc verifyHeaders*(c: Clique; com: CommonRef; headers: openArray[BlockHeader]):
|
|
||||||
Future[seq[CliqueOkResult]] {.async,gcsafe.} =
|
|
||||||
## For the Consensus Engine, `verifyHeader()` s similar to VerifyHeader, but
|
|
||||||
## verifies a batch of headers concurrently. This method is accompanied
|
|
||||||
## by a `stopVerifyHeader()` method that can abort the operations.
|
|
||||||
##
|
|
||||||
## This implementation checks whether a header conforms to the consensus
|
|
||||||
## rules. It verifies a batch of headers. If running in the background,
|
|
||||||
## the process can be stopped by calling the `stopVerifyHeader()` function.
|
|
||||||
syncExceptionWrap:
|
|
||||||
c.doExclusively:
|
|
||||||
c.stopVHeaderReq = false
|
|
||||||
for n in 0 ..< headers.len:
|
|
||||||
c.doExclusively:
|
|
||||||
let isStopRequest = c.stopVHeaderReq
|
|
||||||
if isStopRequest:
|
|
||||||
result.add cliqueResultErr((errCliqueStopped,""))
|
|
||||||
break
|
|
||||||
result.add c.verifyHeader(com, headers[n], headers[0 ..< n])
|
|
||||||
c.doExclusively:
|
|
||||||
c.stopVHeaderReq = false
|
|
||||||
|
|
||||||
proc stopVerifyHeader*(c: Clique): bool {.discardable.} =
|
|
||||||
## Activate the stop flag for running `verifyHeader()` function.
|
|
||||||
## Returns `true` if the stop flag could be activated.
|
|
||||||
syncExceptionWrap:
|
|
||||||
c.doExclusively:
|
|
||||||
if not c.stopVHeaderReq:
|
|
||||||
c.stopVHeaderReq = true
|
|
||||||
result = true
|
|
||||||
|
|
||||||
|
|
||||||
# clique/clique.go(450): func (c *Clique) VerifyUncles(chain [..]
|
|
||||||
proc verifyUncles*(c: Clique; ethBlock: EthBlock): CliqueOkResult =
|
|
||||||
## For the Consensus Engine, `verifyUncles()` verifies that the given
|
|
||||||
## block's uncles conform to the consensus rules of a given engine.
|
|
||||||
##
|
|
||||||
## This implementation always returns an error for existing uncles as this
|
|
||||||
## consensus mechanism doesn't permit uncles.
|
|
||||||
if 0 < ethBlock.uncles.len:
|
|
||||||
return err((errCliqueUnclesNotAllowed,""))
|
|
||||||
result = ok()
|
|
||||||
|
|
||||||
|
|
||||||
# clique/clique.go(506): func (c *Clique) Prepare(chain [..]
|
# clique/clique.go(506): func (c *Clique) Prepare(chain [..]
|
||||||
proc prepare*(c: Clique; parent: BlockHeader, header: var BlockHeader): CliqueOkResult
|
proc prepare*(c: Clique; parent: BlockHeader, header: var BlockHeader): CliqueOkResult
|
||||||
{.gcsafe, raises: [Defect, CatchableError].} =
|
{.gcsafe, raises: [Defect, CatchableError].} =
|
||||||
|
@ -186,7 +103,6 @@ proc prepare*(c: Clique; parent: BlockHeader, header: var BlockHeader): CliqueOk
|
||||||
|
|
||||||
let modEpoch = (parent.blockNumber+1) mod c.cfg.epoch
|
let modEpoch = (parent.blockNumber+1) mod c.cfg.epoch
|
||||||
if modEpoch != 0:
|
if modEpoch != 0:
|
||||||
c.doExclusively:
|
|
||||||
# Gather all the proposals that make sense voting on
|
# Gather all the proposals that make sense voting on
|
||||||
var addresses: seq[EthAddress]
|
var addresses: seq[EthAddress]
|
||||||
for (address,authorize) in c.proposals.pairs:
|
for (address,authorize) in c.proposals.pairs:
|
||||||
|
@ -227,8 +143,6 @@ proc prepareForSeal*(c: Clique; prepHeader: BlockHeader; header: var BlockHeader
|
||||||
# clique/clique.go(589): func (c *Clique) Authorize(signer [..]
|
# clique/clique.go(589): func (c *Clique) Authorize(signer [..]
|
||||||
proc authorize*(c: Clique; signer: EthAddress; signFn: CliqueSignerFn) =
|
proc authorize*(c: Clique; signer: EthAddress; signFn: CliqueSignerFn) =
|
||||||
## Injects private key into the consensus engine to mint new blocks with.
|
## Injects private key into the consensus engine to mint new blocks with.
|
||||||
syncExceptionWrap:
|
|
||||||
c.doExclusively:
|
|
||||||
c.signer = signer
|
c.signer = signer
|
||||||
c.signFn = signFn
|
c.signFn = signFn
|
||||||
|
|
||||||
|
@ -273,7 +187,6 @@ proc seal*(c: Clique; ethBlock: var EthBlock):
|
||||||
return err((nilCliqueSealNoBlockYet, ""))
|
return err((nilCliqueSealNoBlockYet, ""))
|
||||||
|
|
||||||
# Don't hold the signer fields for the entire sealing procedure
|
# Don't hold the signer fields for the entire sealing procedure
|
||||||
c.doExclusively:
|
|
||||||
let
|
let
|
||||||
signer = c.signer
|
signer = c.signer
|
||||||
signFn = c.signFn
|
signFn = c.signFn
|
||||||
|
|
Loading…
Reference in New Issue