Commit c44d3754 authored by Litian's avatar Litian Committed by 33cn

只在自动挖矿的地方控制ticket共识挖矿

parent 277ec707
...@@ -7,7 +7,6 @@ package wallet ...@@ -7,7 +7,6 @@ package wallet
import ( import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
...@@ -21,6 +20,7 @@ import ( ...@@ -21,6 +20,7 @@ import (
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
wcom "github.com/33cn/chain33/wallet/common" wcom "github.com/33cn/chain33/wallet/common"
ty "github.com/33cn/plugin/plugin/dapp/ticket/types" ty "github.com/33cn/plugin/plugin/dapp/ticket/types"
"strings"
) )
var ( var (
...@@ -29,14 +29,7 @@ var ( ...@@ -29,14 +29,7 @@ var (
) )
func init() { func init() {
// 只有ticket共识下ticket相关的操作才有效 wcom.RegisterPolicy(ty.TicketX, New())
q := types.Conf("config.consensus")
if q != nil {
cons := q.GStr("name")
if strings.Compare(strings.TrimSpace(cons), ty.TicketX) == 0 {
wcom.RegisterPolicy(ty.TicketX, New())
}
}
} }
// New new instance // New new instance
...@@ -777,6 +770,17 @@ func (policy *ticketPolicy) autoMining() { ...@@ -777,6 +770,17 @@ func (policy *ticketPolicy) autoMining() {
defer bizlog.Info("End auto mining") defer bizlog.Info("End auto mining")
operater := policy.getWalletOperate() operater := policy.getWalletOperate()
defer operater.GetWaitGroup().Done() defer operater.GetWaitGroup().Done()
// 只有ticket共识下ticket相关的操作才有效
q := types.Conf("config.consensus")
if q != nil {
cons := q.GStr("name")
if strings.Compare(strings.TrimSpace(cons), ty.TicketX) != 0 {
bizlog.Info("consensus is not ticket, exit mining")
return
}
}
lastHeight := int64(0) lastHeight := int64(0)
miningTicketTicker := policy.getMingTicketTicker() miningTicketTicker := policy.getMingTicketTicker()
for { for {
......
...@@ -7,14 +7,14 @@ package wallet_test ...@@ -7,14 +7,14 @@ package wallet_test
import ( import (
"testing" "testing"
_ "github.com/33cn/chain33/system"
"github.com/33cn/chain33/util/testnode" "github.com/33cn/chain33/util/testnode"
wcom "github.com/33cn/chain33/wallet/common"
_ "github.com/33cn/plugin/plugin"
ty "github.com/33cn/plugin/plugin/dapp/ticket/types" ty "github.com/33cn/plugin/plugin/dapp/ticket/types"
ticketwallet "github.com/33cn/plugin/plugin/dapp/ticket/wallet" ticketwallet "github.com/33cn/plugin/plugin/dapp/ticket/wallet"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
_ "github.com/33cn/chain33/system"
_ "github.com/33cn/plugin/plugin"
) )
func Test_WalletTicket(t *testing.T) { func Test_WalletTicket(t *testing.T) {
...@@ -22,7 +22,6 @@ func Test_WalletTicket(t *testing.T) { ...@@ -22,7 +22,6 @@ func Test_WalletTicket(t *testing.T) {
cfg, sub := testnode.GetDefaultConfig() cfg, sub := testnode.GetDefaultConfig()
cfg.Consensus.Name = "ticket" cfg.Consensus.Name = "ticket"
wcom.RegisterPolicy(ty.TicketX, ticketwallet.New())
mock33 := testnode.NewWithConfig(cfg, sub, nil) mock33 := testnode.NewWithConfig(cfg, sub, nil)
defer mock33.Close() defer mock33.Close()
err := mock33.WaitHeight(0) err := mock33.WaitHeight(0)
......
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