Commit 60740582 authored by szh's avatar szh

add mutx

parent 1b318cf5
...@@ -10,7 +10,7 @@ Target Server Type : MYSQL ...@@ -10,7 +10,7 @@ Target Server Type : MYSQL
Target Server Version : 50553 Target Server Version : 50553
File Encoding : 65001 File Encoding : 65001
Date: 2019-10-12 10:20:44 Date: 2019-10-12 11:11:49
*/ */
SET FOREIGN_KEY_CHECKS=0; SET FOREIGN_KEY_CHECKS=0;
...@@ -50,6 +50,7 @@ CREATE TABLE `rasp_miner_stat` ( ...@@ -50,6 +50,7 @@ CREATE TABLE `rasp_miner_stat` (
DROP TABLE IF EXISTS `rasp_miner_txs`; DROP TABLE IF EXISTS `rasp_miner_txs`;
CREATE TABLE `rasp_miner_txs` ( CREATE TABLE `rasp_miner_txs` (
`height` bigint(20) NOT NULL DEFAULT '0', `height` bigint(20) NOT NULL DEFAULT '0',
`hash` varchar(64) NOT NULL,
`miner` varchar(64) NOT NULL, `miner` varchar(64) NOT NULL,
`return_addr` varchar(64) DEFAULT NULL, `return_addr` varchar(64) DEFAULT NULL,
`amount` int(10) DEFAULT '0' COMMENT '矿工挖矿获利', `amount` int(10) DEFAULT '0' COMMENT '矿工挖矿获利',
......
...@@ -66,6 +66,7 @@ func SyncBlock() { ...@@ -66,6 +66,7 @@ func SyncBlock() {
txsList := make([]*models.RaspMinerTxs,0) txsList := make([]*models.RaspMinerTxs,0)
checkList := make(map[int64]int64,0) checkList := make(map[int64]int64,0)
var wg sync.WaitGroup var wg sync.WaitGroup
var mutx sync.Mutex
for height := processHeight ;height < processHeight + maxDownload;height ++ { for height := processHeight ;height < processHeight + maxDownload;height ++ {
wg.Add(1) wg.Add(1)
go func(height int64) { go func(height int64) {
...@@ -75,13 +76,14 @@ func SyncBlock() { ...@@ -75,13 +76,14 @@ func SyncBlock() {
logging.Error("DealBlock err",err) logging.Error("DealBlock err",err)
panic(err) panic(err)
} }
mutx.Lock()
statList = append(statList,stat) statList = append(statList,stat)
txsList = append(txsList,txs) txsList = append(txsList,txs)
mutx.Unlock()
logging.Info("DealBlock",height) logging.Info("DealBlock",height)
logging.Info("DealBlock stat",*stat) logging.Info("DealBlock stat",*stat)
logging.Info("DealBlock txs",*txs) logging.Info("DealBlock txs",*txs)
checkList[height] = height checkList[height] = height
time.Sleep(time.Millisecond*10)
}(height) }(height)
} }
//db.SetMainNetHeight(int(processHeight + types.MaxProcessBlocks + 1)) //db.SetMainNetHeight(int(processHeight + types.MaxProcessBlocks + 1))
...@@ -111,7 +113,7 @@ func SyncBlock() { ...@@ -111,7 +113,7 @@ func SyncBlock() {
} }
} }
if len(txsList) != int(maxDownload) || len(txsList) != len(statList) { if len(txsList) != int(maxDownload) || len(txsList) != len(statList) {
logging.Error("txsList",len(txsList),"txsMap",len(txsMap),"statList",len(statList)) logging.Error("txsList",len(txsList),"txsMap",len(txsMap),"statList",len(statList),"checkList",len(checkList))
for _,v:= range checkList { for _,v:= range checkList {
var t, s bool var t, s bool
for _, vv:= range txsList { for _, vv:= range txsList {
...@@ -159,7 +161,6 @@ func SyncBlock() { ...@@ -159,7 +161,6 @@ func SyncBlock() {
} }
func (prev *prevHeight) SetMainHeight() error { func (prev *prevHeight) SetMainHeight() error {
header,err := client.GetLastHeader() header,err := client.GetLastHeader()
......
...@@ -10,6 +10,7 @@ type RaspMinerTxs struct { ...@@ -10,6 +10,7 @@ type RaspMinerTxs struct {
ReturnAddr string `json:"return_addr"` ReturnAddr string `json:"return_addr"`
Amount int64 `json:"amount"` Amount int64 `json:"amount"`
Height int64 `json:"height"` Height int64 `json:"height"`
Hash string `json:"hash"`
Time int64 `json:"time"` Time int64 `json:"time"`
} }
...@@ -56,6 +57,7 @@ func AddMinerTxs(data map[string]interface{}) error { ...@@ -56,6 +57,7 @@ func AddMinerTxs(data map[string]interface{}) error {
ReturnAddr: data["return_addr"].(string), ReturnAddr: data["return_addr"].(string),
Amount: data["amount"].(int64), Amount: data["amount"].(int64),
Height: data["height"].(int64), Height: data["height"].(int64),
Hash:data["hash"].(string),
Time: data["time"].(int64), Time: data["time"].(int64),
} }
if err := db.Create(&tx).Error; err != nil { if err := db.Create(&tx).Error; err != nil {
......
...@@ -39,6 +39,7 @@ type MinedInfo struct { ...@@ -39,6 +39,7 @@ type MinedInfo struct {
type MinedTxInfo struct { type MinedTxInfo struct {
Height int64 `json:"height"` Height int64 `json:"height"`
Hash string `json:"hash"`
Amount int64 `json:"amount"` Amount int64 `json:"amount"`
BlockTime int64 `json:"block_time"` BlockTime int64 `json:"block_time"`
} }
......
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