Skip to content

Commit

Permalink
It is with great excitement that the Matrix AI Network team releases …
Browse files Browse the repository at this point in the history
…the first major update to the Matrix AI Network! The primary goal of this update is to increase the stability of the network.
  • Loading branch information
MatrixAINetworkMan committed May 17, 2019
1 parent e884ff2 commit cc6d84a
Show file tree
Hide file tree
Showing 183 changed files with 6,885 additions and 16,671 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"reflect"
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/MatrixAINetwork/go-matrix/common"
"github.com/davecgh/go-spew/spew"
)

// typeWithoutStringer is a alias for the Type type which simply doesn't implement
Expand Down
4 changes: 2 additions & 2 deletions accounts/keystore/account_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ func (ac *accountCache) scanAccounts() error {
err = json.NewDecoder(buf).Decode(&key)
//addr := common.HexToAddress(key.Address)//需修改
strAddr := key.Address
addr ,err := base58.Base58DecodeToAddress(strAddr)
if err != nil{
addr, err := base58.Base58DecodeToAddress(strAddr)
if err != nil {
return nil
}
switch {
Expand Down
4 changes: 2 additions & 2 deletions accounts/keystore/account_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"testing"
"time"

"github.com/cespare/cp"
"github.com/davecgh/go-spew/spew"
"github.com/MatrixAINetwork/go-matrix/accounts"
"github.com/MatrixAINetwork/go-matrix/common"
"github.com/cespare/cp"
"github.com/davecgh/go-spew/spew"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion accounts/keystore/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/MatrixAINetwork/go-matrix/common"
"github.com/MatrixAINetwork/go-matrix/common/math"
"github.com/MatrixAINetwork/go-matrix/crypto"
"github.com/pborman/uuid"
"github.com/MatrixAINetwork/go-matrix/params"
"github.com/pborman/uuid"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion accounts/usbwallet/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"sync"
"time"

"github.com/karalabe/hid"
"github.com/MatrixAINetwork/go-matrix/accounts"
"github.com/MatrixAINetwork/go-matrix/event"
"github.com/MatrixAINetwork/go-matrix/log"
"github.com/karalabe/hid"
)

// LedgerScheme is the protocol scheme prefixing account and wallet URLs.
Expand Down
2 changes: 1 addition & 1 deletion accounts/usbwallet/internal/trezor/types.pb.go

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

2 changes: 1 addition & 1 deletion accounts/usbwallet/trezor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
"io"
"math/big"

"github.com/golang/protobuf/proto"
"github.com/MatrixAINetwork/go-matrix/accounts"
"github.com/MatrixAINetwork/go-matrix/accounts/usbwallet/internal/trezor"
"github.com/MatrixAINetwork/go-matrix/common"
"github.com/MatrixAINetwork/go-matrix/common/hexutil"
"github.com/MatrixAINetwork/go-matrix/core/types"
"github.com/MatrixAINetwork/go-matrix/log"
"github.com/golang/protobuf/proto"
)

// ErrTrezorPINNeeded is returned if opening the trezor requires a PIN code. In
Expand Down
2 changes: 1 addition & 1 deletion accounts/usbwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"sync"
"time"

"github.com/karalabe/hid"
matrix "github.com/MatrixAINetwork/go-matrix"
"github.com/MatrixAINetwork/go-matrix/accounts"
"github.com/MatrixAINetwork/go-matrix/common"
"github.com/MatrixAINetwork/go-matrix/core/types"
"github.com/MatrixAINetwork/go-matrix/log"
"github.com/karalabe/hid"
)

// Maximum time between wallet health checks to detect USB unplugs.
Expand Down
18 changes: 9 additions & 9 deletions base58/base58.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ package base58
import (
"github.com/MatrixAINetwork/go-matrix/common"
"github.com/MatrixAINetwork/go-matrix/crc8"
"github.com/pkg/errors"
"math/big"
"strings"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -152,27 +152,27 @@ func Base58EncodeToString(currency string, b common.Address) string {
return strAddr + strCrc
}

func Base58DecodeToAddress(strData string) (common.Address,error) {
func Base58DecodeToAddress(strData string) (common.Address, error) {
strData = strings.TrimSpace(strData)
if strData == "" {
return common.Address{},errors.New("input address invalid")
return common.Address{}, errors.New("input address invalid")
}
if !strings.Contains(strData, ".") {
return common.Address{},errors.New("input address invalid")
return common.Address{}, errors.New("input address invalid")
}
currency := strings.Split(strData, ".")[0]
if !common.IsValidityManCurrency(currency){
return common.Address{},errors.New("input address invalid")
if !common.IsValidityManCurrency(currency) {
return common.Address{}, errors.New("input address invalid")
}

crc := strData[len(strData)-1]
crc1 := crc8.CalCRC8([]byte(strData[0 : len(strData)-1]))
strCrc := EncodeInt(crc1 % 58)
if strCrc != string(crc){
return common.Address{},errors.New("input address invalid")
if strCrc != string(crc) {
return common.Address{}, errors.New("input address invalid")
}

tmpaddres := strings.Split(strData, ".")[1]
addres := Decode(tmpaddres[0 : len(tmpaddres)-1]) //最后一位为crc%58
return common.BytesToAddress(addres),nil
return common.BytesToAddress(addres), nil
}
3 changes: 2 additions & 1 deletion baseinterface/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package baseinterface

import (
"github.com/MatrixAINetwork/go-matrix/core/state"
"github.com/MatrixAINetwork/go-matrix/election/support"
"github.com/MatrixAINetwork/go-matrix/mc"
)
Expand Down Expand Up @@ -32,7 +33,7 @@ func NewElect(ElectPlugs string) ElectionInterface {

type ElectionInterface interface {
MinerTopGen(*mc.MasterMinerReElectionReqMsg) *mc.MasterMinerReElectionRsp
ValidatorTopGen(*mc.MasterValidatorReElectionReqMsg) *mc.MasterValidatorReElectionRsq
ValidatorTopGen(*mc.MasterValidatorReElectionReqMsg, *state.StateDBManage) *mc.MasterValidatorReElectionRsq
ToPoUpdate(support.AllNative, *mc.TopologyGraph) []mc.Alternative
// PrimarylistUpdate([]mc.TopologyNodeInfo, []mc.TopologyNodeInfo, []mc.TopologyNodeInfo, mc.TopologyNodeInfo, int) ([]mc.TopologyNodeInfo, []mc.TopologyNodeInfo, []mc.TopologyNodeInfo)
}
2 changes: 1 addition & 1 deletion blkgenor/process_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (p *Process) sendHeaderVerifyReq(header *types.Header, txsCode []*common.Re
TxsCode: txsCode,
ConsensusTurn: p.consensusTurn,
OnlineConsensusResults: onlineConsensusResults,
From: ca.GetSignAddress(),
From: ca.GetSignAddress(),
}
//send to local block verify module
localBlock := &mc.LocalBlockVerifyConsensusReq{BlkVerifyConsensusReq: p2pBlock, OriginalTxs: originalTxs, FinalTxs: finalTxs, Receipts: receipts, State: stateDB}
Expand Down
2 changes: 1 addition & 1 deletion blkverify/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func encodeVerifiedBlock(req *mc.HD_BlkConsensusReqMsg, txs []types.CoinSelfTran
if req == nil {
return nil, errors.New("req msg is nil")
}
txss:=types.GetTX(txs)
txss := types.GetTX(txs)
txSize := req.TxsCodeCount()
if txSize != len(txss) {
return nil, errors.New("txs count is not match txCodes count")
Expand Down
41 changes: 31 additions & 10 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ const (
)

var (
WhiteAddrlist = [1]Address{InterestRewardAddress}
RewardAccounts = [5]Address{BlkMinerRewardAddress, BlkValidatorRewardAddress, TxGasRewardAddress, LotteryRewardAddress, InterestRewardAddress}
WhiteAddrlist = [1]Address{InterestRewardAddress}
RewardAccounts = [5]Address{BlkMinerRewardAddress, BlkValidatorRewardAddress, TxGasRewardAddress, LotteryRewardAddress, InterestRewardAddress}
ConsensusAccounts []Address
BlackList []Address
BlackList []Address
BlackListString []string
WorkPath string
)
Expand Down Expand Up @@ -515,10 +515,10 @@ type EntrustType struct {
EnstrustSetType byte //0-按高度委托,1-按时间委托,2-按次数委托

//委托限制
StartHeight uint64 //委托起始高度
EndHeight uint64 //委托结束高度
StartTime uint64
EndTime uint64
StartHeight uint64 //委托起始高度
EndHeight uint64 //委托结束高度
StartTime uint64
EndTime uint64
EntrustCount uint32 //委托次数
}

Expand All @@ -531,7 +531,7 @@ type AuthType struct {
EndHeight uint64 //委托结束高度
StartTime uint64
EndTime uint64
EntrustCount uint32 //授权委托次数
EntrustCount uint32 //授权委托次数
}

type CoinRoot struct {
Expand All @@ -558,7 +558,7 @@ type SMakeCoin struct {
PackNum uint64
CoinAddress Address
//CoinTotal *big.Int //总发行量
PayCoinType string
PayCoinType string
}

type BroadTxkey struct {
Expand Down Expand Up @@ -705,4 +705,25 @@ type CoinConfig struct {
//PayCoinType string `json:"PayCoinType"` //发放币种
}

const COINPREFIX string = "ms_"
const COINPREFIX string = "ms_"

type LinkInfo struct {
Sbs uint64
Bn uint64
Bt uint64
}

func IsGreaterLink(linkA, linkB LinkInfo) bool {
if linkA.Sbs > linkB.Sbs {
return true
} else if linkA.Sbs == linkB.Sbs {
if linkA.Bn > linkB.Bn {
return true
} else if linkA.Bn == linkB.Bn {
if linkA.Bt > linkB.Bt {
return true
}
}
}
return false
}
16 changes: 10 additions & 6 deletions consensus/blkmanage/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ func New(support BlKSupport) (*ManBlkManage, error) {
obj.RegisterManBLkPlugs(CommonBlk, manparams.VersionBeta, manCommonplug)

obj.RegisterManBLkPlugs(BroadcastBlk, manparams.VersionBeta, manBcplug)

obj.RegisterManBLkPlugs(CommonBlk, manparams.VersionGamma, manCommonplug)

obj.RegisterManBLkPlugs(BroadcastBlk, manparams.VersionGamma, manBcplug)
return obj, nil
}

Expand All @@ -153,20 +157,20 @@ func (bd *ManBlkManage) RegisterManBLkPlugs(types string, version string, plug M
}

func (bd *ManBlkManage) ProduceBlockVersion(num uint64, preVersion string) string {
//if num == manparams.VersionNumBeta {
// return manparams.VersionBeta
//}
if num == manparams.VersionNumGamma {
return manparams.VersionGamma
}
return preVersion
}

func (bd *ManBlkManage) VerifyBlockVersion(num uint64, curVersion string, preVersion string) error {
/*if num == manparams.VersionNumBeta {
if curVersion != manparams.VersionBeta {
if num == manparams.VersionNumGamma {
if manparams.VersionCmp(curVersion, manparams.VersionGamma) != 0 {
return errors.New("版本号异常")
} else {
return nil
}
} else*/if curVersion != preVersion {
} else if curVersion != preVersion {
return errors.New("版本号异常,不等于父区块版本号")
}
return nil
Expand Down
15 changes: 12 additions & 3 deletions consensus/blkmanage/manbcblk.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (bd *ManBCBlkPlug) Prepare(version string, support BlKSupport, interval *mc
bd.baseInterface.setNumber(originHeader, num)
bd.baseInterface.setGasLimit(originHeader, parent)
bd.baseInterface.setExtra(originHeader)
onlineConsensusResults, _ := bd.baseInterface.setTopology(support, parent.Hash(), originHeader, interval, num)
onlineConsensusResults, _ := bd.baseInterface.setTopology(support, version, parent.Hash(), originHeader, interval, num)
bd.baseInterface.setSignatures(originHeader)
err = bd.setBCVrf(support, parent, originHeader)
if nil != err {
Expand Down Expand Up @@ -126,6 +126,11 @@ func (bd *ManBCBlkPlug) ProcessState(support BlKSupport, header *types.Header, a
return nil, nil, nil, nil, nil, nil, err
}

if err = support.BlockChain().ProcessStateVersionSwitch(header.Number.Uint64(), work.State); err != nil {
log.ERROR(LogManBlk, "状态树版本号切换更新状态树", err, "高度", header.Number.Uint64())
return nil, nil, nil, nil, nil, nil, err
}

mapTxs := support.TxPool().GetAllSpecialTxs()
Txs := make([]types.SelfTransaction, 0)
for _, txs := range mapTxs {
Expand Down Expand Up @@ -173,7 +178,7 @@ func (bd *ManBCBlkPlug) VerifyHeader(version string, support BlKSupport, header
}
onlineConsensusResults := make([]*mc.HD_OnlineConsensusVoteResultMsg, 0)

if err := support.ReElection().VerifyNetTopology(header, onlineConsensusResults); err != nil {
if err := support.ReElection().VerifyNetTopology(version, header, onlineConsensusResults); err != nil {
log.ERROR(LogManBlk, "验证拓扑信息失败", err, "高度", header.Number.Uint64())
return nil, err
}
Expand Down Expand Up @@ -205,6 +210,10 @@ func (bd *ManBCBlkPlug) VerifyTxsAndState(support BlKSupport, verifyHeader *type
log.ERROR(LogManBlk, "状态树更新版本号失败", err, "高度", verifyHeader.Number.Uint64())
return nil, nil, nil, nil, err
}
if err = support.BlockChain().ProcessStateVersionSwitch(verifyHeader.Number.Uint64(), work.State); err != nil {
log.ERROR(LogManBlk, "状态树版本号切换更新状态树", err, "高度", verifyHeader.Number.Uint64())
return nil, nil, nil, nil, err
}

//执行交易
work.ProcessBroadcastTransactions(support.EventMux(), verifyTxs)
Expand All @@ -213,7 +222,7 @@ func (bd *ManBCBlkPlug) VerifyTxsAndState(support BlKSupport, verifyHeader *type
currblock := types.MakeCurencyBlock(retTxs, work.Receipts, nil)
// 运行matrix状态树
block := types.NewBlock(verifyHeader, currblock, nil)
if err := support.BlockChain().ProcessMatrixState(block,string(parent.Version()), work.State); err != nil {
if err := support.BlockChain().ProcessMatrixState(block, string(parent.Version()), work.State); err != nil {
log.ERROR(LogManBlk, "广播挖矿结果验证, matrix 状态树运行错误", err)
return nil, nil, nil, nil, err
}
Expand Down
Loading

0 comments on commit cc6d84a

Please sign in to comment.