Skip to content

Commit

Permalink
feat(bpos): adjust the judgment rules of IllegalProposal and IllegalV…
Browse files Browse the repository at this point in the history
…otes
  • Loading branch information
RainFallsSilent committed Jun 13, 2023
1 parent 2b70cd7 commit cbce3ca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
2 changes: 2 additions & 0 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ type DPoSConfiguration struct {
NFTV2StartHeight uint32 `screw:"--NFTV2StartHeight" usage:"the start height of NFT 2.0 transaction"`
// DexStartHeight defines the height of DEX started.
DexStartHeight uint32 `screw:"--dexstartheight" usage:"the starting height of Dex support"`
// IllegalV2Height defines the height of new rule of illegal.
IllegalV2Height uint32 `screw:"--illegal" usage:"the height of new rule of illegal"`
}

type CRConfiguration struct {
Expand Down
14 changes: 13 additions & 1 deletion core/transaction/illegalproposaltransaction.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) 2017-2021 The Elastos Foundation
// Use of this source code is governed by an MIT
// license that can be found in the LICENSE file.
//
package transaction

import (
"bytes"
"errors"
"fmt"
"math"

"github.com/elastos/Elastos.ELA/blockchain"
Expand All @@ -20,6 +20,18 @@ type IllegalProposalTransaction struct {
BaseTransaction
}

func (t *IllegalProposalTransaction) HeightVersionCheck() error {
blockHeight := t.parameters.BlockHeight
chainParams := t.parameters.Config

if blockHeight >= chainParams.DPoSConfiguration.IllegalV2Height {
return errors.New(fmt.Sprintf("not support %s transaction "+
"with payload version %d after IllegalV2Height",
t.TxType().Name(), t.PayloadVersion()))
}
return nil
}

func (t *IllegalProposalTransaction) CheckTransactionInput() error {
if len(t.Inputs()) != 0 {
return errors.New("no cost transactions must has no input")
Expand Down
7 changes: 6 additions & 1 deletion core/transaction/illegalvotetransaction.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2017-2021 The Elastos Foundation
// Use of this source code is governed by an MIT
// license that can be found in the LICENSE file.
//
package transaction

import (
Expand Down Expand Up @@ -102,6 +101,12 @@ func (t *IllegalVoteTransaction) CheckDPOSIllegalVotes(d *payload.DPOSIllegalVot
return errors.New("should be same sponsor")
}

if t.parameters.BlockHeight > t.parameters.Config.DPoSConfiguration.IllegalV2Height {
if !d.Evidence.Proposal.Hash().IsEqual(d.CompareEvidence.Proposal.Hash()) {
return errors.New("should be same proposal")
}
}

if d.Evidence.Proposal.ViewOffset != d.CompareEvidence.Proposal.ViewOffset {
return errors.New("should in same view")
}
Expand Down
13 changes: 4 additions & 9 deletions mempool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ type TxPool struct {
sync.RWMutex
}

//TxReceivingInfo record the tx receiving info detail, can expend it's field in the future need
// TxReceivingInfo record the tx receiving info detail, can expend it's field in the future need
type TxReceivingInfo struct {
Height uint32
}

//append transaction to txnpool when check ok, and broadcast the transaction.
//1.check 2.check with ledger(db) 3.check with pool
// append transaction to txnpool when check ok, and broadcast the transaction.
// 1.check 2.check with ledger(db) 3.check with pool
func (mp *TxPool) AppendToTxPool(tx interfaces.Transaction) elaerr.ELAError {
mp.Lock()
defer mp.Unlock()
Expand Down Expand Up @@ -80,11 +80,6 @@ func (mp *TxPool) removeCRAppropriationConflictTransactions() {
}

func (mp *TxPool) appendToTxPool(tx interfaces.Transaction) elaerr.ELAError {
// todo complete me
if tx.IsIllegalProposalTx() || tx.IsIllegalVoteTx() {
return elaerr.Simple(elaerr.ErrTxValidation, nil)
}

txHash := tx.Hash()

// If the transaction is CR appropriation transaction, need to remove
Expand Down Expand Up @@ -206,7 +201,7 @@ func (mp *TxPool) CleanSubmittedTransactions(block *Block) {
mp.Unlock()
}

//ResendOutdatedTransactions Resend outdated transactions
// ResendOutdatedTransactions Resend outdated transactions
func (mp *TxPool) ResendOutdatedTransactions(block *Block) {
mp.Lock()
txs := make([]interfaces.Transaction, 0)
Expand Down

0 comments on commit cbce3ca

Please sign in to comment.