Skip to content

Commit

Permalink
Merge pull request #842 from lochjin/dev2.0
Browse files Browse the repository at this point in the history
fix:snap-sync abnormal jamming
  • Loading branch information
dindinw authored Dec 3, 2024
2 parents 8d0a998 + b3a013e commit 8ccbc74
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 57 deletions.
9 changes: 6 additions & 3 deletions core/blockchain/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,13 @@ func (b *BlockChain) ProcessBlockBySnap(sds []*SnapData) (meerdag.IBlock, error)
}
tx.Object = vtx
}
_, err = b.MeerVerifyTx(vtx, view)
if err != nil {
return returnFun(err)
if vtx.ExportData != nil {
err = b.meerChain.MeerPool().CheckMeerChangeExportTx(vtx.ETx, vtx.ExportData, view)
if err != nil {
return returnFun(err)
}
}

err = b.connectVMTransaction(tx, vtx, nil, view)
if err != nil {
return returnFun(err)
Expand Down
1 change: 1 addition & 0 deletions core/json/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type GetPeerInfoResult struct {
Tasks int `json:"tasks,omitempty"`
Broadcast int `json:"broadcast,omitempty"`
Snap bool `json:"snap,omitempty"`
SnapSync bool `json:"snapsync,omitempty"`
MeerState *MeerState `json:"meerstate,omitempty"`
}

Expand Down
5 changes: 4 additions & 1 deletion meerevm/meer/meerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ func (b *MeerChain) VerifyTx(tx *mmeer.VMTx, utxoView *utxo.UtxoViewpoint) (int6
return 0, err
}
if tx.ExportData != nil {
err = b.meerpool.checkMeerChangeExportTx(txe, tx.ExportData, utxoView)
err = b.meerpool.CheckMeerChangeExportTx(txe, tx.ExportData, utxoView)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -695,6 +695,9 @@ func (b *MeerChain) SyncTo(target common.Hash) error {
if system.InterruptRequested(b.consensus.Interrupt()) {
return errors.New("System interrupt")
}
if b.IsShutdown() {
return errors.New("MeerChain is shutdown")
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions meerevm/meer/meerchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (m *MeerPool) checkMeerChangeTxs(block *types.Block, receipts types.Receipt
if err != nil {
return err
}
err = m.checkMeerChangeExportTx(tx, ccExportEvent, nil)
err = m.CheckMeerChangeExportTx(tx, ccExportEvent, nil)
if err != nil {
m.ethTxPool.RemoveTx(tx.Hash(), true)
return err
Expand All @@ -65,7 +65,7 @@ func (m *MeerPool) HasUtxo(txid *hash.Hash, idx uint32) bool {
return err == nil && ue != nil
}

func (m *MeerPool) checkMeerChangeExportTx(tx *types.Transaction, ced *meerchange.MeerchangeExportData, utxoView *utxo.UtxoViewpoint) error {
func (m *MeerPool) CheckMeerChangeExportTx(tx *types.Transaction, ced *meerchange.MeerchangeExportData, utxoView *utxo.UtxoViewpoint) error {
ops, err := ced.GetOutPoints()
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions p2p/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (api *PublicP2PAPI) GetPeerInfo(verbose *bool, pid *string) (interface{}, e
ReConnect: p.ReConnect,
Active: active,
Snap: p.IsSnap(),
SnapSync: p.SnapSync,
}
info.Protocol = p.Protocol
info.Services = p.Services.String()
Expand Down
13 changes: 13 additions & 0 deletions p2p/peers/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ func (p *Peer) StatsSnapshot() (*StatsSnap, error) {
if p.getMeerState() != nil {
ss.MeerState = common.NewMeerState(p.getMeerState())
}
if p.chainState != nil {
ss.SnapSync = p.chainState.SnapSync
}
return ss, nil
}

Expand Down Expand Up @@ -776,6 +779,16 @@ func (p *Peer) GetMeerState() *v2.MeerState {
return p.getMeerState()
}

func (p *Peer) IsSnapSync() bool {
p.lock.RLock()
defer p.lock.RUnlock()

if p.chainState == nil {
return false
}
return p.chainState.SnapSync
}

func (p *Peer) getMeerState() *v2.MeerState {
if p.chainState == nil {
return nil
Expand Down
1 change: 1 addition & 0 deletions p2p/peers/statssnap.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type StatsSnap struct {
Tasks int
Broadcast int
MeerState *common.MeerState
SnapSync bool
}

func (p *StatsSnap) IsRelay() bool {
Expand Down
2 changes: 1 addition & 1 deletion p2p/proto/v1/messages.ssz.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 66 additions & 25 deletions p2p/proto/v2/chainstate.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions p2p/proto/v2/chainstate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ message ChainState {
v1.GraphState graphState = 6;
bytes userAgent = 7 [(gogoproto.moretags) = "ssz-max:\"256\""];
MeerState meerState =8;
bool snapSync = 9;
}
19 changes: 14 additions & 5 deletions p2p/proto/v2/messages.ssz.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions p2p/synch/chainstate_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (s *Sync) getChainStateV2() *v2.ChainState {
UserAgent: []byte(s.p2p.Config().UserAgent),
DisableRelayTx: s.p2p.Config().DisableRelayTx,
MeerState: s.getMeerState(),
SnapSync: s.peerSync.IsSnapSync(),
}

return cs
Expand Down
2 changes: 1 addition & 1 deletion p2p/synch/getblockdatas.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *Sync) getMerkleBlockDataHandler(ctx context.Context, msg interface{}, s
}

func (ps *PeerSync) processGetBlockDatas(pe *peers.Peer, blocks []*hash.Hash) *ProcessResult {
if !ps.isSyncPeer(pe) || !pe.IsConnected() {
if !ps.isSyncPeer(pe) || !pe.IsConnected() || pe.IsSnapSync() {
err := fmt.Errorf("no sync peer:%v", pe.GetID())
log.Trace(err.Error(), "processID", ps.getProcessID())
return nil
Expand Down
1 change: 0 additions & 1 deletion p2p/synch/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func (ps *PeerSync) processConnected(msg *ConnectedMsg) {
func (ps *PeerSync) immediatelyConnected(pe *peers.Peer) {
pe.HSlock.Lock()
defer pe.HSlock.Unlock()

ps.Connection(pe)
}

Expand Down
4 changes: 2 additions & 2 deletions p2p/synch/meerevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func (ps *PeerSync) connectMeerEVM(pe *peers.Peer) {
if err != nil {
log.Error("invalid enode: %v", err)
}
meerP2P.AddTrustedPeer(node)
meerP2P.AddPeer(node)
} else if len(meers.ENR) > 0 {
node, err := enode.Parse(enode.ValidSchemes, meers.ENR)
if err != nil {
log.Error("invalid enr: %v", err)
}
meerP2P.AddTrustedPeer(node)
meerP2P.AddPeer(node)
}
}
Loading

0 comments on commit 8ccbc74

Please sign in to comment.