mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
Merge pull request #407 from maticnetwork/POS-374
Added logging for statesyncs data
This commit is contained in:
commit
8c3423ca7c
4 changed files with 29 additions and 16 deletions
|
|
@ -1144,7 +1144,8 @@ func (c *Bor) fetchAndCommitSpan(
|
|||
msg := getSystemMessage(common.HexToAddress(c.config.ValidatorContract), data)
|
||||
|
||||
// apply message
|
||||
return applyMessage(msg, state, header, c.chainConfig, chain)
|
||||
_, err = applyMessage(msg, state, header, c.chainConfig, chain)
|
||||
return err
|
||||
}
|
||||
|
||||
// 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()
|
||||
for _, eventRecord := range eventRecords {
|
||||
if eventRecord.ID <= lastStateID {
|
||||
|
|
@ -1191,11 +1194,15 @@ func (c *Bor) CommitStates(
|
|||
}
|
||||
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
|
||||
}
|
||||
totalGas += int(gasUsed)
|
||||
|
||||
lastStateID++
|
||||
}
|
||||
log.Info("StateSyncData", "Gas", totalGas, "Block-number", number, "LastStateID", lastStateID, "TotalRecords", len(eventRecords))
|
||||
return stateSyncs, nil
|
||||
}
|
||||
|
||||
|
|
@ -1311,14 +1318,16 @@ func applyMessage(
|
|||
header *types.Header,
|
||||
chainConfig *params.ChainConfig,
|
||||
chainContext core.ChainContext,
|
||||
) error {
|
||||
) (uint64, error) {
|
||||
initialGas := msg.Gas()
|
||||
|
||||
// Create a new context to be used in the EVM environment
|
||||
blockContext := core.NewEVMBlockContext(header, chainContext, &header.Coinbase)
|
||||
// Create a new environment which holds all relevant information
|
||||
// about the transaction and calling mechanisms.
|
||||
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, state, chainConfig, vm.Config{})
|
||||
// Apply the transaction to the current state (included in the env)
|
||||
_, _, err := vmenv.Call(
|
||||
_, gasLeft, err := vmenv.Call(
|
||||
vm.AccountRef(msg.From()),
|
||||
*msg.To(),
|
||||
msg.Data(),
|
||||
|
|
@ -1330,7 +1339,8 @@ func applyMessage(
|
|||
state.Finalise(true)
|
||||
}
|
||||
|
||||
return nil
|
||||
gasUsed := initialGas - gasLeft
|
||||
return gasUsed, nil
|
||||
}
|
||||
|
||||
func validatorContains(a []*Validator, x *Validator) (*Validator, bool) {
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ type EventRecordWithTime struct {
|
|||
Time time.Time `json:"record_time" yaml:"record_time"`
|
||||
}
|
||||
|
||||
// String returns the string representatin of span
|
||||
func (e *EventRecordWithTime) String() string {
|
||||
// String returns the string representation of EventRecord
|
||||
func (e *EventRecordWithTime) String(gasUsed uint64) string {
|
||||
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.Contract.String(),
|
||||
e.Data.String(),
|
||||
|
|
@ -34,6 +34,7 @@ func (e *EventRecordWithTime) String() string {
|
|||
e.LogIndex,
|
||||
e.ChainID,
|
||||
e.Time.Format(time.RFC3339),
|
||||
gasUsed,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ type InvalidStateReceivedError struct {
|
|||
|
||||
func (e *InvalidStateReceivedError) Error() string {
|
||||
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.Number,
|
||||
e.To.Format(time.RFC3339),
|
||||
|
|
|
|||
|
|
@ -53,25 +53,27 @@ func (gc *GenesisContractsClient) CommitState(
|
|||
state *state.StateDB,
|
||||
header *types.Header,
|
||||
chCtx chainContext,
|
||||
) error {
|
||||
) (uint64, error) {
|
||||
eventRecord := event.BuildEventRecord()
|
||||
recordBytes, err := rlp.EncodeToBytes(eventRecord)
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
method := "commitState"
|
||||
t := event.Time.Unix()
|
||||
data, err := gc.stateReceiverABI.Pack(method, big.NewInt(0).SetInt64(t), recordBytes)
|
||||
if err != nil {
|
||||
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)
|
||||
if err := applyMessage(msg, state, header, gc.chainConfig, chCtx); err != nil {
|
||||
return err
|
||||
gasUsed, err := applyMessage(msg, state, header, gc.chainConfig, chCtx)
|
||||
// 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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue