Skip to content

Commit

Permalink
fix(bpos): discrete mining can include illegal proposal and vote
Browse files Browse the repository at this point in the history
  • Loading branch information
Houshoupei84 committed Aug 21, 2023
1 parent 8db9977 commit 871d2a2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
1 change: 1 addition & 0 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,7 @@ func (b *BlockChain) connectBlock(node *BlockNode, block *Block, confirm *payloa
// Notify the caller that the block was connected to the main chain.
// The caller would typically want to react with actions such as
// updating wallets.
//todo add go
events.Notify(events.ETBlockConnected, block)

return nil
Expand Down
42 changes: 30 additions & 12 deletions core/checkpoint/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,36 @@ func (m *Manager) onBlockSaved(block *types.DposBlock,
}
}

if block.Height >=
originalHeight+v.SavePeriod() {
v.SetHeight(block.Height)
snapshot := v.Snapshot()
if snapshot == nil {
log.Error("snapshot is nil, key:", v.Key())
continue
}
reply := make(chan bool, 1)
m.channels[v.Key()].Save(snapshot, reply)
if !async {
<-reply
if v.Key() == txpoolCheckpointKey {
go func() {
if block.Height >=
originalHeight+v.SavePeriod() {
v.SetHeight(block.Height)
snapshot := v.Snapshot()
if snapshot == nil {
log.Error("snapshot is nil, key:", v.Key())
}
reply := make(chan bool, 1)
m.channels[v.Key()].Save(snapshot, reply)
if !async {
<-reply
}
}
}()
} else {
if block.Height >=
originalHeight+v.SavePeriod() {
v.SetHeight(block.Height)
snapshot := v.Snapshot()
if snapshot == nil {
log.Error("snapshot is nil, key:", v.Key())
continue
}
reply := make(chan bool, 1)
m.channels[v.Key()].Save(snapshot, reply)
if !async {
<-reply
}
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ func (n EventType) String() string {
// Event defines notification that is sent to the caller via the callback
// function provided during the call to New and consists of a notification type
// as well as associated data that depends on the type as follows:
// - ETBlockAccepted: *types.Block
// - ETBlockConnected: *types.Block
// - ETBlockDisconnected: *types.Block
// - ETTransactionAccepted: *types.BaseTransaction
// - ETBlockAccepted: *types.Block
// - ETBlockConnected: *types.Block
// - ETBlockDisconnected: *types.Block
// - ETTransactionAccepted: *types.BaseTransaction
type Event struct {
Type EventType
Data interface{}
}

var events struct {
mtx sync.Mutex
mtx sync.RWMutex
callbacks []EventCallback
}

Expand Down Expand Up @@ -150,12 +150,12 @@ func Notify(typ EventType, data interface{}) {
mutex.Unlock()

// Generate and send the notification.
events.mtx.Lock()
events.mtx.RLock()
n := Event{Type: typ, Data: data}
for _, callback := range events.callbacks {
callback(&n)
}
events.mtx.Unlock()
events.mtx.RUnlock()

// Reset notify count.
mutex.Lock()
Expand Down
6 changes: 3 additions & 3 deletions pow/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ func (pow *Service) GenerateBlock(minerAddr string,
var proposalsUsedAmount common.Fixed64
for _, tx := range txs {

if tx.IsIllegalProposalTx() || tx.IsIllegalVoteTx() {
continue
}
//if tx.IsIllegalProposalTx() || tx.IsIllegalVoteTx() {
// continue
//}

size := totalTxsSize + tx.GetSize()
if size > int(pact.MaxBlockContextSize) {
Expand Down

0 comments on commit 871d2a2

Please sign in to comment.