Skip to content
Open
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
github.com/cevaris/ordered_map v0.0.0-20190319150403-3adeae072e73
github.com/elastos/Elastos.ELA v0.7.0
github.com/elastos/Elastos.ELA v0.6.1-0.20210630074712-c34eacefbc5a
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/stretchr/testify v1.4.0
Expand Down
7 changes: 5 additions & 2 deletions interface/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ type Config struct {
// on the given height has been rollback
OnRollback func(height uint32)

//FilterType is the filter type .(FTBloom, FTDPOS and so on )
// FilterType is the filter type .(FTBloom, FTDPOS and so on )
FilterType uint8

//node version
// Node version
NodeVersion string

// Upgrade proposal type
UpgradeProposalType uint16
}

/*
Expand Down
34 changes: 30 additions & 4 deletions interface/spvservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const (
// notifyTimeout is the duration to timeout a notify to the listener, and
// resend the notify to the listener.
notifyTimeout = 10 * time.Second // 10 second

// upgrade side chain proposal type
minUpgradeProposalType = 0x0200
maxUpgradeProposalType = 0x02ff
)

type ConsensusAlgorithm byte
Expand All @@ -47,10 +51,12 @@ type spvservice struct {
listeners map[common.Uint256]TransactionListener
revertListener RevertListener
blockListener BlockListener
//FilterType is the filter type .(FTBloom, FTDPOS and so on )
// FilterType is the filter type .(FTBloom, FTDPOS and so on )
filterType uint8
// p2p Protocol version height use to change version msg content
NewP2PProtocolVersionHeight uint64
// the upgrade ProposalType
UpgradeProposalType uint16
}

// NewSPVService creates a new SPV service instance.
Expand Down Expand Up @@ -93,6 +99,7 @@ func NewSPVService(cfg *Config) (*spvservice, error) {
listeners: make(map[common.Uint256]TransactionListener),
filterType: cfg.FilterType,
NewP2PProtocolVersionHeight: cfg.ChainParams.NewP2PProtocolVersionHeight,
UpgradeProposalType: cfg.UpgradeProposalType,
}

chainStore := database.NewChainDB(headerStore, service)
Expand Down Expand Up @@ -329,16 +336,35 @@ func (s *spvservice) putTx(batch store.DataBatch, utx util.Transaction,
p.RateOfCustomIDFee, p.Hash(tx.PayloadVersion), nakedBatch); err != nil {
return false, err
}
default:
if p.ProposalType > minUpgradeProposalType && p.ProposalType <= maxUpgradeProposalType {
if err := s.db.Upgrade().BatchPutControversialUpgrade(
p.Hash(tx.PayloadVersion), p.UpgradeCodeInfo, tx.PayloadVersion, nakedBatch); err != nil {
return false, err
}
}
}
case types.CustomIDResult:
p, ok := tx.Payload.(*payload.CustomIDProposalResult)
if !ok {
return false, errors.New("invalid custom ID result tx")
}
nakedBatch := batch.GetNakedBatch()
err := s.db.CID().BatchPutCustomIDProposalResults(p.ProposalResults, nakedBatch)
if err != nil {
return false, err
for _, r := range p.ProposalResults {
switch r.ProposalType {
case payload.ReceiveCustomID, payload.ReserveCustomID, payload.ChangeCustomIDFee:
err := s.db.CID().BatchPutCustomIDProposalResult(r, nakedBatch)
if err != nil {
return false, err
}
default:
if r.ProposalType > minUpgradeProposalType && r.ProposalType <= maxUpgradeProposalType {
err := s.db.Upgrade().BatchPutUpgradeProposalResult(r, nakedBatch)
if err != nil {
return false, err
}
}
}
}
}

Expand Down
1 change: 0 additions & 1 deletion interface/store/addrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,5 @@ func (a *addrs) Clear() error {
}

func (a *addrs) Close() error {
a.Lock()
return nil
}
14 changes: 12 additions & 2 deletions interface/store/arbiters.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,29 @@ func (c *arbiters) GetByHeight(height uint32) (crcArbiters [][]byte, normalArbit
}

func (c *arbiters) Close() error {
c.Lock()
return nil
}

func (c *arbiters) Clear() error {
c.Lock()
defer c.Unlock()
it := c.db.NewIterator(dbutil.BytesPrefix(BKTArbiters), nil)
defer it.Release()
for it.Next() {
c.b.Delete(it.Key())
}
it.Release()
c.b.Delete(BKTArbPosition)
c.b.Delete(BKTArbPositions)
it = c.db.NewIterator(dbutil.BytesPrefix(BKTArbitersData), nil)
for it.Next() {
c.b.Delete(it.Key())
}
it.Release()
it = c.db.NewIterator(dbutil.BytesPrefix(BKTTransactionHeight), nil)
for it.Next() {
c.b.Delete(it.Key())
}
it.Release()
return c.db.Write(c.b, nil)
}

Expand Down
4 changes: 0 additions & 4 deletions interface/store/arbiters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ func TestArbiters(t *testing.T) {
t.Errorf("crc arbiter can not be found")
return
}




}

func checkExist(target [][]byte, src [][]byte) bool {
Expand Down
Loading