Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions chain/chaindb.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (cdb *ChainDB) connectToChain(dbtx db.Transaction, block *types.Block, skip
// Save the last consensus status.
if cdb.cc != nil {
if err := cdb.cc.Save(dbtx); err != nil {
logger.Error().Err(err).Msg("failed to save DPoS status")
logger.Error().Err(err).Uint64("blockNo", blockNo).Msg("failed to save DPoS status")
}
}

Expand Down Expand Up @@ -571,11 +571,14 @@ func (cdb *ChainDB) dropBlock(dropNo types.BlockNo) error {
}

func (cdb *ChainDB) getBestBlockNo() (latestNo types.BlockNo) {
var ok bool

aopv := cdb.latest.Load()
if aopv != nil {
latestNo = aopv.(types.BlockNo)
} else {
panic("ChainDB:latest is nil")
if aopv == nil {
logger.Panic().Msg("ChainService: latest is nil")
}
if latestNo, ok = aopv.(types.BlockNo); !ok {
logger.Panic().Msg("ChainService: latest is not types.BlockNo")
}
return latestNo
}
Expand Down
8 changes: 3 additions & 5 deletions chain/chaindbForRaft.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (cdb *ChainDB) ResetWAL(hardStateInfo *types.HardStateInfo) error {

snapData := consensus.NewSnapshotData(nil, nil, snapBlock)
if snapData == nil {
panic("new snap failed")
logger.Panic().Uint64("SnapBlockNo", snapBlock.BlockNo()).Msg("new snap failed")
}

data, err := snapData.Encode()
Expand Down Expand Up @@ -129,7 +129,6 @@ func (cdb *ChainDB) WriteHardState(hardstate *raftpb.HardState) error {

if data, err = proto.Marshal(hardstate); err != nil {
logger.Panic().Msg("failed to marshal raft state")
return err
}
dbTx.Set(raftStateKey, data)
dbTx.Commit()
Expand All @@ -147,7 +146,6 @@ func (cdb *ChainDB) GetHardState() (*raftpb.HardState, error) {
state := &raftpb.HardState{}
if err := proto.Unmarshal(data, state); err != nil {
logger.Panic().Msg("failed to unmarshal raft state")
return nil, ErrInvalidHardState
}

logger.Info().Uint64("term", state.Term).Str("vote", types.Uint64ToHexaString(state.Vote)).Uint64("commit", state.Commit).Msg("load hard state")
Expand Down Expand Up @@ -199,14 +197,14 @@ func (cdb *ChainDB) WriteRaftEntry(ents []*consensus.WalEntry, blocks []*types.B

if entry.Type == consensus.EntryBlock {
if err := cdb.addBlock(dbTx, blocks[i]); err != nil {
panic("add block entry")
logger.Panic().Err(err).Uint64("BlockNo", blocks[i].BlockNo()).Msg("failed to add block entry")
}

targetNo = blocks[i].BlockNo()
}

if data, err = entry.ToBytes(); err != nil {
panic("failed to convert entry to bytes")
logger.Panic().Err(err).Uint64("BlockNo", blocks[i].BlockNo()).Uint64("index", entry.Index).Msg("failed to convert entry to bytes")
}

lastIdx = entry.Index
Expand Down
26 changes: 11 additions & 15 deletions chain/chainservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,15 @@ func NewChainService(cfg *cfg.Config) *ChainService {

var err error
if cs.Core, err = NewCore(cfg.DbType, cfg.DataDir, cfg.EnableTestmode, types.BlockNo(cfg.Blockchain.ForceResetHeight)); err != nil {
logger.Fatal().Err(err).Msg("failed to initialize DB")
panic(err)
logger.Panic().Err(err).Msg("failed to initialize DB")
}

if err = Init(cfg.Blockchain.MaxBlockSize,
cfg.Blockchain.CoinbaseAccount,
cfg.Consensus.EnableBp,
cfg.Blockchain.MaxAnchorCount,
cfg.Blockchain.VerifierCount); err != nil {
logger.Error().Err(err).Msg("failed to init chainservice")
panic("invalid config: blockchain")
logger.Panic().Err(err).Msg("failed to init chainservice | invalid config: blockchain")
}

var verifyMode = cs.cfg.Blockchain.VerifyOnly || cs.cfg.Blockchain.VerifyBlock != 0
Expand All @@ -263,14 +261,11 @@ func NewChainService(cfg *cfg.Config) *ChainService {

// init genesis block
if _, err := cs.initGenesis(nil, !cfg.UseTestnet, cfg.EnableTestmode); err != nil {
logger.Fatal().Err(err).Msg("failed to create a genesis block")
panic("failed to init genesis block")
logger.Panic().Err(err).Msg("failed to create a genesis block")
}

if err := cs.checkHardfork(); err != nil {
msg := "check the hardfork compatibility"
logger.Fatal().Err(err).Msg(msg)
panic(msg)
logger.Panic().Err(err).Msg("check the hardfork compatibility")
}

if ConsensusName() == consensus.ConsensusName[consensus.ConsensusDPOS] {
Expand Down Expand Up @@ -302,7 +297,7 @@ func NewChainService(cfg *cfg.Config) *ChainService {
//reset parameter of aergo.system
systemState, err := cs.SDB().GetSystemAccountState()
if err != nil {
panic("failed to read aergo.system state")
logger.Panic().Err(err).Msg("failed to read aergo.system state")
}
system.InitSystemParams(systemState, len(cs.GetGenesisInfo().BPs))

Expand Down Expand Up @@ -404,12 +399,13 @@ func (cs *ChainService) setRecovered(val bool) {
}

func (cs *ChainService) isRecovered() bool {
var val bool
var val, ok bool
aopv := cs.recovered.Load()
if aopv != nil {
val = aopv.(bool)
} else {
panic("ChainService: recovered is nil")
if aopv == nil {
logger.Panic().Msg("ChainService: recovered is nil")
}
if val, ok = aopv.(bool); !ok {
logger.Panic().Msg("ChainService: recovered is not bool")
}
return val
}
Expand Down
3 changes: 1 addition & 2 deletions chain/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package chain

import (
"errors"
"fmt"

"github.com/aergoio/aergo/consensus"
"github.com/aergoio/aergo/internal/enc"
Expand Down Expand Up @@ -96,7 +95,7 @@ func MaxBlockSize() uint32 {

func setMaxBlockBodySize(size uint32) {
if size > types.BlockSizeHardLimit() {
panic(fmt.Errorf("too large block size (%v), hard limit = 8MiB", size))
logger.Panic().Uint32("block size", size).Msg("too large block size, hard limit = 8MiB")
}
maxBlockBodySize = size
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/impl/dpos/bp/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func NewSnapshots(c ClusterMember, cdb consensus.ChainDB, sdb *state.ChainStateD
if block, err := cdb.GetBestBlock(); err == nil {
snap.UpdateCluster(block.BlockNo())
} else {
panic(err.Error())
logger.Panic().Err(err).Msg("Failed to get the best block")
}

return snap
Expand Down
3 changes: 1 addition & 2 deletions consensus/impl/dpos/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,8 @@ func (bs *bootLoader) decodeStatus(key []byte, dst interface{}) error {

err := common.GobDecode(value, dst)
if err != nil {
logger.Debug().Err(err).Str("key", string(key)).
logger.Panic().Err(err).Str("key", string(key)).
Msg("failed to decode DPoS status")
panic(err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/impl/dpos/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func newTestChain(clusterSize uint16) (*testChain, error) {

func (tc *testChain) setGenesis(block *types.Block) {
if block.BlockNo() != 0 {
panic("invalid genesis block: non-zero block no")
logger.Panic().Msg("invalid genesis block: non-zero block no")
}
tc.status.libState.genesisInfo = &blockInfo{BlockHash: block.ID(), BlockNo: 0}
tc.status.bestBlock = block
Expand Down
2 changes: 1 addition & 1 deletion consensus/impl/dpos/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (s *Status) init(cdb consensus.ChainDB, resetHeight types.BlockNo) {

genesis, err := cdb.GetBlockByNo(0)
if err != nil {
panic(err)
logger.Panic().Err(err).Msg("failed to get genesis block")
}

best, err := cdb.GetBestBlock()
Expand Down
4 changes: 2 additions & 2 deletions consensus/impl/raftv2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func (cl *Cluster) addMember(member *consensus.Member, applied bool) error {
// notify to p2p TODO temporary code
peerID, err := types.IDFromBytes(member.PeerID)
if err != nil {
panic("invalid member peerid " + enc.ToString(member.PeerID))
logger.Panic().Err(err).Str("peerid", enc.ToString(member.PeerID)).Msg("invalid member peerid")
}

if cl.notifyFn != nil {
Expand Down Expand Up @@ -466,7 +466,7 @@ func (cl *Cluster) removeMember(member *consensus.Member) error {
// notify to p2p TODO temporary code
peerID, err := types.IDFromBytes(member.PeerID)
if err != nil {
panic("invalid member peerid " + enc.ToString(member.PeerID))
logger.Panic().Err(err).Str("peerid", enc.ToString(member.PeerID)).Msg("invalid member peerid")
}

if cl.notifyFn != nil {
Expand Down
2 changes: 1 addition & 1 deletion consensus/impl/raftv2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (bf *BlockFactory) InitCluster(cfg *config.Config) error {

raftConfig := cfg.Consensus.Raft
if raftConfig == nil {
panic("raftconfig is not set. please set raftName, raftBPs.")
logger.Panic().Msg("raft config is not set. please set raftName, raftBPs.")
}

chainID, err := genesis.ID.Bytes()
Expand Down
6 changes: 3 additions & 3 deletions consensus/impl/raftv2/raftserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ func (rs *raftServer) createAergoP2PTransporter() Transporter {
future := rs.RequestFuture(message.P2PSvc, message.GetRaftTransport{Cluster: rs.cluster}, time.Second<<4, "getbackend")
result, err := future.Result()
if err != nil {
panic(err.Error())
logger.Panic().Err(err).Msg("failed to get backend")
}
return result.(Transporter)
}
Expand Down Expand Up @@ -674,7 +674,7 @@ func (rs *raftServer) serveChannels() {

snapshot, err := rs.raftStorage.Snapshot()
if err != nil {
panic(err)
logger.Panic().Err(err).Msg("failed to get snapshot")
}
rs.setConfState(&snapshot.Metadata.ConfState)
rs.setSnapshotIndex(snapshot.Metadata.Index)
Expand Down Expand Up @@ -969,7 +969,7 @@ func (rs *raftServer) triggerSnapshot() {
if err == raftlib.ErrCompacted {
return
}
panic(err)
logger.Fatal().Err(err).Uint64("index", compactIndex).Msg("failed to compact raft log")
}

logger.Info().Uint64("index", compactIndex).Msg("compacted raftLog.at index")
Expand Down
2 changes: 1 addition & 1 deletion consensus/impl/raftv2/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (chainsnap *ChainSnapshotter) createSnapshotData(cluster *Cluster, snapBloc

snap := consensus.NewSnapshotData(members, removedMembers, snapBlock)
if snap == nil {
panic("new snap failed")
logger.Panic().Msg("new snap failed")
}

return snap, nil
Expand Down
7 changes: 4 additions & 3 deletions consensus/impl/raftv2/waldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func (wal *WalDB) convertFromRaft(entries []raftpb.Entry) ([]*consensus.WalEntry
case raftpb.EntryConfChange:
return consensus.EntryConfChange
default:
panic("not support raftpb entrytype")
logger.Panic().Str("entry", types.RaftEntryToString(entry)).Msg("invalid entry type")
panic("invalid entry type")
}
}

Expand Down Expand Up @@ -100,11 +101,11 @@ func (wal *WalDB) convertFromRaft(entries []raftpb.Entry) ([]*consensus.WalEntry
)
for i, entry := range entries {
if blocks[i], data, err = getWalData(&entry); err != nil {
panic("entry unmarshalEntryData error")
logger.Panic().Err(err).Str("entry", types.RaftEntryToString(&entry)).Msg("entry unmarshalEntryData error")
}

if confChanges[i], err = getConfChange(&entry); err != nil {
panic("entry unmarshalEntryConfChange error")
logger.Panic().Err(err).Str("entry", types.RaftEntryToString(&entry)).Msg("entry unmarshalEntryConfChange error")
}

walents[i] = &consensus.WalEntry{
Expand Down
2 changes: 1 addition & 1 deletion consensus/raftCommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (we *WalEntry) ToBytes() ([]byte, error) {
var val bytes.Buffer
encoder := gob.NewEncoder(&val)
if err := encoder.Encode(we); err != nil {
panic("raft entry to bytes error")
logger.Panic().Err(err).Msg("raft entry to bytes error")
}

return val.Bytes(), nil
Expand Down