Commit f6103da0 authored by vipwzw's avatar vipwzw Committed by 33cn

update

parent 9eac9d7d
......@@ -68,24 +68,37 @@ type client struct {
wg sync.WaitGroup
}
type subConfig struct {
WriteBlockSeconds int64 `json:"writeBlockSeconds,omitempty"`
ParaRemoteGrpcClient string `json:"paraRemoteGrpcClient,omitempty"`
StartHeight int64 `json:"startHeight,omitempty"`
EmptyBlockInterval int64 `json:"emptyBlockInterval,omitempty"`
AuthAccount string `json:"authAccount,omitempty"`
WaitBlocks4CommitMsg int32 `json:"waitBlocks4CommitMsg,omitempty"`
SearchHashMatchedBlockDepth int32 `json:"searchHashMatchedBlockDepth,omitempty"`
}
// New function to init paracross env
func New(cfg *types.Consensus, sub []byte) queue.Module {
c := drivers.NewBaseClient(cfg)
if cfg.ParaRemoteGrpcClient != "" {
grpcSite = cfg.ParaRemoteGrpcClient
var subcfg subConfig
if sub != nil {
types.MustDecode(sub, &subcfg)
}
if cfg.StartHeight > 0 {
startHeight = cfg.StartHeight
if subcfg.ParaRemoteGrpcClient != "" {
grpcSite = subcfg.ParaRemoteGrpcClient
}
if cfg.WriteBlockSeconds > 0 {
blockSec = cfg.WriteBlockSeconds
if subcfg.StartHeight > 0 {
startHeight = subcfg.StartHeight
}
if cfg.EmptyBlockInterval > 0 {
emptyBlockInterval = cfg.EmptyBlockInterval
if subcfg.WriteBlockSeconds > 0 {
blockSec = subcfg.WriteBlockSeconds
}
if cfg.SearchHashMatchedBlockDepth > 0 {
searchHashMatchDepth = cfg.SearchHashMatchedBlockDepth
if subcfg.EmptyBlockInterval > 0 {
emptyBlockInterval = subcfg.EmptyBlockInterval
}
if subcfg.SearchHashMatchedBlockDepth > 0 {
searchHashMatchDepth = subcfg.SearchHashMatchedBlockDepth
}
pk, err := hex.DecodeString(minerPrivateKey)
......@@ -121,21 +134,18 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
privateKey: priKey,
isCaughtUp: false,
}
if cfg.WaitBlocks4CommitMsg < 2 {
if subcfg.WaitBlocks4CommitMsg < 2 {
panic("config WaitBlocks4CommitMsg should not less 2")
}
para.commitMsgClient = &commitMsgClient{
paraClient: para,
waitMainBlocks: cfg.WaitBlocks4CommitMsg,
waitMainBlocks: subcfg.WaitBlocks4CommitMsg,
commitMsgNotify: make(chan int64, 1),
delMsgNotify: make(chan int64, 1),
mainBlockAdd: make(chan *types.BlockDetail, 1),
quit: make(chan struct{}),
}
c.SetChild(para)
return para
}
......@@ -178,6 +188,7 @@ func (client *client) InitBlock() {
newblock.Height = 0
newblock.BlockTime = genesisBlockTime
newblock.ParentHash = zeroHash[:]
newblock.MainHash = zeroHash[:]
tx := client.CreateGenesisTx()
newblock.Txs = tx
newblock.TxHash = merkle.CalcMerkleRoot(newblock.Txs)
......@@ -661,16 +672,13 @@ func (client *client) addMinerTx(preStateHash []byte, block *types.Block, main *
MainBlockHash: main.Seq.Hash,
MainBlockHeight: main.Detail.Block.Height,
}
tx, err := paracross.CreateRawMinerTx(status)
if err != nil {
return err
}
tx.Sign(types.SECP256K1, client.privateKey)
block.Txs = append([]*types.Transaction{tx}, block.Txs...)
return nil
}
func (client *client) createBlock(lastBlock *types.Block, txs []*types.Transaction, seq int64, mainBlock *types.BlockSeq) error {
......@@ -682,8 +690,8 @@ func (client *client) createBlock(lastBlock *types.Block, txs []*types.Transacti
//挖矿固定难度
newblock.Difficulty = types.GetP(0).PowLimitBits
newblock.TxHash = merkle.CalcMerkleRoot(newblock.Txs)
newblock.BlockTime = mainBlock.Detail.Block.BlockTime
newblock.BlockTime = mainBlock.BlockTime
newblock.MainHash = mainBlock.Hash()
err := client.addMinerTx(lastBlock.StateHash, &newblock, mainBlock)
if err != nil {
return err
......
......@@ -46,7 +46,6 @@ func NewRaftCluster(cfg *types.Consensus, sub []byte) queue.Module {
if sub != nil {
types.MustDecode(sub, &subcfg)
}
if subcfg.Genesis != "" {
genesis = subcfg.Genesis
}
......
......@@ -43,7 +43,10 @@ func execBlock(client queue.Client, prevStateRoot []byte, block *types.Block, er
block.TxHash = merkle.CalcMerkleRootCache(cacheTxs)
block.Txs = types.CacheToTxs(cacheTxs)
//println("1")
receipts := util.ExecTx(client, prevStateRoot, block)
receipts, err := util.ExecTx(client, prevStateRoot, block)
if err != nil {
return nil, nil, err
}
var maplist = make(map[string]*types.KeyValue)
var kvset []*types.KeyValue
var deltxlist = make(map[int]bool)
......@@ -94,7 +97,10 @@ func execBlock(client queue.Client, prevStateRoot []byte, block *types.Block, er
var detail types.BlockDetail
calcHash = util.ExecKVMemSet(client, prevStateRoot, block.Height, kvset, sync)
calcHash, err = util.ExecKVMemSet(client, prevStateRoot, block.Height, kvset, sync)
if err != nil {
return nil, nil, err
}
//println("2")
if errReturn && !bytes.Equal(block.StateHash, calcHash) {
util.ExecKVSetRollback(client, calcHash)
......
#!/usr/bin/env bash
withdraw=$(../chain33-cli bty withdraw -e "ticket" -n "安全支出费用: $1" -a "$1")
send=$(../chain33-cli bty transfer -a "$1" -n "安全支出费用: $1" -t 1MY4pMgjpS2vWiaSDZasRhN47pcwEire32)
echo "cli wallet sign -d $withdraw -a 1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP >d:/a.txt"
echo "cli wallet sign -d $send -a 1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP >>d:/a.txt"
//这个包提供了平行链和主链的统一的访问接口
package api
import (
"context"
"errors"
"sync/atomic"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/types"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)
/*
平行链可以访问的有两条链:
1. 通过 client.QueueProtocolAPI 事件访问 平行链本身
2. 通过 grpc 接口访问主链
通过 client.QueueProtocolAPI 和 grpc 都可能会产生 网络错误,或者超时的问题
这个时候,区块做异常处理的时候需要做一些特殊处理
接口函数:
1. GetBlockByHash
2. GetLastBlockHash
3. GetRandNum
*/
//ErrAPIEnv api的执行环境出问题,区块执行的时候,遇到这一个的错误需要retry
var ErrAPIEnv = errors.New("ErrAPIEnv")
//ExecutorAPI 提供给执行器使用的接口
//因为合约是主链和平行链通用的,所以,主链和平行链都可以调用这套接口
type ExecutorAPI interface {
GetBlockByHashes(param *types.ReqHashes) (*types.BlockDetails, error)
GetRandNum(param *types.ReqRandHash) ([]byte, error)
IsErr() bool
}
type mainChainAPI struct {
api client.QueueProtocolAPI
errflag int32
}
//New 新建接口
func New(api client.QueueProtocolAPI, grpcaddr string) ExecutorAPI {
if types.IsPara() {
return newParaChainAPI(api, grpcaddr)
}
return &mainChainAPI{api: api}
}
func (api *mainChainAPI) IsErr() bool {
return atomic.LoadInt32(&api.errflag) == 1
}
func (api *mainChainAPI) GetRandNum(param *types.ReqRandHash) ([]byte, error) {
msg, err := api.api.Query(param.ExecName, "RandNumHash", param)
if err != nil {
return nil, seterr(err, &api.errflag)
}
reply, ok := msg.(*types.ReplyHash)
if !ok {
return nil, types.ErrTypeAsset
}
return reply.Hash, nil
}
func (api *mainChainAPI) GetBlockByHashes(param *types.ReqHashes) (*types.BlockDetails, error) {
data, err := api.api.GetBlockByHashes(param)
return data, seterr(err, &api.errflag)
}
type paraChainAPI struct {
api client.QueueProtocolAPI
grpcClient types.Chain33Client
errflag int32
}
func newParaChainAPI(api client.QueueProtocolAPI, grpcaddr string) ExecutorAPI {
paraRemoteGrpcClient := types.Conf("config.consensus").GStr("ParaRemoteGrpcClient")
if grpcaddr != "" {
paraRemoteGrpcClient = grpcaddr
}
if paraRemoteGrpcClient == "" {
paraRemoteGrpcClient = "127.0.0.1:8002"
}
conn, err := grpc.Dial(paraRemoteGrpcClient, grpc.WithInsecure())
if err != nil {
panic(err)
}
grpcClient := types.NewChain33Client(conn)
return &paraChainAPI{api: api, grpcClient: grpcClient}
}
func (api *paraChainAPI) IsErr() bool {
return atomic.LoadInt32(&api.errflag) == 1
}
func (api *paraChainAPI) GetRandNum(param *types.ReqRandHash) ([]byte, error) {
reply, err := api.grpcClient.QueryRandNum(context.Background(), param)
if err != nil {
return nil, seterr(err, &api.errflag)
}
return reply.Hash, nil
}
func (api *paraChainAPI) GetBlockByHashes(param *types.ReqHashes) (*types.BlockDetails, error) {
data, err := api.grpcClient.GetBlockByHashes(context.Background(), param)
return data, seterr(err, &api.errflag)
}
func seterr(err error, flag *int32) error {
if IsGrpcError(err) || IsQueueError(err) {
atomic.StoreInt32(flag, 1)
}
return err
}
//IsGrpcError 判断系统api 错误,还是 rpc 本身的错误
func IsGrpcError(err error) bool {
if err == nil {
return false
}
if err == ErrAPIEnv {
return true
}
if grpc.Code(err) == codes.Unknown {
return false
}
return true
}
//IsQueueError 是否是队列错误
func IsQueueError(err error) bool {
if err == nil {
return false
}
if err == ErrAPIEnv {
return true
}
if err == queue.ErrQueueTimeout ||
err == queue.ErrQueueChannelFull ||
err == queue.ErrIsQueueClosed {
return true
}
return false
}
package api
import (
"errors"
"testing"
"time"
"github.com/33cn/chain33/client/mocks"
"github.com/33cn/chain33/queue"
qmocks "github.com/33cn/chain33/queue/mocks"
"github.com/33cn/chain33/rpc"
"github.com/33cn/chain33/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestAPI(t *testing.T) {
api := new(mocks.QueueProtocolAPI)
eapi := New(api, "")
param := &types.ReqHashes{
Hashes: [][]byte{[]byte("hello")},
}
api.On("GetBlockByHashes", mock.Anything).Return(&types.BlockDetails{}, nil)
detail, err := eapi.GetBlockByHashes(param)
assert.Nil(t, err)
assert.Equal(t, detail, &types.BlockDetails{})
param2 := &types.ReqRandHash{
ExecName: "ticket",
BlockNum: 5,
Hash: []byte("hello"),
}
api.On("Query", "ticket", "RandNumHash", mock.Anything).Return(&types.ReplyHash{Hash: []byte("hello")}, nil)
randhash, err := eapi.GetRandNum(param2)
assert.Nil(t, err)
assert.Equal(t, randhash, []byte("hello"))
assert.Equal(t, false, eapi.IsErr())
types.SetTitleOnlyForTest("user.p.wzw.")
//testnode setup
rpcCfg := new(types.RPC)
rpcCfg.GrpcBindAddr = "127.0.0.1:8003"
rpcCfg.JrpcBindAddr = "127.0.0.1:8004"
rpcCfg.MainnetJrpcAddr = rpcCfg.JrpcBindAddr
rpcCfg.Whitelist = []string{"127.0.0.1", "0.0.0.0"}
rpcCfg.JrpcFuncWhitelist = []string{"*"}
rpcCfg.GrpcFuncWhitelist = []string{"*"}
rpc.InitCfg(rpcCfg)
server := rpc.NewGRpcServer(&qmocks.Client{}, api)
assert.NotNil(t, server)
go server.Listen()
time.Sleep(time.Second)
eapi = New(api, "")
_, err = eapi.GetBlockByHashes(param)
assert.Equal(t, true, IsGrpcError(err))
assert.Equal(t, false, IsGrpcError(nil))
assert.Equal(t, false, IsGrpcError(errors.New("xxxx")))
assert.Equal(t, true, eapi.IsErr())
eapi = New(api, "127.0.0.1:8003")
detail, err = eapi.GetBlockByHashes(param)
assert.Equal(t, err, nil)
assert.Equal(t, detail, &types.BlockDetails{})
randhash, err = eapi.GetRandNum(param2)
assert.Nil(t, err)
assert.Equal(t, randhash, []byte("hello"))
assert.Equal(t, false, eapi.IsErr())
//queue err
assert.Equal(t, false, IsQueueError(nil))
assert.Equal(t, false, IsQueueError(errors.New("xxxx")))
assert.Equal(t, true, IsQueueError(queue.ErrQueueTimeout))
assert.Equal(t, true, IsQueueError(queue.ErrIsQueueClosed))
assert.Equal(t, false, IsQueueError(errors.New("ErrIsQueueClosed")))
}
......@@ -78,7 +78,10 @@ func main() {
log.Info("execblock", "block height", *height)
prevState := blocks.Items[0].Block.StateHash
block := blocks.Items[1].Block
receipt := util.ExecTx(q.Client(), prevState, block)
receipt, err := util.ExecTx(q.Client(), prevState, block)
if err != nil {
panic(err)
}
for i, r := range receipt.GetReceipts() {
println("=======================")
println("tx index ", i)
......
......@@ -9,6 +9,7 @@ import (
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/client/api"
"github.com/33cn/chain33/common/address"
dbm "github.com/33cn/chain33/common/db"
drivers "github.com/33cn/chain33/system/dapp"
......@@ -21,29 +22,39 @@ type executor struct {
stateDB dbm.KV
localDB dbm.KVDB
coinsAccount *account.DB
ctx *executorCtx
height int64
blocktime int64
// 增加区块的难度值,后面的执行器逻辑需要这些属性
difficulty uint64
txs []*types.Transaction
api client.QueueProtocolAPI
execapi api.ExecutorAPI
receipts []*types.ReceiptData
}
func newExecutor(stateHash []byte, exec *Executor, height, blocktime int64, difficulty uint64,
txs []*types.Transaction, receipts []*types.ReceiptData) *executor {
type executorCtx struct {
stateHash []byte
height int64
blocktime int64
difficulty uint64
parentHash []byte
mainHash []byte
}
func newExecutor(ctx *executorCtx, exec *Executor, txs []*types.Transaction, receipts []*types.ReceiptData) *executor {
client := exec.client
enableMVCC := exec.pluginEnable["mvcc"]
opt := &StateDBOption{EnableMVCC: enableMVCC, Height: height}
opt := &StateDBOption{EnableMVCC: enableMVCC, Height: ctx.height}
localdb := NewLocalDB(client)
e := &executor{
stateDB: NewStateDB(client, stateHash, localdb, opt),
stateDB: NewStateDB(client, ctx.stateHash, localdb, opt),
localDB: localdb,
coinsAccount: account.NewCoinsAccount(),
height: height,
blocktime: blocktime,
difficulty: difficulty,
height: ctx.height,
blocktime: ctx.blocktime,
difficulty: ctx.difficulty,
ctx: ctx,
txs: txs,
receipts: receipts,
}
......@@ -135,8 +146,9 @@ func (e *executor) checkTx(tx *types.Transaction, index int) error {
func (e *executor) setEnv(exec drivers.Driver) {
exec.SetStateDB(e.stateDB)
exec.SetLocalDB(e.localDB)
exec.SetEnv(e.height, e.blocktime, e.difficulty)
exec.SetEnv(e.height, e.blocktime, e.difficulty, e.ctx.parentHash, e.ctx.mainHash)
exec.SetAPI(e.api)
e.execapi = exec.GetExecutorAPI()
exec.SetTxs(e.txs)
exec.SetReceipt(e.receipts)
}
......
......@@ -11,6 +11,7 @@ import (
"sync"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/client/api"
clog "github.com/33cn/chain33/common/log"
log "github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/pluginmgr"
......@@ -156,7 +157,15 @@ func (exec *Executor) procExecQuery(msg queue.Message) {
func (exec *Executor) procExecCheckTx(msg queue.Message) {
datas := msg.GetData().(*types.ExecTxList)
execute := newExecutor(datas.StateHash, exec, datas.Height, datas.BlockTime, datas.Difficulty, datas.Txs, nil)
ctx := &executorCtx{
stateHash: datas.StateHash,
height: datas.Height,
blocktime: datas.BlockTime,
difficulty: datas.Difficulty,
mainHash: datas.MainHash,
parentHash: datas.ParentHash,
}
execute := newExecutor(ctx, exec, datas.Txs, nil)
execute.enableMVCC()
execute.api = exec.qclient
//返回一个列表表示成功还是失败
......@@ -179,7 +188,15 @@ func (exec *Executor) procExecCheckTx(msg queue.Message) {
func (exec *Executor) procExecTxList(msg queue.Message) {
datas := msg.GetData().(*types.ExecTxList)
execute := newExecutor(datas.StateHash, exec, datas.Height, datas.BlockTime, datas.Difficulty, datas.Txs, nil)
ctx := &executorCtx{
stateHash: datas.StateHash,
height: datas.Height,
blocktime: datas.BlockTime,
difficulty: datas.Difficulty,
mainHash: datas.MainHash,
parentHash: datas.ParentHash,
}
execute := newExecutor(ctx, exec, datas.Txs, nil)
execute.enableMVCC()
execute.api = exec.qclient
var receipts []*types.Receipt
......@@ -193,6 +210,10 @@ func (exec *Executor) procExecTxList(msg queue.Message) {
}
if tx.GroupCount == 0 {
receipt, err := execute.execTx(tx, index)
if api.IsGrpcError(err) || api.IsQueueError(err) {
msg.Reply(exec.client.NewMessage("", types.EventReceipts, err))
return
}
if err != nil {
receipts = append(receipts, types.NewErrReceipt(err))
continue
......@@ -232,7 +253,15 @@ func (exec *Executor) procExecTxList(msg queue.Message) {
func (exec *Executor) procExecAddBlock(msg queue.Message) {
datas := msg.GetData().(*types.BlockDetail)
b := datas.Block
execute := newExecutor(b.StateHash, exec, b.Height, b.BlockTime, uint64(b.Difficulty), b.Txs, datas.Receipts)
ctx := &executorCtx{
stateHash: b.StateHash,
height: b.Height,
blocktime: b.BlockTime,
difficulty: uint64(b.Difficulty),
mainHash: b.MainHash,
parentHash: b.ParentHash,
}
execute := newExecutor(ctx, exec, b.Txs, datas.Receipts)
execute.enableMVCC()
execute.api = exec.qclient
var kvset types.LocalDBSet
......@@ -284,7 +313,15 @@ func (exec *Executor) procExecAddBlock(msg queue.Message) {
func (exec *Executor) procExecDelBlock(msg queue.Message) {
datas := msg.GetData().(*types.BlockDetail)
b := datas.Block
execute := newExecutor(b.StateHash, exec, b.Height, b.BlockTime, uint64(b.Difficulty), b.Txs, nil)
ctx := &executorCtx{
stateHash: b.StateHash,
height: b.Height,
blocktime: b.BlockTime,
difficulty: uint64(b.Difficulty),
mainHash: b.MainHash,
parentHash: b.ParentHash,
}
execute := newExecutor(ctx, exec, b.Txs, nil)
execute.enableMVCC()
execute.api = exec.qclient
var kvset types.LocalDBSet
......
......@@ -49,7 +49,15 @@ func TestExecutorGetTxGroup(t *testing.T) {
txgroup.SignN(1, types.SECP256K1, priv2)
txgroup.SignN(2, types.SECP256K1, priv3)
txs = txgroup.GetTxs()
execute := newExecutor(nil, exec, 1, time.Now().Unix(), 1, txs, nil)
ctx := &executorCtx{
stateHash: nil,
height: 1,
blocktime: time.Now().Unix(),
difficulty: 1,
mainHash: nil,
parentHash: nil,
}
execute := newExecutor(ctx, exec, txs, nil)
e := execute.loadDriver(txs[0], 0)
execute.setEnv(e)
txs2 := e.GetTxs()
......@@ -64,7 +72,7 @@ func TestExecutorGetTxGroup(t *testing.T) {
//err tx group list
txs[0].Header = nil
execute = newExecutor(nil, exec, 1, time.Now().Unix(), 1, txs, nil)
execute = newExecutor(ctx, exec, txs, nil)
e = execute.loadDriver(txs[0], 0)
execute.setEnv(e)
_, err = e.GetTxGroup(len(txs) - 1)
......
......@@ -76,7 +76,7 @@ func (client *client) Send(msg Message, waitReply bool) (err error) {
timeout = time.Minute
}
err = client.SendTimeout(msg, waitReply, timeout)
if err == types.ErrTimeout {
if err == ErrQueueTimeout {
panic(err)
}
return err
......@@ -85,7 +85,7 @@ func (client *client) Send(msg Message, waitReply bool) (err error) {
// SendTimeout 超时发送, msg 消息 ,waitReply 是否等待回应, timeout 超时时间
func (client *client) SendTimeout(msg Message, waitReply bool, timeout time.Duration) (err error) {
if client.isClose() {
return types.ErrIsClosed
return ErrIsQueueClosed
}
if !waitReply {
msg.chReply = nil
......@@ -115,9 +115,9 @@ func (client *client) WaitTimeout(msg Message, timeout time.Duration) (Message,
case msg = <-msg.chReply:
return msg, msg.Err()
case <-client.done:
return Message{}, errors.New("client is closed")
return Message{}, ErrIsQueueClosed
case <-t.C:
return Message{}, types.ErrTimeout
return Message{}, ErrQueueTimeout
}
}
......@@ -128,7 +128,7 @@ func (client *client) Wait(msg Message) (Message, error) {
timeout = 5 * time.Minute
}
msg, err := client.WaitTimeout(msg, timeout)
if err == types.ErrTimeout {
if err == ErrQueueTimeout {
panic(err)
}
return msg, err
......
......@@ -6,6 +6,7 @@
package queue
import (
"errors"
"fmt"
"os"
"os/signal"
......@@ -32,6 +33,13 @@ const (
defaultLowChanBuffer = 40960
)
//消息队列的错误
var (
ErrIsQueueClosed = errors.New("ErrIsQueueClosed")
ErrQueueTimeout = errors.New("ErrQueueTimeout")
ErrQueueChannelFull = errors.New("ErrQueueChannelFull")
)
// DisableLog disable log
func DisableLog() {
qlog.SetHandler(log.DiscardHandler())
......@@ -162,7 +170,7 @@ func (q *queue) send(msg Message, timeout time.Duration) (err error) {
return nil
default:
qlog.Debug("send chainfull", "msg", msg, "topic", msg.Topic, "sub", sub)
return types.ErrChannelFull
return ErrQueueChannelFull
}
}
t := time.NewTimer(timeout)
......@@ -171,7 +179,7 @@ func (q *queue) send(msg Message, timeout time.Duration) (err error) {
case sub.high <- msg:
case <-t.C:
qlog.Debug("send timeout", "msg", msg, "topic", msg.Topic, "sub", sub)
return types.ErrTimeout
return ErrQueueTimeout
}
if msg.Topic != "store" {
qlog.Debug("send ok", "msg", msg, "topic", msg.Topic, "sub", sub)
......@@ -192,8 +200,8 @@ func (q *queue) sendAsyn(msg Message) error {
qlog.Debug("send asyn ok", "msg", msg)
return nil
default:
qlog.Error("send asyn err", "msg", msg, "err", types.ErrChannelFull)
return types.ErrChannelFull
qlog.Error("send asyn err", "msg", msg, "err", ErrQueueChannelFull)
return ErrQueueChannelFull
}
}
......@@ -216,7 +224,7 @@ func (q *queue) sendLowTimeout(msg Message, timeout time.Duration) error {
return nil
case <-t.C:
qlog.Error("send asyn timeout", "msg", msg)
return types.ErrTimeout
return ErrQueueTimeout
}
}
......
......@@ -43,14 +43,14 @@ func TestTimeout(t *testing.T) {
//再发送一个交易返回chain full
err := client.SendTimeout(msg, true, 0)
if err != types.ErrChannelFull {
if err != ErrQueueChannelFull {
t.Error(err)
return
}
//发送一个交易返回返回timeout
err = client.SendTimeout(msg, true, time.Millisecond)
if err != types.ErrTimeout {
if err != ErrQueueTimeout {
t.Error(err)
return
}
......
......@@ -15,6 +15,7 @@ import (
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/client/api"
"github.com/33cn/chain33/common/address"
dbm "github.com/33cn/chain33/common/db"
log "github.com/33cn/chain33/common/log/log15"
......@@ -41,13 +42,14 @@ type Driver interface {
GetDriverName() string
//执行器的别名(一个驱动(code),允许创建多个执行器,类似evm一份代码可以创建多个合约)
GetName() string
GetExecutorAPI() api.ExecutorAPI
//设置执行器的真实名称
SetName(string)
SetCurrentExecName(string)
Allow(tx *types.Transaction, index int) error
IsFriend(myexec []byte, writekey []byte, othertx *types.Transaction) bool
GetActionName(tx *types.Transaction) string
SetEnv(height, blocktime int64, difficulty uint64)
SetEnv(height, blocktime int64, difficulty uint64, parentHash, mainHash []byte)
CheckTx(tx *types.Transaction, index int) error
Exec(tx *types.Transaction, index int) (*types.Receipt, error)
ExecLocal(tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error)
......@@ -69,21 +71,23 @@ type Driver interface {
// DriverBase defines driverbase type
type DriverBase struct {
statedb dbm.KV
localdb dbm.KVDB
coinsaccount *account.DB
height int64
blocktime int64
name string
curname string
child Driver
childValue reflect.Value
isFree bool
difficulty uint64
api client.QueueProtocolAPI
txs []*types.Transaction
receipts []*types.ReceiptData
ety types.ExecutorType
statedb dbm.KV
localdb dbm.KVDB
coinsaccount *account.DB
height int64
blocktime int64
parentHash, mainHash []byte
name string
curname string
child Driver
childValue reflect.Value
isFree bool
difficulty uint64
api client.QueueProtocolAPI
execapi api.ExecutorAPI
txs []*types.Transaction
receipts []*types.ReceiptData
ety types.ExecutorType
}
// GetPayloadValue define get payload func
......@@ -99,6 +103,19 @@ func (d *DriverBase) GetExecutorType() types.ExecutorType {
return d.ety
}
//GetLastHash 获取最后区块的hash,主链和平行链不同
func (d *DriverBase) GetLastHash() []byte {
if types.IsPara() {
return d.mainHash
}
return d.parentHash
}
//GetParentHash 获取上一个区块的hash
func (d *DriverBase) GetParentHash() []byte {
return d.parentHash
}
// GetFuncMap defines get execfuncmap func
func (d *DriverBase) GetFuncMap() map[string]reflect.Method {
if d.ety == nil {
......@@ -108,8 +125,9 @@ func (d *DriverBase) GetFuncMap() map[string]reflect.Method {
}
// SetAPI set queue protocol api
func (d *DriverBase) SetAPI(api client.QueueProtocolAPI) {
d.api = api
func (d *DriverBase) SetAPI(queueapi client.QueueProtocolAPI) {
d.api = queueapi
d.execapi = api.New(queueapi, "")
}
// GetAPI return queue protocol api
......@@ -117,11 +135,18 @@ func (d *DriverBase) GetAPI() client.QueueProtocolAPI {
return d.api
}
// GetExecutorAPI return executor api
func (d *DriverBase) GetExecutorAPI() api.ExecutorAPI {
return d.execapi
}
// SetEnv set env
func (d *DriverBase) SetEnv(height, blocktime int64, difficulty uint64) {
func (d *DriverBase) SetEnv(height, blocktime int64, difficulty uint64, parentHash, mainHash []byte) {
d.height = height
d.blocktime = blocktime
d.difficulty = difficulty
d.parentHash = parentHash
d.mainHash = mainHash
}
// SetIsFree set isfree
......
......@@ -2,8 +2,11 @@ package dapp
import (
"testing"
"time"
"github.com/33cn/chain33/client/mocks"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
"github.com/stretchr/testify/assert"
)
......@@ -35,9 +38,12 @@ func (none *noneApp) GetDriverName() string {
return "none"
}
func TestReigister(t *testing.T) {
func init() {
Register("none", newnoneApp, 0)
Register("demo", newdemoApp, 1)
}
func TestReigister(t *testing.T) {
_, err := LoadDriver("demo", 0)
assert.Equal(t, err, types.ErrUnknowDriver)
_, err = LoadDriver("demo", 1)
......@@ -65,6 +71,47 @@ func TestReigister(t *testing.T) {
assert.Equal(t, "none", driver.GetDriverName())
}
func TestDriverAPI(t *testing.T) {
tx := &types.Transaction{Execer: []byte("demo")}
demo := LoadDriverAllow(tx, 0, 1).(*demoApp)
dir, ldb, kvdb := util.CreateTestDB()
defer util.CloseTestDB(dir, ldb)
demo.SetEnv(1, time.Now().Unix(), 1, []byte("parentHash"), []byte("mainHash"))
demo.SetLocalDB(kvdb)
demo.SetStateDB(kvdb)
demo.SetAPI(&mocks.QueueProtocolAPI{})
assert.NotNil(t, demo.GetAPI())
assert.NotNil(t, demo.GetExecutorAPI())
types.SetTitleOnlyForTest("chain33")
assert.Equal(t, "parentHash", string(demo.GetParentHash()))
assert.Equal(t, "parentHash", string(demo.GetLastHash()))
types.SetTitleOnlyForTest("user.p.wzw.")
assert.Equal(t, "parentHash", string(demo.GetParentHash()))
assert.Equal(t, "mainHash", string(demo.GetLastHash()))
assert.Equal(t, true, IsDriverAddress(ExecAddress("none"), 0))
assert.Equal(t, false, IsDriverAddress(ExecAddress("demo"), 0))
assert.Equal(t, true, IsDriverAddress(ExecAddress("demo"), 1))
}
func TestExecAddress(t *testing.T) {
assert.Equal(t, "16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp", ExecAddress("ticket"))
}
func TestAllow(t *testing.T) {
tx := &types.Transaction{Execer: []byte("demo")}
demo := LoadDriverAllow(tx, 0, 1).(*demoApp)
assert.Equal(t, true, demo.AllowIsSame([]byte("demo")))
types.SetTitleOnlyForTest("user.p.wzw.")
assert.Equal(t, true, demo.AllowIsSame([]byte("user.p.wzw.demo")))
assert.Equal(t, false, demo.AllowIsSame([]byte("user.p.wzw2.demo")))
assert.Equal(t, false, demo.AllowIsUserDot1([]byte("user.p.wzw.demo")))
assert.Equal(t, true, demo.AllowIsUserDot1([]byte("user.demo")))
assert.Equal(t, true, demo.AllowIsUserDot1([]byte("user.p.wzw.user.demo")))
assert.Equal(t, true, demo.AllowIsUserDot2([]byte("user.p.wzw.user.demo.xxxx")))
assert.Equal(t, true, demo.AllowIsUserDot2([]byte("user.demo.xxxx")))
assert.Equal(t, nil, demo.Allow(tx, 0))
tx = &types.Transaction{Execer: []byte("demo2")}
assert.Equal(t, types.ErrNotAllow, demo.Allow(tx, 0))
assert.Equal(t, false, demo.IsFriend(nil, nil, nil))
}
......@@ -7,23 +7,12 @@ package dapp
//store package store the world - state data
import (
"github.com/33cn/chain33/common/address"
clog "github.com/33cn/chain33/common/log"
log "github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
)
var elog = log.New("module", "execs")
// SetLogLevel set log level
func SetLogLevel(level string) {
clog.SetLogLevel(level)
}
// DisableLog disable log
func DisableLog() {
elog.SetHandler(log.DiscardHandler())
}
// DriverCreate defines a drivercreate function
type DriverCreate func() Driver
......
......@@ -143,6 +143,7 @@ func (m *Header) GetSignature() *Signature {
}
// 参考Header解释
// mainHash 平行链上使用的字段,代表这个区块的主链hash
type Block struct {
Version int64 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"`
ParentHash []byte `protobuf:"bytes,2,opt,name=parentHash,proto3" json:"parentHash,omitempty"`
......@@ -151,6 +152,7 @@ type Block struct {
Height int64 `protobuf:"varint,5,opt,name=height,proto3" json:"height,omitempty"`
BlockTime int64 `protobuf:"varint,6,opt,name=blockTime,proto3" json:"blockTime,omitempty"`
Difficulty uint32 `protobuf:"varint,11,opt,name=difficulty,proto3" json:"difficulty,omitempty"`
MainHash []byte `protobuf:"bytes,12,opt,name=mainHash,proto3" json:"mainHash,omitempty"`
Signature *Signature `protobuf:"bytes,8,opt,name=signature,proto3" json:"signature,omitempty"`
Txs []*Transaction `protobuf:"bytes,7,rep,name=txs,proto3" json:"txs,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
......@@ -232,6 +234,13 @@ func (m *Block) GetDifficulty() uint32 {
return 0
}
func (m *Block) GetMainHash() []byte {
if m != nil {
return m.MainHash
}
return nil
}
func (m *Block) GetSignature() *Signature {
if m != nil {
return m.Signature
......@@ -1540,74 +1549,75 @@ func init() {
func init() { proto.RegisterFile("blockchain.proto", fileDescriptor_e9ac6287ce250c9a) }
var fileDescriptor_e9ac6287ce250c9a = []byte{
// 1097 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x56, 0x5f, 0x6f, 0xe3, 0x44,
0x10, 0x97, 0xf3, 0xaf, 0xc9, 0x24, 0x0d, 0xbd, 0x55, 0x40, 0x51, 0x05, 0x5c, 0x6e, 0x39, 0x1d,
0x51, 0x39, 0xa5, 0x52, 0x8b, 0x8e, 0x7b, 0x00, 0x09, 0x9a, 0x22, 0xb5, 0xd7, 0xe3, 0x28, 0xdb,
0x5e, 0x1f, 0x78, 0xdb, 0xda, 0xdb, 0xda, 0x6a, 0xfc, 0xa7, 0xde, 0x75, 0x88, 0xf9, 0x0e, 0x7c,
0x0a, 0xde, 0x10, 0x1f, 0x12, 0xed, 0xec, 0x3a, 0xb6, 0x43, 0x8b, 0x84, 0xc4, 0x0b, 0x6f, 0x3b,
0xff, 0x67, 0x7e, 0xe3, 0x99, 0x31, 0xec, 0x5c, 0x2f, 0x62, 0xf7, 0xce, 0xf5, 0x79, 0x10, 0xcd,
0x92, 0x34, 0x56, 0x31, 0x69, 0xab, 0x3c, 0x11, 0x72, 0xf7, 0x89, 0x4a, 0x79, 0x24, 0xb9, 0xab,
0x82, 0xd8, 0x4a, 0x76, 0x07, 0x6e, 0x1c, 0x86, 0x05, 0x45, 0xff, 0x6c, 0x40, 0xe7, 0x44, 0x70,
0x4f, 0xa4, 0x64, 0x0c, 0x5b, 0x4b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xf4, 0xe7,
0x4f, 0x6e, 0x03, 0xe5, 0x67, 0xd7, 0x33, 0x37, 0x0e, 0xf7, 0x0f, 0x0f, 0xdd, 0x68, 0x1f, 0xff,
0x69, 0x0f, 0x0f, 0xf7, 0xd1, 0xeb, 0x75, 0x07, 0x7f, 0x5a, 0x0f, 0xff, 0x0a, 0x00, 0x00, 0xff,
0xff, 0x23, 0x1c, 0x7b, 0x8c, 0xf0, 0x0a, 0x00, 0x00,
// 1112 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x56, 0xdd, 0x6e, 0x1b, 0xc5,
0x17, 0xd7, 0xfa, 0x2b, 0xf6, 0xb1, 0xe3, 0x7f, 0x3a, 0xf2, 0x1f, 0x59, 0x11, 0x50, 0x77, 0xa8,
0x8a, 0x15, 0x2a, 0x47, 0x4a, 0x50, 0xe9, 0x05, 0x48, 0x10, 0x07, 0x29, 0x69, 0x4a, 0x09, 0x93,
0x34, 0x17, 0xdc, 0x4d, 0xd6, 0x93, 0xec, 0x28, 0xde, 0x8f, 0xec, 0xcc, 0x1a, 0x9b, 0x77, 0xe0,
0x45, 0x10, 0xef, 0xc0, 0xab, 0xa1, 0x39, 0x33, 0xeb, 0xdd, 0x35, 0x09, 0xa8, 0x97, 0xdc, 0x9d,
0xef, 0x8f, 0xdf, 0xd9, 0x39, 0x67, 0x61, 0xe7, 0x7a, 0x1e, 0xfb, 0x77, 0x7e, 0xc0, 0x65, 0x34,
0x49, 0xd2, 0x58, 0xc7, 0xa4, 0xa9, 0x57, 0x89, 0x50, 0xbb, 0x4f, 0x74, 0xca, 0x23, 0xc5, 0x7d,
0x2d, 0x63, 0xa7, 0xd9, 0xed, 0xf9, 0x71, 0x18, 0xe6, 0x1c, 0xfd, 0xa3, 0x06, 0xad, 0x13, 0xc1,
0x67, 0x22, 0x25, 0x43, 0xd8, 0x5a, 0x88, 0x54, 0xc9, 0x38, 0x1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x19, 0xa8, 0x94, 0x4b, 0xe0, 0x6a, 0x5c, 0xf3, 0x47, 0x4f, 0x7f, 0xfe, 0xe4,
0x56, 0xea, 0x20, 0xbb, 0x9e, 0xf8, 0x71, 0xb8, 0x7f, 0x78, 0xe8, 0x47, 0xfb, 0xf8, 0xbf, 0x7b,
0x78, 0xb8, 0x8f, 0x51, 0xaf, 0x5b, 0xf8, 0x43, 0x7b, 0xf8, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff,
0xb8, 0xed, 0x1e, 0x31, 0x0c, 0x0b, 0x00, 0x00,
}
......@@ -65,19 +65,12 @@ type Mempool struct {
// Consensus 配置
type Consensus struct {
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
GenesisBlockTime int64 `protobuf:"varint,2,opt,name=genesisBlockTime" json:"genesisBlockTime,omitempty"`
Minerstart bool `protobuf:"varint,3,opt,name=minerstart" json:"minerstart,omitempty"`
Genesis string `protobuf:"bytes,4,opt,name=genesis" json:"genesis,omitempty"`
HotkeyAddr string `protobuf:"bytes,5,opt,name=hotkeyAddr" json:"hotkeyAddr,omitempty"`
ForceMining bool `protobuf:"varint,6,opt,name=forceMining" json:"forceMining,omitempty"`
WriteBlockSeconds int64 `protobuf:"varint,20,opt,name=writeBlockSeconds" json:"writeBlockSeconds,omitempty"`
ParaRemoteGrpcClient string `protobuf:"bytes,22,opt,name=paraRemoteGrpcClient" json:"paraRemoteGrpcClient,omitempty"`
StartHeight int64 `protobuf:"varint,23,opt,name=startHeight" json:"startHeight,omitempty"`
EmptyBlockInterval int64 `protobuf:"varint,24,opt,name=emptyBlockInterval" json:"emptyBlockInterval,omitempty"`
AuthAccount string `protobuf:"bytes,25,opt,name=authAccount" json:"authAccount,omitempty"`
WaitBlocks4CommitMsg int32 `protobuf:"varint,26,opt,name=waitBlocks4CommitMsg" json:"waitBlocks4CommitMsg,omitempty"`
SearchHashMatchedBlockDepth int32 `protobuf:"varint,27,opt,name=searchHashMatchedBlockDepth" json:"searchHashMatchedBlockDepth,omitempty"`
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
GenesisBlockTime int64 `protobuf:"varint,2,opt,name=genesisBlockTime" json:"genesisBlockTime,omitempty"`
Minerstart bool `protobuf:"varint,3,opt,name=minerstart" json:"minerstart,omitempty"`
Genesis string `protobuf:"bytes,4,opt,name=genesis" json:"genesis,omitempty"`
HotkeyAddr string `protobuf:"bytes,5,opt,name=hotkeyAddr" json:"hotkeyAddr,omitempty"`
ForceMining bool `protobuf:"varint,6,opt,name=forceMining" json:"forceMining,omitempty"`
}
// Wallet 配置
......
......@@ -27,7 +27,6 @@ var (
ErrReRunGenesis = errors.New("ErrReRunGenesis")
ErrActionNotSupport = errors.New("ErrActionNotSupport")
ErrQueryNotSupport = errors.New("ErrQueryNotSupport")
ErrChannelFull = errors.New("ErrChannelFull")
ErrAmount = errors.New("ErrAmount")
ErrMinerIsStared = errors.New("ErrMinerIsStared")
ErrMinerNotStared = errors.New("ErrMinerNotStared")
......@@ -57,11 +56,11 @@ var (
ErrToAddrNotSameToExecAddr = errors.New("ErrToAddrNotSameToExecAddr")
ErrTypeAsset = errors.New("ErrTypeAsset")
ErrEmpty = errors.New("ErrEmpty")
ErrIsClosed = errors.New("ErrIsClosed")
ErrSendSameToRecv = errors.New("ErrSendSameToRecv")
ErrExecNameNotAllow = errors.New("ErrExecNameNotAllow")
ErrExecNotFound = errors.New("ErrExecNotFound")
ErrLocalDBPerfix = errors.New("ErrLocalDBPerfix")
ErrTimeout = errors.New("ErrTimeout")
ErrBlockHeaderDifficulty = errors.New("ErrBlockHeaderDifficulty")
ErrNoTx = errors.New("ErrNoTx")
ErrTxExist = errors.New("ErrTxExist")
......@@ -99,7 +98,6 @@ var (
ErrBlockHeightNoMatch = errors.New("ErrBlockHeightNoEqual")
ErrParentTdNoExist = errors.New("ErrParentTdNoExist")
ErrBlockHashNoMatch = errors.New("ErrBlockHashNoMatch")
ErrIsClosed = errors.New("ErrIsClosed")
ErrDecode = errors.New("ErrDecode")
ErrNotRollBack = errors.New("ErrNotRollBack")
ErrPeerInfoIsNil = errors.New("ErrPeerInfoIsNil")
......
......@@ -62,6 +62,8 @@ func (m *Genesis) GetIsrun() bool {
type ExecTxList struct {
StateHash []byte `protobuf:"bytes,1,opt,name=stateHash,proto3" json:"stateHash,omitempty"`
ParentHash []byte `protobuf:"bytes,7,opt,name=parentHash,proto3" json:"parentHash,omitempty"`
MainHash []byte `protobuf:"bytes,8,opt,name=mainHash,proto3" json:"mainHash,omitempty"`
Txs []*Transaction `protobuf:"bytes,2,rep,name=txs,proto3" json:"txs,omitempty"`
BlockTime int64 `protobuf:"varint,3,opt,name=blockTime,proto3" json:"blockTime,omitempty"`
Height int64 `protobuf:"varint,4,opt,name=height,proto3" json:"height,omitempty"`
......@@ -104,6 +106,20 @@ func (m *ExecTxList) GetStateHash() []byte {
return nil
}
func (m *ExecTxList) GetParentHash() []byte {
if m != nil {
return m.ParentHash
}
return nil
}
func (m *ExecTxList) GetMainHash() []byte {
if m != nil {
return m.MainHash
}
return nil
}
func (m *ExecTxList) GetTxs() []*Transaction {
if m != nil {
return m.Txs
......@@ -816,45 +832,46 @@ func init() {
func init() { proto.RegisterFile("executor.proto", fileDescriptor_12d1cdcda51e000f) }
var fileDescriptor_12d1cdcda51e000f = []byte{
// 633 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x61, 0x6b, 0xdb, 0x48,
0x10, 0x3d, 0x59, 0x76, 0x1c, 0x8f, 0x7d, 0x21, 0xd9, 0x3b, 0x0e, 0x11, 0xae, 0x89, 0x51, 0xd2,
0xd4, 0xd0, 0xe2, 0x80, 0x4d, 0x7f, 0x40, 0x63, 0x4a, 0x1d, 0x68, 0x0a, 0x55, 0xdc, 0x2f, 0xf9,
0x50, 0xd8, 0xac, 0xc7, 0xf6, 0x12, 0x7b, 0x57, 0xec, 0x8e, 0x82, 0xf5,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38, 0xbc, 0xf4, 0x03, 0xbb, 0xdf, 0xf3, 0x4f, 0xd7, 0xf0, 0x47, 0x00, 0x00, 0x00, 0xff,
0xff, 0x95, 0x0a, 0xd4, 0x55, 0xe6, 0x04, 0x00, 0x00,
// 653 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x61, 0x6b, 0x13, 0x41,
0x10, 0xf5, 0xee, 0x92, 0xa6, 0x99, 0xc4, 0xd2, 0xae, 0x22, 0x47, 0xd1, 0x36, 0x5c, 0x6b, 0x0d,
0x28, 0x29, 0x24, 0xf8, 0x03, 0x6c, 0x10, 0x53, 0xb0, 0x82, 0xd7, 0xf8, 0xa5, 0x1f, 0x84, 0xed,
0x66, 0x92, 0x2c, 0x4d, 0x76, 0x8f, 0xbd, 0xb9, 0x92, 0xfb, 0xe6, 0x6f, 0x13, 0x7f, 0x98, 0xec,
0xe6, 0x92, 0x3b, 0x6c, 0x15, 0xfc, 0x76, 0xf3, 0xde, 0xe3, 0xed, 0xbc, 0xd9, 0x9b, 0x85, 0x3d,
0x5c, 0xa1, 0xc8, 0x48, 0x9b, 0x5e, 0x62, 0x34, 0x69, 0x56, 0xa7, 0x3c, 0xc1, 0xf4, 0xf0, 0x80,
0x0c, 0x57, 0x29, 0x17, 0x24, 0xb5, 0x5a, 0x33, 0xd1, 0x31, 0x34, 0x3e, 0xa1, 0xc2, 0x54, 0xa6,
0xec, 0x39, 0xd4, 0x65, 0x6a, 0x32, 0x15, 0x7a, 0x1d, 0xaf, 0xbb, 0x1b, 0xaf, 0x8b, 0xe8, 0x87,
0x0f, 0xf0, 0x71, 0x85, 0x62, 0xbc, 0xfa, 0x2c, 0x53, 0x62, 0x2f, 0xa1, 0x99, 0x12, 0x27, 0x1c,
0xf1, 0x74, 0xee, 0x84, 0xed, 0xb8, 0x04, 0xd8, 0x11, 0x40, 0xc2, 0x0d, 0x2a, 0x72, 0x74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 0x91,
0x4c, 0x49, 0x9b, 0x7c, 0x88, 0x86, 0xae, 0x49, 0x1b, 0xb4, 0x8b, 0x61, 0xb4, 0x26, 0x81, 0x86,
0xd2, 0xd0, 0xeb, 0x04, 0x76, 0xdd, 0xb7, 0x00, 0x7b, 0x07, 0x07, 0x52, 0x11, 0x9a, 0x25, 0x4e,
0x24, 0x27, 0x1c, 0x3a, 0x95, 0xef, 0x54, 0x0f, 0x09, 0x76, 0x06, 0x7b, 0x06, 0xef, 0xb5, 0xe0,
0xf6, 0xdf, 0xb5, 0x8f, 0x89, 0xfb, 0x13, 0xdb, 0xf1, 0x1f, 0xa8, 0x3d, 0x53, 0x64, 0x66, 0x84,
0x72, 0x46, 0xf3, 0x62, 0x8f, 0x4b, 0xc0, 0xb2, 0x6a, 0x45, 0xa3, 0xf5, 0x96, 0xd7, 0xd7, 0xec,
0x16, 0xb8, 0x38, 0xbe, 0x79, 0x35, 0x93, 0x34, 0xcf, 0x6e, 0x7b, 0x42, 0x2f, 0xcf, 0x07, 0x03,
0xa1, 0xce, 0xc5, 0x9c, 0x4b, 0x35, 0x18, 0x9c, 0xbb, 0x81, 0xdd, 0xee, 0xb8, 0x67, 0x6f, 0xf0,
0x3b, 0x00, 0x00, 0xff, 0xff, 0xd4, 0xce, 0x6b, 0x62, 0x22, 0x05, 0x00, 0x00,
}
......@@ -28,6 +28,7 @@ message Header {
Signature signature = 8;
}
// 参考Header解释
// mainHash 平行链上使用的字段,代表这个区块的主链hash
message Block {
int64 version = 1;
bytes parentHash = 2;
......@@ -36,6 +37,7 @@ message Block {
int64 height = 5;
int64 blockTime = 6;
uint32 difficulty = 11;
bytes mainHash = 12;
Signature signature = 8;
repeated Transaction txs = 7;
}
......
......@@ -11,6 +11,8 @@ message Genesis {
message ExecTxList {
bytes stateHash = 1;
bytes parentHash = 7;
bytes mainHash = 8;
repeated Transaction txs = 2;
int64 blockTime = 3;
int64 height = 4;
......
......@@ -30,9 +30,11 @@ func CheckBlock(client queue.Client, block *types.BlockDetail) error {
}
//ExecTx : To send lists of txs within a block to exector for execution
func ExecTx(client queue.Client, prevStateRoot []byte, block *types.Block) *types.Receipts {
func ExecTx(client queue.Client, prevStateRoot []byte, block *types.Block) (*types.Receipts, error) {
list := &types.ExecTxList{
StateHash: prevStateRoot,
ParentHash: block.ParentHash,
MainHash: block.MainHash,
Txs: block.Txs,
BlockTime: block.BlockTime,
Height: block.Height,
......@@ -43,14 +45,14 @@ func ExecTx(client queue.Client, prevStateRoot []byte, block *types.Block) *type
client.Send(msg, true)
resp, err := client.Wait(msg)
if err != nil {
panic(err)
return nil, err
}
receipts := resp.GetData().(*types.Receipts)
return receipts
return receipts, nil
}
//ExecKVMemSet : send kv values to memory store and set it in db
func ExecKVMemSet(client queue.Client, prevStateRoot []byte, height int64, kvset []*types.KeyValue, sync bool) []byte {
func ExecKVMemSet(client queue.Client, prevStateRoot []byte, height int64, kvset []*types.KeyValue, sync bool) ([]byte, error) {
set := &types.StoreSet{StateHash: prevStateRoot, KV: kvset, Height: height}
setwithsync := &types.StoreSetWithSync{Storeset: set, Sync: sync}
......@@ -58,10 +60,10 @@ func ExecKVMemSet(client queue.Client, prevStateRoot []byte, height int64, kvset
client.Send(msg, true)
resp, err := client.Wait(msg)
if err != nil {
panic(err)
return nil, err
}
hash := resp.GetData().(*types.ReplyHash)
return hash.GetHash()
return hash.GetHash(), nil
}
//ExecKVSetCommit : commit the data set opetation to db
......
......@@ -102,6 +102,20 @@ targetTimePerBlock = 2
[mver.consensus.ForkChainParamV2]
powLimitBits = "0x1f2fffff"
[consensus.sub.para]
ParaRemoteGrpcClient="localhost:8802"
#主链指定高度的区块开始同步
startHeight=345850
#打包时间间隔,单位秒
writeBlockSeconds=2
#主链每隔几个没有相关交易的区块,平行链上打包空区块
emptyBlockInterval=50
#验证账户,验证节点需要配置自己的账户,并且钱包导入对应种子,非验证节点留空
authAccount=""
#等待平行链共识消息在主链上链并成功的块数,超出会重发共识消息,最小是2
waitBlocks4CommitMsg=2
searchHashMatchedBlockDepth=100
[consensus.sub.solo]
genesis="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
genesisBlockTime=1514533394
......
......@@ -245,7 +245,10 @@ func ExecBlock(client queue.Client, prevStateRoot []byte, block *types.Block, er
block.TxHash = merkle.CalcMerkleRootCache(cacheTxs)
block.Txs = types.CacheToTxs(cacheTxs)
receipts := ExecTx(client, prevStateRoot, block)
receipts, err := ExecTx(client, prevStateRoot, block)
if err != nil {
return nil, nil, err
}
var kvset []*types.KeyValue
var deltxlist = make(map[int]bool)
var rdata []*types.ReceiptData //save to db receipt log
......@@ -285,7 +288,10 @@ func ExecBlock(client queue.Client, prevStateRoot []byte, block *types.Block, er
}
var detail types.BlockDetail
calcHash = ExecKVMemSet(client, prevStateRoot, block.Height, kvset, sync)
calcHash, err = ExecKVMemSet(client, prevStateRoot, block.Height, kvset, sync)
if err != nil {
return nil, nil, err
}
if errReturn && !bytes.Equal(block.StateHash, calcHash) {
ExecKVSetRollback(client, calcHash)
if len(rdata) > 0 {
......
......@@ -139,7 +139,10 @@ func SaveAccountTomavl(client queue.Client, prevStateRoot []byte, accs []*types.
kvs := accountdb.GetKVSet(acc)
kvset = append(kvset, kvs...)
}
hash := util.ExecKVMemSet(client, prevStateRoot, 0, kvset, true)
hash, err := util.ExecKVMemSet(client, prevStateRoot, 0, kvset, true)
if err != nil {
panic(err)
}
Statehash = hash
util.ExecKVSetCommit(client, Statehash)
return hash
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment