2019-08-24 17:51:00 +00:00
|
|
|
package blockchain
|
|
|
|
|
|
|
|
import (
|
2020-04-29 16:57:04 +00:00
|
|
|
"encoding/hex"
|
2020-01-27 21:48:16 +00:00
|
|
|
"fmt"
|
2021-02-15 16:33:38 +00:00
|
|
|
"time"
|
2020-01-27 21:48:16 +00:00
|
|
|
|
2022-06-15 10:03:48 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
2021-09-21 19:59:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
2022-05-02 18:32:37 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
|
2022-03-15 14:02:39 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
2021-07-21 21:34:07 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-09-16 09:46:29 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/runtime/version"
|
2021-09-15 00:09:04 +00:00
|
|
|
prysmTime "github.com/prysmaticlabs/prysm/time"
|
2021-10-01 20:17:57 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/time/slots"
|
2019-08-24 17:51:00 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
var log = logrus.WithField("prefix", "blockchain")
|
|
|
|
|
|
|
|
// logs state transition related data every slot.
|
2022-05-02 18:32:37 +00:00
|
|
|
func logStateTransitionData(b interfaces.BeaconBlock) error {
|
2021-08-09 20:05:46 +00:00
|
|
|
log := log.WithField("slot", b.Slot())
|
2021-05-26 16:19:54 +00:00
|
|
|
if len(b.Body().Attestations()) > 0 {
|
|
|
|
log = log.WithField("attestations", len(b.Body().Attestations()))
|
2021-02-18 19:08:27 +00:00
|
|
|
}
|
2021-05-26 16:19:54 +00:00
|
|
|
if len(b.Body().Deposits()) > 0 {
|
|
|
|
log = log.WithField("deposits", len(b.Body().Deposits()))
|
2021-02-18 19:08:27 +00:00
|
|
|
}
|
2021-05-26 16:19:54 +00:00
|
|
|
if len(b.Body().AttesterSlashings()) > 0 {
|
|
|
|
log = log.WithField("attesterSlashings", len(b.Body().AttesterSlashings()))
|
2021-02-18 19:08:27 +00:00
|
|
|
}
|
2021-05-26 16:19:54 +00:00
|
|
|
if len(b.Body().ProposerSlashings()) > 0 {
|
|
|
|
log = log.WithField("proposerSlashings", len(b.Body().ProposerSlashings()))
|
2021-02-18 19:08:27 +00:00
|
|
|
}
|
2021-05-26 16:19:54 +00:00
|
|
|
if len(b.Body().VoluntaryExits()) > 0 {
|
|
|
|
log = log.WithField("voluntaryExits", len(b.Body().VoluntaryExits()))
|
2021-02-18 19:08:27 +00:00
|
|
|
}
|
2022-03-15 14:02:39 +00:00
|
|
|
if b.Version() == version.Altair || b.Version() == version.Bellatrix {
|
2021-08-26 05:01:09 +00:00
|
|
|
agg, err := b.Body().SyncAggregate()
|
2022-03-15 14:02:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-08-26 05:01:09 +00:00
|
|
|
}
|
2022-03-15 14:02:39 +00:00
|
|
|
log = log.WithField("syncBitsCount", agg.SyncCommitteeBits.Count())
|
|
|
|
}
|
|
|
|
if b.Version() == version.Bellatrix {
|
|
|
|
p, err := b.Body().ExecutionPayload()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log = log.WithField("payloadHash", fmt.Sprintf("%#x", bytesutil.Trunc(p.BlockHash)))
|
|
|
|
log = log.WithField("txCount", len(p.Transactions))
|
2021-08-26 05:01:09 +00:00
|
|
|
}
|
2021-02-18 19:08:27 +00:00
|
|
|
log.Info("Finished applying state transition")
|
2022-03-15 14:02:39 +00:00
|
|
|
return nil
|
2019-08-24 17:51:00 +00:00
|
|
|
}
|
2020-01-27 21:48:16 +00:00
|
|
|
|
2022-05-22 16:57:48 +00:00
|
|
|
func logBlockSyncStatus(block interfaces.BeaconBlock, blockRoot [32]byte, justified, finalized *ethpb.Checkpoint, receivedTime time.Time, genesisTime uint64) error {
|
2021-10-01 20:17:57 +00:00
|
|
|
startTime, err := slots.ToTime(genesisTime, block.Slot())
|
2021-02-10 17:24:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-05-22 16:57:48 +00:00
|
|
|
level := log.Logger.GetLevel()
|
|
|
|
if level >= logrus.DebugLevel {
|
2022-06-30 19:02:23 +00:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"slot": block.Slot(),
|
|
|
|
"slotInEpoch": block.Slot() % params.BeaconConfig().SlotsPerEpoch,
|
|
|
|
"block": fmt.Sprintf("0x%s...", hex.EncodeToString(blockRoot[:])[:8]),
|
|
|
|
"epoch": slots.ToEpoch(block.Slot()),
|
|
|
|
"justifiedEpoch": justified.Epoch,
|
|
|
|
"justifiedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(justified.Root)[:8]),
|
|
|
|
"finalizedEpoch": finalized.Epoch,
|
|
|
|
"finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]),
|
|
|
|
"parentRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(block.ParentRoot())[:8]),
|
|
|
|
"version": version.String(block.Version()),
|
|
|
|
"sinceSlotStartTime": prysmTime.Now().Sub(startTime),
|
|
|
|
"chainServiceProcessedTime": prysmTime.Now().Sub(receivedTime),
|
|
|
|
}).Debug("Synced new block")
|
|
|
|
} else {
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"slot": block.Slot(),
|
|
|
|
"block": fmt.Sprintf("0x%s...", hex.EncodeToString(blockRoot[:])[:8]),
|
|
|
|
"finalizedEpoch": finalized.Epoch,
|
|
|
|
"finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]),
|
|
|
|
"epoch": slots.ToEpoch(block.Slot()),
|
|
|
|
}).Info("Synced new block")
|
2022-05-22 16:57:48 +00:00
|
|
|
}
|
2021-02-10 17:24:40 +00:00
|
|
|
return nil
|
2020-04-29 16:57:04 +00:00
|
|
|
}
|
2022-06-15 10:03:48 +00:00
|
|
|
|
|
|
|
// logs payload related data every slot.
|
|
|
|
func logPayload(block interfaces.BeaconBlock) error {
|
|
|
|
isExecutionBlk, err := blocks.IsExecutionBlock(block.Body())
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not determine if block is execution block")
|
|
|
|
}
|
|
|
|
if !isExecutionBlk {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
payload, err := block.Body().ExecutionPayload()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if payload.GasLimit == 0 {
|
|
|
|
return errors.New("gas limit should not be 0")
|
|
|
|
}
|
|
|
|
gasUtilized := float64(payload.GasUsed) / float64(payload.GasLimit)
|
|
|
|
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"blockHash": fmt.Sprintf("%#x", bytesutil.Trunc(payload.BlockHash)),
|
|
|
|
"parentHash": fmt.Sprintf("%#x", bytesutil.Trunc(payload.ParentHash)),
|
|
|
|
"blockNumber": payload.BlockNumber,
|
|
|
|
"gasUtilized": fmt.Sprintf("%.2f", gasUtilized),
|
|
|
|
}).Debug("Synced new payload")
|
|
|
|
return nil
|
|
|
|
}
|