Commit 5dbec4c6 authored by suyanlong's avatar suyanlong

Add sync step control

parent 6b15b917
......@@ -8,6 +8,7 @@ start_height = 1
height_diff = 0
fee = 100000
is_test = true
step = 10
[log]
level = "debug"
......
......@@ -44,6 +44,7 @@ type Chain33 struct {
StartHeight int64 `mapstructure:"start_height" json:"start_height"` // 起始高度
HeightDiff int64 `mapstructure:"height_diff" json:"height_diff"` // 高度差
Fee int64 `mapstructure:"Fee" json:"Fee"` // 单笔交易的手续费
Step int64 `mapstructure:"step" json:"step"` // 步长
EventFilter string `mapstructure:"event_filter" toml:"event_filter" json:"event_filter"`
TimeoutHeight int64 `mapstructure:"timeout_height" json:"timeout_height"`
IsTest bool `mapstructure:"is_test" json:"is_test"`
......
......@@ -45,17 +45,19 @@ var (
)
type Evmxgo struct {
eventC chan *pb.IBTP // 发送给sidecar
chainID int32
fromID string
toID string
ticker *time.Ticker
done chan bool
client *rpc.Client
pk string // 签名,仅仅是和当前链挂钩的私钥。
height *atomic.Int64 // 已经解析的高度。1、初始化时设置; 2、服务每次重启后设置
db *util.KVDBList // 记录已完成的hashID、高度等信息。
fee int64
eventC chan *pb.IBTP // 发送给sidecar
chainID int32
fromID string
toID string
ticker *time.Ticker
done chan bool
client *rpc.Client
pk string // 签名,仅仅是和当前链挂钩的私钥。
height *atomic.Int64 // 已经解析的高度。1、初始化时设置; 2、服务每次重启后设置
db *util.KVDBList // 记录已完成的hashID、高度等信息。
fee int64
step int64
heightDiff int64 // 高度差
logger hclog.InterceptLogger
}
......@@ -171,6 +173,11 @@ func (e *Evmxgo) Initialize(configPath string, _ string, _ []byte) error {
}
e.logger.Info("startHeight ", "startHeight", startHeight)
e.logger.Info("latest height", "height", e.height.Load())
e.heightDiff = chain33Config.Chain33.HeightDiff
e.step = chain33Config.Chain33.Step
if e.step == 0 {
e.step = 10
}
// 启动定时器,检查是否有遗漏的数据。
// 检验已经完成的数据。
......@@ -208,16 +215,20 @@ func (e *Evmxgo) pollAppChain() chan *types.Event {
header, err := e.client.QueryLastHeader()
if err != nil {
e.logger.Error("call QueryLastHeader ", "error", err)
time.Sleep(2 * time.Second)
// time.Sleep(2 * time.Second)
} else {
e.logger.Info("GetLastHeader", "height", header.Height)
lastHeight := header.Height
height := e.height.Load()
if lastHeight <= height {
if lastHeight-e.heightDiff <= height {
time.Sleep(2 * time.Second)
} else {
height1 := height + 1
blockInfo, err := e.client.QueryBlockInfo(height1, height1, true)
start := height + 1
end := height + 1
if start+e.step <= lastHeight {
end = start + e.step
}
blockInfo, err := e.client.QueryBlockInfo(start, end, true)
if err != nil {
e.logger.Error("call QueryBlockInfo", "error", err)
} else {
......
......@@ -11,6 +11,7 @@ height_diff = 0
fee = 100000
#被监听链ID
chain_id = 0
step = 10
[log]
#日志级别
......
......@@ -68,6 +68,7 @@ type Paracross struct {
// 分类块中的交易为:已完成、未完成的交易。
notify chan int64 // 高度完成提醒
heightDiff int64 // 高度差
step int64
isTest bool
logger hclog.InterceptLogger
......@@ -209,6 +210,10 @@ func (p *Paracross) Initialize(configPath string, ID string, extra []byte) error
p.logger.Info("latest height", "height", p.height.Load())
p.chEvent = make(chan *types.Event, 1)
p.step = chain33Config.Chain33.Step
if p.step == 0 {
p.step = 10
}
// 启动定时器,检查是否有遗漏的数据。
......@@ -234,7 +239,7 @@ func (p *Paracross) pollAppchain() {
header, err := p.grpcClient.GetLastHeader(p.ctx, &types33.ReqNil{})
if err != nil {
p.logger.Error("GetLastHeader call error", "error", err)
time.Sleep(2 * time.Second)
// time.Sleep(2 * time.Second)
} else {
p.logger.Info("GetLastHeader", "height", header.Height)
lastHeight := header.Height
......@@ -242,7 +247,12 @@ func (p *Paracross) pollAppchain() {
if lastHeight-p.heightDiff <= height {
time.Sleep(2 * time.Second)
} else {
p.processBlock(height+1, height+1)
start := height + 1
end := height + 1
if start+p.step <= lastHeight {
end = start + p.step
}
p.processBlock(start, end)
}
}
}
......
......@@ -13,6 +13,7 @@ height_diff = 6
fee = 100000
#被监听链ID
chain_id = 0
step = 10
[log]
#日志级别
......
......@@ -4,6 +4,8 @@ import (
"fmt"
"testing"
"github.com/33cn/chain33/common"
"github.com/stretchr/testify/assert"
)
......@@ -19,3 +21,8 @@ func TestMock(t *testing.T) {
fmt.Println(ibtp)
}
}
func TestHash(t *testing.T) {
paraBlockHash := common.Sha256([]byte("111064"))
t.Log(common.HashHex(paraBlockHash))
}
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