Merge branch 'master' into rfc35/common-ancestor-approach-units

This commit is contained in:
Manav Darji 2022-06-02 21:02:55 +05:30
commit b19d5e109b
11 changed files with 79 additions and 43 deletions

View file

@ -1144,7 +1144,8 @@ func (c *Bor) fetchAndCommitSpan(
msg := getSystemMessage(common.HexToAddress(c.config.ValidatorContract), data) msg := getSystemMessage(common.HexToAddress(c.config.ValidatorContract), data)
// apply message // apply message
return applyMessage(msg, state, header, c.chainConfig, chain) _, err = applyMessage(msg, state, header, c.chainConfig, chain)
return err
} }
// CommitStates commit states // CommitStates commit states
@ -1173,6 +1174,8 @@ func (c *Bor) CommitStates(
} }
} }
totalGas := 0 /// limit on gas for state sync per block
chainID := c.chainConfig.ChainID.String() chainID := c.chainConfig.ChainID.String()
for _, eventRecord := range eventRecords { for _, eventRecord := range eventRecords {
if eventRecord.ID <= lastStateID { if eventRecord.ID <= lastStateID {
@ -1191,11 +1194,15 @@ func (c *Bor) CommitStates(
} }
stateSyncs = append(stateSyncs, &stateData) stateSyncs = append(stateSyncs, &stateData)
if err := c.GenesisContractsClient.CommitState(eventRecord, state, header, chain); err != nil { gasUsed, err := c.GenesisContractsClient.CommitState(eventRecord, state, header, chain)
if err != nil {
return nil, err return nil, err
} }
totalGas += int(gasUsed)
lastStateID++ lastStateID++
} }
log.Info("StateSyncData", "Gas", totalGas, "Block-number", number, "LastStateID", lastStateID, "TotalRecords", len(eventRecords))
return stateSyncs, nil return stateSyncs, nil
} }
@ -1311,14 +1318,16 @@ func applyMessage(
header *types.Header, header *types.Header,
chainConfig *params.ChainConfig, chainConfig *params.ChainConfig,
chainContext core.ChainContext, chainContext core.ChainContext,
) error { ) (uint64, error) {
initialGas := msg.Gas()
// Create a new context to be used in the EVM environment // Create a new context to be used in the EVM environment
blockContext := core.NewEVMBlockContext(header, chainContext, &header.Coinbase) blockContext := core.NewEVMBlockContext(header, chainContext, &header.Coinbase)
// Create a new environment which holds all relevant information // Create a new environment which holds all relevant information
// about the transaction and calling mechanisms. // about the transaction and calling mechanisms.
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, state, chainConfig, vm.Config{}) vmenv := vm.NewEVM(blockContext, vm.TxContext{}, state, chainConfig, vm.Config{})
// Apply the transaction to the current state (included in the env) // Apply the transaction to the current state (included in the env)
_, _, err := vmenv.Call( _, gasLeft, err := vmenv.Call(
vm.AccountRef(msg.From()), vm.AccountRef(msg.From()),
*msg.To(), *msg.To(),
msg.Data(), msg.Data(),
@ -1330,7 +1339,8 @@ func applyMessage(
state.Finalise(true) state.Finalise(true)
} }
return nil gasUsed := initialGas - gasLeft
return gasUsed, nil
} }
func validatorContains(a []*Validator, x *Validator) (*Validator, bool) { func validatorContains(a []*Validator, x *Validator) (*Validator, bool) {

View file

@ -23,10 +23,10 @@ type EventRecordWithTime struct {
Time time.Time `json:"record_time" yaml:"record_time"` Time time.Time `json:"record_time" yaml:"record_time"`
} }
// String returns the string representatin of span // String returns the string representation of EventRecord
func (e *EventRecordWithTime) String() string { func (e *EventRecordWithTime) String(gasUsed uint64) string {
return fmt.Sprintf( return fmt.Sprintf(
"id %v, contract %v, data: %v, txHash: %v, logIndex: %v, chainId: %v, time %s", "id %v, contract %v, data: %v, txHash: %v, logIndex: %v, chainId: %v, time %s, gasUsed %d",
e.ID, e.ID,
e.Contract.String(), e.Contract.String(),
e.Data.String(), e.Data.String(),
@ -34,6 +34,7 @@ func (e *EventRecordWithTime) String() string {
e.LogIndex, e.LogIndex,
e.ChainID, e.ChainID,
e.Time.Format(time.RFC3339), e.Time.Format(time.RFC3339),
gasUsed,
) )
} }

View file

@ -134,7 +134,7 @@ type InvalidStateReceivedError struct {
func (e *InvalidStateReceivedError) Error() string { func (e *InvalidStateReceivedError) Error() string {
return fmt.Sprintf( return fmt.Sprintf(
"Received invalid event %s at block %d. Requested events until %s. Last state id was %d", "Received invalid event %v at block %d. Requested events until %s. Last state id was %d",
e.Event, e.Event,
e.Number, e.Number,
e.To.Format(time.RFC3339), e.To.Format(time.RFC3339),

View file

@ -53,25 +53,27 @@ func (gc *GenesisContractsClient) CommitState(
state *state.StateDB, state *state.StateDB,
header *types.Header, header *types.Header,
chCtx chainContext, chCtx chainContext,
) error { ) (uint64, error) {
eventRecord := event.BuildEventRecord() eventRecord := event.BuildEventRecord()
recordBytes, err := rlp.EncodeToBytes(eventRecord) recordBytes, err := rlp.EncodeToBytes(eventRecord)
if err != nil { if err != nil {
return err return 0, err
} }
method := "commitState" method := "commitState"
t := event.Time.Unix() t := event.Time.Unix()
data, err := gc.stateReceiverABI.Pack(method, big.NewInt(0).SetInt64(t), recordBytes) data, err := gc.stateReceiverABI.Pack(method, big.NewInt(0).SetInt64(t), recordBytes)
if err != nil { if err != nil {
log.Error("Unable to pack tx for commitState", "error", err) log.Error("Unable to pack tx for commitState", "error", err)
return err return 0, err
} }
log.Info("→ committing new state", "eventRecord", event.String())
msg := getSystemMessage(common.HexToAddress(gc.StateReceiverContract), data) msg := getSystemMessage(common.HexToAddress(gc.StateReceiverContract), data)
if err := applyMessage(msg, state, header, gc.chainConfig, chCtx); err != nil { gasUsed, err := applyMessage(msg, state, header, gc.chainConfig, chCtx)
return err // Logging event log with time and individual gasUsed
log.Info("→ committing new state", "eventRecord", event.String(gasUsed))
if err != nil {
return 0, err
} }
return nil return gasUsed, nil
} }
func (gc *GenesisContractsClient) LastStateId(snapshotNumber uint64) (*big.Int, error) { func (gc *GenesisContractsClient) LastStateId(snapshotNumber uint64) (*big.Int, error) {

View file

@ -127,11 +127,22 @@ func (h *HeimdallClient) FetchWithRetry(rawPath string, rawQuery string) (*Respo
u.Path = rawPath u.Path = rawPath
u.RawQuery = rawQuery u.RawQuery = rawQuery
// attempt counter
attempt := 1
// request data once
res, err := h.internalFetch(u)
if err == nil && res != nil {
return res, nil
}
// create a new ticker for retrying the request // create a new ticker for retrying the request
ticker := time.NewTicker(5 * time.Second) ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop() defer ticker.Stop()
for { for {
log.Info("Retrying again in 5 seconds to fetch data from Heimdall", "path", u.Path, "attempt", attempt)
attempt++
select { select {
case <-h.closeCh: case <-h.closeCh:
log.Debug("Shutdown detected, terminating request") log.Debug("Shutdown detected, terminating request")
@ -141,7 +152,6 @@ func (h *HeimdallClient) FetchWithRetry(rawPath string, rawQuery string) (*Respo
if err == nil && res != nil { if err == nil && res != nil {
return res, nil return res, nil
} }
log.Info("Retrying again in 5 seconds to fetch data from Heimdall", "path", u.Path)
} }
} }
} }

View file

@ -1435,6 +1435,13 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode
// Merge threshold reached, stop importing, but don't roll back // Merge threshold reached, stop importing, but don't roll back
rollback = 0 rollback = 0
log.Info("Legacy sync reached merge threshold", "number", rejected[0].Number, "hash", rejected[0].Hash(), "td", td, "ttd", ttd)
return ErrMergeTransition
}
if len(rejected) != 0 {
// Merge threshold reached, stop importing, but don't roll back
rollback = 0
log.Info("Legacy sync reached merge threshold", "number", rejected[0].Number, "hash", rejected[0].Hash(), "td", td, "ttd", ttd) log.Info("Legacy sync reached merge threshold", "number", rejected[0].Number, "hash", rejected[0].Hash(), "td", td, "ttd", ttd)
return ErrMergeTransition return ErrMergeTransition
} }

View file

@ -624,7 +624,6 @@ func testBoundedForkedSync(t *testing.T, protocol uint, mode SyncMode) {
func TestBoundedHeavyForkedSync66Full(t *testing.T) { func TestBoundedHeavyForkedSync66Full(t *testing.T) {
testBoundedHeavyForkedSync(t, eth.ETH66, FullSync) testBoundedHeavyForkedSync(t, eth.ETH66, FullSync)
} }
func TestBoundedHeavyForkedSync66Snap(t *testing.T) { func TestBoundedHeavyForkedSync66Snap(t *testing.T) {
testBoundedHeavyForkedSync(t, eth.ETH66, SnapSync) testBoundedHeavyForkedSync(t, eth.ETH66, SnapSync)
} }
@ -922,7 +921,6 @@ func testInvalidHeaderRollback(t *testing.T, protocol uint, mode SyncMode) {
func TestHighTDStarvationAttack66Full(t *testing.T) { func TestHighTDStarvationAttack66Full(t *testing.T) {
testHighTDStarvationAttack(t, eth.ETH66, FullSync) testHighTDStarvationAttack(t, eth.ETH66, FullSync)
} }
func TestHighTDStarvationAttack66Snap(t *testing.T) { func TestHighTDStarvationAttack66Snap(t *testing.T) {
testHighTDStarvationAttack(t, eth.ETH66, SnapSync) testHighTDStarvationAttack(t, eth.ETH66, SnapSync)
} }

View file

@ -88,13 +88,13 @@ var Defaults = Config{
Miner: miner.Config{ Miner: miner.Config{
GasCeil: 8000000, GasCeil: 8000000,
GasPrice: big.NewInt(params.GWei), GasPrice: big.NewInt(params.GWei),
Recommit: 3 * time.Second, Recommit: 125 * time.Second,
}, },
TxPool: core.DefaultTxPoolConfig, TxPool: core.DefaultTxPoolConfig,
RPCGasCap: 50000000, RPCGasCap: 50000000,
RPCEVMTimeout: 5 * time.Second, RPCEVMTimeout: 5 * time.Second,
GPO: FullNodeGPO, GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether RPCTxFeeCap: 5, // 5 matic
} }
func init() { func init() {

View file

@ -389,24 +389,27 @@ func (w *worker) close() {
// recalcRecommit recalculates the resubmitting interval upon feedback. // recalcRecommit recalculates the resubmitting interval upon feedback.
func recalcRecommit(minRecommit, prev time.Duration, target float64, inc bool) time.Duration { func recalcRecommit(minRecommit, prev time.Duration, target float64, inc bool) time.Duration {
var ( // var (
prevF = float64(prev.Nanoseconds()) // prevF = float64(prev.Nanoseconds())
next float64 // next float64
) // )
if inc { // if inc {
next = prevF*(1-intervalAdjustRatio) + intervalAdjustRatio*(target+intervalAdjustBias) // next = prevF*(1-intervalAdjustRatio) + intervalAdjustRatio*(target+intervalAdjustBias)
max := float64(maxRecommitInterval.Nanoseconds()) // max := float64(maxRecommitInterval.Nanoseconds())
if next > max { // if next > max {
next = max // next = max
} // }
} else { // } else {
next = prevF*(1-intervalAdjustRatio) + intervalAdjustRatio*(target-intervalAdjustBias) // next = prevF*(1-intervalAdjustRatio) + intervalAdjustRatio*(target-intervalAdjustBias)
min := float64(minRecommit.Nanoseconds()) // min := float64(minRecommit.Nanoseconds())
if next < min { // if next < min {
next = min // next = min
} // }
} // }
return time.Duration(int64(next)) // log.Info("Recalc Commit", "Prev", prev, "Next", next)
//returning the Same prev value to keep the recommit interval constant
return time.Duration(int64(prev))
} }
// newWorkLoop is a standalone goroutine to submit new sealing work upon received events. // newWorkLoop is a standalone goroutine to submit new sealing work upon received events.

View file

@ -434,10 +434,15 @@ func testRegenerateMiningBlock(t *testing.T, chainConfig *params.ChainConfig, en
} }
func TestAdjustIntervalEthash(t *testing.T) { func TestAdjustIntervalEthash(t *testing.T) {
// Skipping this test as recommit interval would remain constant
t.Skip()
testAdjustInterval(t, ethashChainConfig, ethash.NewFaker()) testAdjustInterval(t, ethashChainConfig, ethash.NewFaker())
} }
func TestAdjustIntervalClique(t *testing.T) { func TestAdjustIntervalClique(t *testing.T) {
// Skipping this test as recommit interval would remain constant
t.Skip()
testAdjustInterval(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase())) testAdjustInterval(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase()))
} }

View file

@ -21,10 +21,10 @@ import (
) )
const ( const (
VersionMajor = 0 // Major version component of the current release VersionMajor = 0 // Major version component of the current release
VersionMinor = 2 // Minor version component of the current release VersionMinor = 2 // Minor version component of the current release
VersionPatch = 16 // Patch version component of the current release VersionPatch = 16 // Patch version component of the current release
VersionMeta = "beta2" // Version metadata to append to the version string VersionMeta = "stable" // Version metadata to append to the version string
) )
// Version holds the textual version string. // Version holds the textual version string.