mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
all: fix typo and comments
This commit is contained in:
parent
8eb927b483
commit
2a12a97a98
4 changed files with 12 additions and 13 deletions
|
|
@ -36,7 +36,7 @@ func (b *SimulatedBackend) Fork(ctx context.Context, parentHash common.Hash) err
|
||||||
return b.Backend.Fork(parentHash)
|
return b.Backend.Fork(parentHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new binding backend using a simulated blockchain
|
// NewSimulatedBackend creates a new binding backend using a simulated blockchain
|
||||||
// for testing purposes.
|
// for testing purposes.
|
||||||
//
|
//
|
||||||
// A simulated backend always uses chainID 1337.
|
// A simulated backend always uses chainID 1337.
|
||||||
|
|
|
||||||
|
|
@ -86,9 +86,10 @@ type SimulatedBeacon struct {
|
||||||
|
|
||||||
// NewSimulatedBeacon constructs a new simulated beacon chain.
|
// NewSimulatedBeacon constructs a new simulated beacon chain.
|
||||||
// Period sets the period in which blocks should be produced.
|
// Period sets the period in which blocks should be produced.
|
||||||
// If period is set to 0, a block is produced on every transaction.
|
//
|
||||||
// If period is set to math.MaxUint64, blocks can only be produced
|
// - If period is set to 0, a block is produced on every transaction.
|
||||||
// via Commit, Fork and AdjustTime.
|
// - If period is set to math.MaxUint64, blocks can only be produced
|
||||||
|
// via Commit, Fork and AdjustTime.
|
||||||
func NewSimulatedBeacon(period uint64, eth *eth.Ethereum) (*SimulatedBeacon, error) {
|
func NewSimulatedBeacon(period uint64, eth *eth.Ethereum) (*SimulatedBeacon, error) {
|
||||||
block := eth.BlockChain().CurrentBlock()
|
block := eth.BlockChain().CurrentBlock()
|
||||||
current := engine.ForkchoiceStateV1{
|
current := engine.ForkchoiceStateV1{
|
||||||
|
|
@ -127,9 +128,8 @@ func (c *SimulatedBeacon) Start() error {
|
||||||
go c.loopOnDemand()
|
go c.loopOnDemand()
|
||||||
} else if c.period == math.MaxUint64 {
|
} else if c.period == math.MaxUint64 {
|
||||||
// if period is set to MaxUint, do not mine at all
|
// if period is set to MaxUint, do not mine at all
|
||||||
// this is used in the simulated backend
|
// this is used in the simulated backend where blocks
|
||||||
// where blocks are explicitly mined via
|
// are explicitly mined via Commit, AdjustTime and Fork
|
||||||
// Commit, AdjustTime and Fork
|
|
||||||
} else {
|
} else {
|
||||||
go c.loop()
|
go c.loop()
|
||||||
}
|
}
|
||||||
|
|
@ -195,6 +195,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, tstamp uint
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.setCurrentState(payload.BlockHash, finalizedHash)
|
c.setCurrentState(payload.BlockHash, finalizedHash)
|
||||||
|
|
||||||
// Mark the block containing the payload as canonical
|
// Mark the block containing the payload as canonical
|
||||||
if _, err = c.engineAPI.ForkchoiceUpdatedV2(c.curForkchoiceState, nil); err != nil {
|
if _, err = c.engineAPI.ForkchoiceUpdatedV2(c.curForkchoiceState, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -247,8 +248,8 @@ func (c *SimulatedBeacon) loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// finalizedBlockHash returns the block hash of the finalized block corresponding to the given number
|
// finalizedBlockHash returns the block hash of the finalized block corresponding
|
||||||
// or nil if doesn't exist in the chain.
|
// to the given number or nil if doesn't exist in the chain.
|
||||||
func (c *SimulatedBeacon) finalizedBlockHash(number uint64) *common.Hash {
|
func (c *SimulatedBeacon) finalizedBlockHash(number uint64) *common.Hash {
|
||||||
var finalizedNumber uint64
|
var finalizedNumber uint64
|
||||||
if number%devEpochLength == 0 {
|
if number%devEpochLength == 0 {
|
||||||
|
|
@ -256,7 +257,6 @@ func (c *SimulatedBeacon) finalizedBlockHash(number uint64) *common.Hash {
|
||||||
} else {
|
} else {
|
||||||
finalizedNumber = (number - 1) / devEpochLength * devEpochLength
|
finalizedNumber = (number - 1) / devEpochLength * devEpochLength
|
||||||
}
|
}
|
||||||
|
|
||||||
if finalizedBlock := c.eth.BlockChain().GetBlockByNumber(finalizedNumber); finalizedBlock != nil {
|
if finalizedBlock := c.eth.BlockChain().GetBlockByNumber(finalizedNumber); finalizedBlock != nil {
|
||||||
fh := finalizedBlock.Hash()
|
fh := finalizedBlock.Hash()
|
||||||
return &fh
|
return &fh
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ type Backend struct {
|
||||||
client simClient
|
client simClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// simClient wraps ethclient. This exists to prevent extracting ethclient.Client from the
|
// simClient wraps ethclient. This exists to prevent extracting ethclient.Client
|
||||||
// Client interface returned by Backend.
|
// from the Client interface returned by Backend.
|
||||||
type simClient struct {
|
type simClient struct {
|
||||||
*ethclient.Client
|
*ethclient.Client
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,6 @@ func newTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) {
|
||||||
Gas: 21000,
|
Gas: 21000,
|
||||||
To: &addr,
|
To: &addr,
|
||||||
})
|
})
|
||||||
|
|
||||||
return types.SignTx(tx, types.LatestSignerForChainID(chainid), key)
|
return types.SignTx(tx, types.LatestSignerForChainID(chainid), key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue