Commit 5dbec4c6 authored by suyanlong's avatar suyanlong

Add sync step control

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