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
7 changes: 5 additions & 2 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,8 @@ func (b *BlockChain) reorganizeChain(detachNodes, attachNodes *list.List) error

// recover check point from genesis block
if recoverFromDefault {
//reset all mem state data
b.CkpManager.OnReset()
b.InitCheckpoint(nil, nil, nil)
}

Expand Down Expand Up @@ -1705,6 +1707,7 @@ func (b *BlockChain) connectBestChain(node *BlockNode, block *Block, confirm *pa
// for future processing, so add the block to the side chain holding
// cache.
log.Debugf("Adding block %x to side chain cache", node.Hash.Bytes())

b.blockCache[*node.Hash] = block
b.confirmCache[*node.Hash] = confirm
//b.Index[*node.Hash] = node
Expand Down Expand Up @@ -1833,12 +1836,13 @@ func (b *BlockChain) ReorganizeChain2(block *Block) error {
// 3. error
func (b *BlockChain) processBlock(block *Block, confirm *payload.Confirm) (bool, bool, error) {
blockHash := block.Hash()

log.Debugf("[ProcessBLock] height = %d, hash = %x", block.Header.Height, blockHash.Bytes())

// The block must not already exist in the main chain or side chains.
exists := b.BlockExists(&blockHash)
if exists {
b.blockCache[block.Hash()] = block
b.confirmCache[block.Hash()] = confirm
str := fmt.Sprintf("already have block %x height %d\n ", blockHash.Bytes(), block.Height)
return false, false, fmt.Errorf(str)
}
Expand Down Expand Up @@ -2019,7 +2023,6 @@ func (b *BlockChain) BlockLocatorFromHash(inhash *Uint256) []*Uint256 {

// The desired block height is in the main chain, so look it up
// from the main chain database.

h, err := b.GetBlockHash(uint32(blockHeight))
if err != nil {
log.Debugf("Lookup of known valid height failed %v", blockHeight)
Expand Down
4 changes: 4 additions & 0 deletions blockchain/indexers/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func (c *Checkpoint) OnRollbackTo(height uint32) error {
return nil
}

func (c *Checkpoint) OnReset() error {
return nil
}

func (c *Checkpoint) OnRollbackSeekTo(height uint32) {
return
}
Expand Down
3 changes: 0 additions & 3 deletions blockchain/txvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,6 @@ func CheckCRTransactionSignature(signature []byte, code []byte, data []byte) err
return err
}
} else if signType == vm.CHECKMULTISIG {
return errors.New("CR not support multi sign code")

// check code and signature
if err := CheckMultiSigSignatures(program.Program{
Code: code,
Parameter: signature,
Expand Down
2 changes: 1 addition & 1 deletion cmd/script/api/dposmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func newDposManager(L *lua.LState) int {
TimeSource: medianTime,
})

mockManager.Consensus = NewConsensus(dposManager, 5*time.Second, mockManager.Handler, math.MaxUint32)
mockManager.Consensus = NewConsensus(dposManager, 5*time.Second, mockManager.Handler, math.MaxUint32, 0)
mockManager.Dispatcher, mockManager.IllegalMonitor = NewDispatcherAndIllegalMonitor(ProposalDispatcherConfig{
EventMonitor: mockManager.EventMonitor,
Consensus: mockManager.Consensus,
Expand Down
12 changes: 10 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func VarIntSerializeSize(val uint64) int {
return 9
}

//get ip string from addr string
//if addr is not the format x.x.x.x:port return empt string ""
// get ip string from addr string
// if addr is not the format x.x.x.x:port return empt string ""
func GetIpFromAddr(addr string) string {
endIndex := strings.Index(addr, ":")
if endIndex < 0 {
Expand All @@ -154,3 +154,11 @@ func IsLetterOrNumber(s string) bool {
func GetNFTID(referkey, txHash Uint256) Uint256 {
return Sha256D(append(referkey[:], txHash[:]...))
}

// standard code return publickey, muticode return code
func GetOwnerKey(code []byte) []byte {
if len(code) == 35 {
return code[1 : len(code)-1]
}
return code
}
14 changes: 7 additions & 7 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (p *Configuration) TestNet() *Configuration {
p.ProhibitTransferToDIDHeight = 807000
p.DIDSideChainAddress = "XKUh4GLhFJiqAMTF6HyWQrV9pK9HcGUdfJ"
p.DPoSV2StartHeight = 965800 + 720*3
p.SupportMultiCodeHeight = 2000
p.SupportMultiCodeHeight = 1171000
p.DPoSV2EffectiveVotes = 3000 * 100000000
p.DPoSConfiguration.DPoSV2DepositCoinMinLockTime = 7200 * 3
p.DPoSConfiguration.DPoSV2MinVotesLockTime = 7200
Expand All @@ -391,17 +391,17 @@ func (p *Configuration) TestNet() *Configuration {
p.CrossChainMonitorInterval = 100
p.CRConfiguration.CRClaimPeriod = 10080
p.DPoSConfiguration.NFTStartHeight = 1098000
p.DPoSConfiguration.NFTV2StartHeight = math.MaxUint32 // todo complete me
p.DPoSConfiguration.DexStartHeight = math.MaxUint32 // todo complete me
p.DPoSConfiguration.NFTV2StartHeight = 1171000
p.DPoSConfiguration.DexStartHeight = 1171000

p.HttpInfoPort = 21333
p.HttpRestPort = 21334
p.HttpWsPort = 21335
p.HttpJsonPort = 21336
p.ProducerSchnorrStartHeight = math.MaxUint32
p.CRSchnorrStartHeight = math.MaxUint32
p.VotesSchnorrStartHeight = math.MaxUint32
p.MultiExchangeVotesStartHeight = math.MaxUint32 // todo complete me
p.ProducerSchnorrStartHeight = math.MaxUint32 // todo complete me
p.CRSchnorrStartHeight = math.MaxUint32 // todo complete me
p.VotesSchnorrStartHeight = math.MaxUint32 // todo complete me
p.MultiExchangeVotesStartHeight = 1171000

p.MemoryPoolTxMaximumStayHeight = 10

Expand Down
17 changes: 17 additions & 0 deletions core/checkpoint/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ type ICheckPoint interface {

// GetHeight returns initial height checkpoint should start with.
StartHeight() uint32

//reset
OnReset() error
}

// Manager holds checkpoints save automatically.
Expand Down Expand Up @@ -203,6 +206,20 @@ func (m *Manager) GetCheckpoint(key string, height uint32) (
}
}

func (m *Manager) OnReset() error {
m.mtx.Lock()
defer m.mtx.Unlock()

sortedPoints := m.getOrderedCheckpoints()
for i, v := range sortedPoints {
err := v.OnReset()
if err != nil {
log.Error(" Reset ", err, " i", i)
}
}
return nil
}

// Restore will load all data of each checkpoints file and store in
// corresponding meta-data.
func (m *Manager) Restore() (err error) {
Expand Down
4 changes: 4 additions & 0 deletions core/checkpoint/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func (c *checkpoint) OnRollbackSeekTo(height uint32) {
return
}

func (c *checkpoint) OnReset() error {
return nil
}

func TestManager_SaveAndRestore(t *testing.T) {
data := uint64(1)
currentHeight := uint32(10)
Expand Down
2 changes: 1 addition & 1 deletion core/transaction/cancelproducertransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (t *CancelProducerTransaction) SpecialContextCheck() (elaerr.ELAError, bool
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("can not cancel DPoS V1&V2 producer")), true
}
}

//need return Returned
if producer.State() == state.Illegal ||
producer.State() == state.Canceled {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("can not cancel this producer")), true
Expand Down
32 changes: 26 additions & 6 deletions core/transaction/crcouncilmemberclaimnodetransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"encoding/hex"
"errors"
"fmt"

"github.com/elastos/Elastos.ELA/blockchain"
"github.com/elastos/Elastos.ELA/core/contract"
"github.com/elastos/Elastos.ELA/core/types/payload"
crstate "github.com/elastos/Elastos.ELA/cr/state"
"github.com/elastos/Elastos.ELA/crypto"
Expand Down Expand Up @@ -56,13 +56,31 @@ func (t *CRCouncilMemberClaimNodeTransaction) SpecialContextCheck() (result elae
!t.parameters.BlockChain.GetCRCommittee().IsInElectionPeriod() {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("CRCouncilMemberClaimNode must during election period")), true
}
switch t.payloadVersion {
case payload.CurrentCRClaimDPoSNodeVersion, payload.NextCRClaimDPoSNodeVersion:
crMember := t.parameters.BlockChain.GetCRCommittee().GetMember(manager.CRCouncilCommitteeDID)
if crMember != nil && (!contract.IsStandard(crMember.Info.Code)) {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("CurrentCRClaimDPoSNodeVersion or NextCRClaimDPoSNodeVersion match standard code")), true
}
case payload.CurrentCRClaimDPoSNodeMultiSignVersion, payload.NextCRClaimDPoSNodeMultiSignVersion:
if !contract.IsMultiSig(t.Programs()[0].Code) {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("CurrentCRClaimDPoSNodeMultiSignVersion or NextCRClaimDPoSNodeMultiSignVersion match multi code")), true
}
programDID, err1 := getDIDFromCode(t.Programs()[0].Code)
if err1 != nil {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("can not create did from program code")), true
}
if !programDID.IsEqual(manager.CRCouncilCommitteeDID) {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("program code not match with payload CRCouncilCommitteeDID")), true
}
}

did := manager.CRCouncilCommitteeDID
var crMember *crstate.CRMember
comm := t.parameters.BlockChain.GetCRCommittee()
if t.parameters.BlockHeight >= t.parameters.Config.DPoSV2StartHeight {
switch t.payloadVersion {
case payload.CurrentCRClaimDPoSNodeVersion:
case payload.CurrentCRClaimDPoSNodeVersion, payload.CurrentCRClaimDPoSNodeMultiSignVersion:
crMember = t.parameters.BlockChain.GetCRCommittee().GetMember(did)
if _, ok := comm.ClaimedDPoSKeys[hex.EncodeToString(manager.NodePublicKey)]; ok {
return elaerr.Simple(elaerr.ErrTxPayload, fmt.Errorf("producer already registered")), true
Expand All @@ -71,7 +89,7 @@ func (t *CRCouncilMemberClaimNodeTransaction) SpecialContextCheck() (result elae
if t.parameters.BlockChain.GetState().ProducerAndCurrentCRNodePublicKeyExists(manager.NodePublicKey) {
return elaerr.Simple(elaerr.ErrTxPayload, fmt.Errorf("producer already registered")), true
}
case payload.NextCRClaimDPoSNodeVersion:
case payload.NextCRClaimDPoSNodeVersion, payload.NextCRClaimDPoSNodeMultiSignVersion:
crMember = t.parameters.BlockChain.GetCRCommittee().GetNextMember(did)
if _, ok := comm.NextClaimedDPoSKeys[hex.EncodeToString(manager.NodePublicKey)]; ok {
return elaerr.Simple(elaerr.ErrTxPayload, fmt.Errorf("producer already registered")), true
Expand Down Expand Up @@ -103,9 +121,11 @@ func (t *CRCouncilMemberClaimNodeTransaction) SpecialContextCheck() (result elae
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("invalid operating public key")), true
}

err = checkCRCouncilMemberClaimNodeSignature(manager, crMember.Info.Code)
if err != nil {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("CR claim DPOS signature check failed")), true
if t.payloadVersion < payload.CurrentCRClaimDPoSNodeMultiSignVersion {
err = checkCRCouncilMemberClaimNodeSignature(manager, crMember.Info.Code)
if err != nil {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("CR claim DPOS signature check failed")), true
}
}

return nil, false
Expand Down
24 changes: 19 additions & 5 deletions core/transaction/crcouncilmemberclaimnodetransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ func (s *txValidatorTestSuite) TestCRCouncilMemberClaimNodeTransaction() {
//publicKey2, _ := common.HexStringToBytes(publicKeyStr2)
//errPublicKeyStr := "02b611f07341d5ddce51b5c4366aca7b889cfe0993bd63fd4"
//errPublicKey, _ := common.HexStringToBytes(errPublicKeyStr)
did := randomUint168()
//did := randomUint168()
code := getCodeByPubKeyStr(publicKeyStr1)
did, _ := getDIDFromCode(code)

{
claimPayload := &payload.CRCouncilMemberClaimNode{
NodePublicKey: publicKey1,
NodePublicKey: publicKey1,
CRCouncilCommitteeDID: *did,
}

programs := []*program.Program{{
Expand Down Expand Up @@ -81,7 +85,8 @@ func (s *txValidatorTestSuite) TestCRCouncilMemberClaimNodeTransaction() {

{
claimPayload := &payload.CRCouncilMemberClaimNode{
NodePublicKey: publicKey1,
NodePublicKey: publicKey1,
CRCouncilCommitteeDID: *did,
}

programs := []*program.Program{{
Expand Down Expand Up @@ -113,6 +118,9 @@ func (s *txValidatorTestSuite) TestCRCouncilMemberClaimNodeTransaction() {
"transaction validate error: payload content invalid:producer already registered")

s.Chain.GetCRCommittee().NextMembers[*did] = &state.CRMember{
Info: payload.CRInfo{
DID: *did,
},
MemberState: state.MemberIllegal,
}
s.Chain.GetCRCommittee().NextClaimedDPoSKeys = make(map[string]struct{}, 0)
Expand All @@ -122,6 +130,9 @@ func (s *txValidatorTestSuite) TestCRCouncilMemberClaimNodeTransaction() {
"transaction validate error: payload content invalid:CR Council Member should be an elected or inactive CR members")

s.Chain.GetCRCommittee().NextMembers[*did] = &state.CRMember{
Info: payload.CRInfo{
DID: *did,
},
MemberState: state.MemberElected,
DPOSPublicKey: publicKey1,
}
Expand All @@ -130,7 +141,8 @@ func (s *txValidatorTestSuite) TestCRCouncilMemberClaimNodeTransaction() {
"transaction validate error: payload content invalid:NodePublicKey is the same as crMember.DPOSPublicKey")

claimPayload = &payload.CRCouncilMemberClaimNode{
NodePublicKey: randomBytes(22),
NodePublicKey: randomBytes(22),
CRCouncilCommitteeDID: *did,
}
txn.SetPayload(claimPayload)
err, _ = txn.SpecialContextCheck()
Expand All @@ -143,10 +155,12 @@ func (s *txValidatorTestSuite) TestCRCouncilMemberClaimNodeTransaction() {
DPOSPublicKey: randomBytes(32),
Info: payload.CRInfo{
Code: code,
DID: *did,
},
}
claimPayload = &payload.CRCouncilMemberClaimNode{
NodePublicKey: publicKey1,
NodePublicKey: publicKey1,
CRCouncilCommitteeDID: *did,
}
buf := new(bytes.Buffer)
claimPayload.SerializeUnsigned(buf, 0)
Expand Down
11 changes: 11 additions & 0 deletions core/transaction/crcproposaltransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ func (t *CRCProposalTransaction) SpecialContextCheck() (result elaerr.ELAError,
if t.parameters.BlockChain.GetCRCommittee().IsProposalFull(proposal.CRCouncilMemberDID) {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("proposal is full")), true
}

if len(proposal.OwnerKey) != 0 && len(proposal.OwnerKey) != 33 {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("OwnerKey must standard publickey")), true
}
if len(proposal.NewOwnerKey) != 0 && len(proposal.NewOwnerKey) != 33 {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("NewOwnerKey must standard publickey")), true
}
if len(proposal.SecretaryGeneralPublicKey) != 0 && len(proposal.SecretaryGeneralPublicKey) != 33 {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("SecretaryGeneralPublicKey must standard publickey")), true
}

// Check draft hash of proposal.
if t.parameters.BlockChain.GetCRCommittee().ExistDraft(proposal.DraftHash) {
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("duplicated draft proposal hash")), true
Expand Down
Loading