Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature support delayed tx #1075

Merged
merged 21 commits into from
Aug 11, 2021
Merged

Conversation

bysomeone
Copy link
Collaborator

@bysomeone bysomeone commented Jul 30, 2021

  1. none合约增加延时存证交易类型

  2. mempool增加延时交易缓存模块

  3. rpc增加发送延时交易接口

fix #1076
fix #1077

@codecov
Copy link

codecov bot commented Jul 30, 2021

Codecov Report

Merging #1075 (046d73d) into master (f188362) will increase coverage by 0.16%.
The diff coverage is 77.69%.

❗ Current head 046d73d differs from pull request most recent head 0810347. Consider uploading reports for the commit 0810347 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1075      +/-   ##
==========================================
+ Coverage   62.85%   63.01%   +0.16%     
==========================================
  Files         157      164       +7     
  Lines       22640    22890     +250     
==========================================
+ Hits        14230    14424     +194     
- Misses       6561     6605      +44     
- Partials     1849     1861      +12     
Impacted Files Coverage Δ
system/dapp/driver.go 58.22% <0.00%> (-0.50%) ⬇️
system/p2p/dht/manage/conns.go 55.17% <0.00%> (-4.00%) ⬇️
system/p2p/dht/protocol/peer/peer.go 75.38% <0.00%> (ø)
system/p2p/dht/protocol/peer/peerinfo.go 41.37% <ø> (-0.19%) ⬇️
system/p2p/dht/p2p.go 51.91% <30.00%> (-3.25%) ⬇️
system/dapp/none/executor/query.go 38.46% <38.46%> (ø)
rpc/jrpchandler.go 66.79% <70.58%> (-0.14%) ⬇️
system/mempool/eventprocess.go 83.16% <71.42%> (-3.09%) ⬇️
client/queueprotocol.go 64.36% <75.00%> (+0.38%) ⬆️
system/dapp/none/executor/exec.go 80.00% <80.00%> (ø)
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f188362...0810347. Read the comment docs.

@bysomeone bysomeone force-pushed the feat-support-delayed-tx branch from 664d919 to 35b6d59 Compare July 30, 2021 09:58
@bysomeone bysomeone changed the title Feat support delayed tx WIP Feat support delayed tx Jul 30, 2021
@bysomeone
Copy link
Collaborator Author

其他模块代码单元测试失败,需要优先解决

@bysomeone bysomeone force-pushed the feat-support-delayed-tx branch from 1f48d22 to 8df4498 Compare August 2, 2021 03:31
@bysomeone bysomeone force-pushed the feat-support-delayed-tx branch from 13d6205 to dbf72d9 Compare August 2, 2021 07:11
@bysomeone bysomeone changed the title WIP Feat support delayed tx Feat support delayed tx Aug 2, 2021
@bysomeone bysomeone changed the title Feat support delayed tx Feature support delayed tx Aug 2, 2021
@@ -1057,3 +1060,39 @@ func (q *QueueProtocol) GetCryptoList() *types.CryptoList {
}
return list
}

// SendDelayTx send delay transaction to mempool
func (q *QueueProtocol) SendDelayTx(param *types.DelayTx, waitReply bool) (*types.Reply, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delay 的交易理论上来说可以直接识别出来,我感觉不需要重新添加接口,直接用原来的接口就可以了。delay的交易和普通交易一样发送就可以

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 延时交易通常由延时存证交易tx发起的,就是tx.paylod=delaytx, 延时存证交易不需要调用这个接口,发送方法和普通交易是一致的,在执行后调用发送延时交易到mempool

  2. 本质上延时交易和普通交易是无差别的,这个接口是提供交易暂存延时打包功能,包括但不限于延时交易,也可以是单纯希望暂缓打包的交易

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改成 mempool 主动过滤后,这个接口还需要吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 这个看普通交易,有没有延缓加入mempool的需求,上次讨论是说南京那边目前还独立做了这个sdk,希望交易等待若干区块后被发送,这里相当于mempool支持这个功能

  2. 延时存证交易本身已经不需要这个接口了

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先保留吧,这个接口。

&types.ReceiptLog{Ty: nty.TyCommitDelayTxLog, Log: types.Encode(delayInfo)})

// send delay tx to mempool
_, err := n.GetAPI().SendDelayTx(&types.DelayTx{Tx: commit.GetDelayTx(), EndDelayTime: delayInfo.EndDelayTime}, false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在执行过程中发送交易,可能会因为 mempool 消息满而整个系统卡住,也会影响性能。建议这个放到blockchain 执行结束向mempool 通知的情况下,可靠性还不是最重要的。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

@@ -156,3 +161,97 @@ func (cache *txCache) getTxByHash(hash string) *types.Transaction {
}
return item.Value
}

//delayTxCache 延时交易缓存
type delayTxCache struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是要考虑大量的delay交易的情况,delay 交易的列表可以考虑存在合约数据库中,用Table保存,以过期时间位索引。mempool 定期去查询,比如10分钟查一次delay的交易,放到cache中。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个可以考虑放到后期处理,有业务后也会关联到一些查询需求,到时统一做设计

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以

@vipwzw vipwzw merged commit b745e3c into 33cn:master Aug 11, 2021
@33cn
Copy link
Owner

33cn commented Oct 15, 2021

🎉 This PR is included in version 1.66.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@33cn 33cn added the released label Oct 15, 2021
@33cn
Copy link
Owner

33cn commented Oct 15, 2021

🎉 This PR is included in version 1.66.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

p2p unit test datarace blockchain ut datarace
4 participants