Coder Social home page Coder Social logo

wecross's Introduction

CodeFactor Build Status Latest release License Language

WeCross简介

WeCross是由微众银行自主研发并完全开源的区块链跨链协作平台,致力于促进跨行业、机构和地域的跨区块链信任传递和商业合作。WeCross支持应用与多链互操作、同/异构链间互操作等多维跨链交互,实现了:

  • 一站式跨链管理

    WeCross为方便开发、维护和管理跨链应用,配套多种跨链工具,包括命令行终端控制台可视化网页管理平台

  • 插件式跨链接入

    WeCross只需基于Stub接口针对不同的链开发适配器,就能以插件化的方式实现跨链接入。目前适配的区块链包括FISCO BCOS 3.0FISCO BCOS 2.0Hyperledger Fabric 1.4Hyperledger Fabric 2

  • 统一跨链身份

    WeCross基于跨链账户服务管理账户的生命周期。每个跨链账户对应多个链账户,实现跨链身份的统一。

  • 统一资源范式

    WeCross对各个链的资源包括合约、交易以及区块等进行抽象和封装,并基于通用跨链接口和统一的寻址方式实现对不同资源的访问和调用。

  • 跨链事务保障

    WeCross基于两阶段提交实现多链的事务写操作。回滚时,事务中的操作都会被重置,最终恢复到事务前的状态。

  • 资产原子交换

    WeCross基于哈希时间锁合约实现异构链间资产原子交换,无需更改原链上的资产模型和资产合约,通用性较强。

  • 合约跨链调用

    WeCross不仅支持跨链应用对异构多链发起调用,而且还支持由合约发起的对其它链合约的异步跨链调用

了解更多技术特性,请下载阅读WeCross白皮书

WeCross架构

快速开始

阅读快速入门,从连通两个区块链开始,快速体验WeCross的强大功能。

技术文档

阅读WeCross 在线文档,详细了解如何使用WeCross。

项目贡献

欢迎参与WeCross社区的维护和建设:

您将成为贡献者,感谢各位贡献者的付出:

https://github.com/WeBankBlockchain/WeCross/graphs/contributors

开源社区

参与meetup:活动日历

学习知识、讨论方案、开发新特性:联系微信小助手,加入跨链兴趣小组(CC-SIG)

License

WeCross的开源协议为Apache License 2.0,详情参考LICENSE

wecross's People

Contributors

767472021 avatar birdmanfly163 avatar ccznb avatar chendongcse avatar chenjiawei514 avatar hanlinbo123 avatar haoxuan40404 avatar heixiongtt avatar helloaldis avatar hqwangningbo avatar jimmyshi22 avatar jsrzx avatar jyfangyang avatar kyonray avatar morebtcg avatar qwdarrenyin avatar robinlg avatar shareong avatar yangzan0816 avatar yinghuochongfly avatar ywy2090 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wecross's Issues

sendTransaction payment.fabric.sacc fabric_user1 set a 66 ->http request timeout

执行:sendTransaction payment.fabric.sacc fabric_user1 set a 66
日志:
WeCrossRPCService() - request: Request{version='1', path='payment.fabric.sacc', method='sendTransaction', accountName='fabric_user1', data=TransactionRequest{method='set', args=[a, 666], options={}}}; url: https://192.168.1.39:8250/payment/fabric/sacc/sendTransaction
这里不知咋就成https的请求了 我配置的内网主机ip
fabric在另外一个主机上部署
直接命令行执行 query和invoke都正常

Task: 优化跨链路由启动过程

背景

跨链路由启动时需要为各个链部署系统合约,包括代理合约(WeCrossProxy)和桥接合约(WeCrossHub),用户会根据提示分别完成部署,如果有n条链m个系统合约,那么用户需要执行n*m次部署命令,不太友好。

一种优化方式是:通过脚本将每条链的系统合约操作命令合并。

bash systemResources.sh -dPH -c chains/my_bcos -t BCOS2.0
bash systemResources.sh -uPH -c chains/my_bcos_gm -t GM_BCOS2.0
bash systemResources.sh -aH -c chains/my_fabric -t Fabric1.4

命令解析:

  • d: deploy,部署合约
  • u: upgrade,升级合约
  • a: getAddress,获取合约地址
  • P: WeCrossProxy
  • H: WeCrossHub
  • c: chainName,链配置路径
  • t: 链类型

任务

实现systemResources.sh脚本。

附录

不同链的系统合约操作命令如下:

  • FISCO BCOS 非国密链
# 代理合约
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.bcos.normal.preparation.ProxyContractDeployment deploy [chainName]
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.bcos.normal.preparation.ProxyContractDeployment upgrade [chainName]

# 桥接合约
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.bcos. normal.preparation.HubContractDeployment deploy [chainName]
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.bcos. normal.preparation.HubContractDeployment upgrade [chainName]
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.bcos. normal.preparation.HubContractDeployment getAddress [chainName]
  • FISCO BCOS 国密链
# 代理合约
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.bcos. guomi.preparation.ProxyContractDeployment deploy [chainName]
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.bcos. guomi.preparation.ProxyContractDeployment upgrade [chainName]

# 桥接合约
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.bcos.guomi.preparation.HubContractDeployment deploy [chainName]
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.bcos.guomi.preparation.HubContractDeployment upgrade [chainName]
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.bcos.guomi.preparation.HubContractDeployment getAddress [chainName]
  • Hyperledger Fabric 链
# 代理合约
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.fabric.proxy.ProxyChaincodeDeployment deploy [chainName]
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.fabric.proxy.ProxyChaincodeDeploymentt upgrade [chainName]

# 桥接合约
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.fabric.hub.HubChaincodeDeployment deploy [chainName]
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.fabric.hub.HubChaincodeDeployment upgrade [chainName]

跨链事务问题咨询

BUG描述
简要描述 BUG 的表现,造成的影响。
执行 :

newHTLCTransferProposal payment.bcos.htlc bcos 5405166a2bfc5d1eddf25625b4e8595f40d446243966f1d5786bab272bb12958 ec775276eb6df852988a94cedbd6f8275fdd093ce7d134e1c1aa2bede7f4e0f7 true 0x55f934bcbe1e9aef8337f5551142a442fdde781c 0x2b5ad5c4795c026514f8317c7a215e218dccd6cf 700 1593485531 [email protected] [email protected] 500 1593485231

响应:
Response{
version='1',
errorCode=52000,
message='Account is null',
data=null
}

问题1:
上述问题是否为接受者地址不存在造成?该地址该如何生成?

问题2:
事务案例中的部署流程缺少用户配置相关细节描述, 接入是借鉴手动组网中的方式嫁接过来操作的是否会存在问题?

Task: 重命名VerifyData

VerifyData功能非常简单,保存待验证的数据,并提供一个接口与期望的数据进行对比。目前的类名似乎不太规范,帮忙贡献一个更好的名字吧。

bulid demo error: WeCross-Account-Manager start failed

Hi, there.
I am a new user for wecross. When I built the demo build_cross_all.sh, it returns the below error:

WeCross-Account-Manager start failed
See logs/error.log for details
Error log
2020-12-24 16:17:45.030 [main] ERROR SqlExceptionHelper() - Communications link failure
.....................................
Initializing TomcatServletWebServerFactory: Service{address='0.0.0.0', port=8340, sslKey='classpath:ssl.key', sslCert='classpath:ssl.crt', caCert='classpath:ca.crt', sslOn=true}
Hibernate: drop table if exists hibernate_sequence
ERROR: Database connection exception, please check!

Any requirement I need for fixing the error?

macOS下使用demo/build.sh搭建Demo失败

BUG描述
macOS下快速搭建Demo失败,错误发生在demo/build.sh脚本32行。

config_bcos_stub_toml函数中130行,调用sed_i函数,发生如下错误:

sed: can't read 16,20d: No such file or directory

sed_i改成sed -i即可。

性能问题咨询

在白皮书上没有看到相关性能的描述,想咨询一下wecross在性能方面的表现目前是否有数据支撑

下载编译失败

按照文档,下载代码并执行编译,结果失败。

Task :test

com.webank.wecross.test.network.NetworkManagerTest > addAndRemoveConcurrentTest STANDARD_OUT
2019-12-06 10:46:15.523 [Thread-7] INFO NetworkManagerTest(:) - Remove resource
... ...
com.webank.wecross.test.peer.PeerResourcesTest > noMyselfTest STANDARD_OUT
2019-12-06 10:46:15.734 [Test worker] ERROR PeerResources(:) - Myself resources has not been set.
2019-12-06 10:46:15.734 [Test worker] ERROR PeerResources(:) - Myself resources has not been set.
... ...
2019-12-06 10:46:21.192 [Test worker] ERROR ResourceLeakDetector(:) - LEAK: HashedWheelTimer.release() was not called before it's garbage-collected. See http://netty.io/wiki/reference-counted-objects.html for more information.
Recent access records:
Created at:
io.netty.util.HashedWheelTimer.(HashedWheelTimer.java:284)
io.netty.util.HashedWheelTimer.(HashedWheelTimer.java:217)
io.netty.util.HashedWheelTimer.(HashedWheelTimer.java:196)
io.netty.util.HashedWheelTimer.(HashedWheelTimer.java:178)
io.netty.util.HashedWheelTimer.(HashedWheelTimer.java:162)
io.netty.util.HashedWheelTimer.(HashedWheelTimer.java:121)
com.webank.wecross.p2p.netty.P2PService.(P2PService.java:33)
com.webank.wecross.test.Mock.MockP2PService.(MockP2PService.java:8)
com.webank.wecross.test.peer.PeerManagerTest.newMockPeerManager(PeerManagerTest.java:102)
com.webank.wecross.test.peer.PeerManagerTest.syncByRequestPeerInfo(PeerManagerTest.java:128)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
....
2019-12-06 10:46:21.254 [Test worker] ERROR WeCrossHost(:) - Startup host error: {}
java.lang.NullPointerException: null
at java.util.regex.Matcher.getTextLength(Matcher.java:1283) ~[?:1.8.0_221]
at java.util.regex.Matcher.reset(Matcher.java:309) ~[?:1.8.0_221]
at java.util.regex.Matcher.(Matcher.java:229) ~[?:1.8.0_221]
at java.util.regex.Pattern.matcher(Pattern.java:1093) ~[?:1.8.0_221]
at com.webank.wecross.p2p.netty.common.Utils.validIP(Utils.java:33) ~[main/:?]
at com.webank.wecross.p2p.config.P2PConfig.validConfig(P2PConfig.java:140) ~[main/:?]
at com.webank.wecross.p2p.netty.Initializer.start(Initializer.java:152) ~[main/:?]
at com.webank.wecross.p2p.netty.P2PService.start(P2PService.java:93) ~[main/:?]
at com.webank.wecross.host.WeCrossHost.start(WeCrossHost.java:26) ~[main/:?]
... ...

  > Task :test FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':test'.

Process 'Gradle Test Executor 1' finished with non-zero exit value 255
This problem might be caused by incorrect test process configuration.
Please refer to the test execution section in the User Manual at https://docs.gradle.org/5.2.1/userguide/java_testing.html#sec:test_execution

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 4m 9s

Task: 完善文档资料

如果你在了解、体验或使用WeCross时发现相关文献资料如技术文档白皮书、项目Readme有错误、不详、不妥等待改进的地方,欢迎提PR,社区由衷感谢你的贡献。

跨链转账结果确认出现问题

BUG描述
按照文档进行htlc跨链转账操作:在进行转账结果确认时发现,bcos_user1(发起者)账户余额确实发生了变化(减少700),但是bcos_user2(bcos链上的转账接受者)账户余额仍是0;查询fabric_user1(fabric链上的转账接受者)账户余额增加500,但是fabric_admin的账户余额却未发生变化。很是费解,希望我描述的算清楚,附上截图
截屏2020-11-16 下午9 26 14
截屏2020-11-16 下午9 36 32

重现方式

预期结果
详细描述上述操作的预期结果。

截图
如果可行,放上截图便于更具体地描述BUG。

环境

  • 操作系统: [例如 Ubuntu、CentOS、MACOS]
  • 运行库 [例如 libc, java ]
  • 版本 [操作系统和运行库的版本]

更多信息
关于该 BUG 的更多信息

CIP-001: WeCross improvement proposals discussion

WeCross improvement proposals

跨链是区块链行业的前沿课题,业界对跨链的定义和设计都有很多不同的理解。跨链的场景、跨链的网络架构、跨链的交互逻辑,都有大量的研究和讨论。基于这个现状,WeCross团队不局限于自己探索和解决所有跨链的问题,而是将已知或可能存在的场景和需求,以CIP(WeCross Improvement Proposals)的形式提出解决方案,邀请广大区块链从业者和用户共同参与方案的规划,一起讨论和完善方案的设计,由WeCross团队采纳,最终合作完成WeCross功能的实现。

浏览CIP:https://github.com/WeBankFinTech/WeCross/labels/CIP

CIP构成

CIP的描述应该简洁精炼,围绕着目标进行,包含以下要素:

  • 功能简介:简述该CIP提出的背景、预期要解决的问题和使用的场景,发起CIP提案时,该章节为必填
  • 模块架构:CIP涉及哪些全新模块和已有模块的修改、各模块之间的联系、逻辑架构图,如果该CIP提案涉及网络、互联逻辑还应提供系统架构图和网络架构图
  • 功能列表:总体的功能列表,各模块的功能列表
  • 接口设计:各模块功能接口的名称、入参、出参和逻辑概要描述
  • 协议设计:如果该CIP提案涉及网络、互联逻辑,提供网络通信协议的流程和字段设计
  • 数据结构:如果该CIP提案涉及数据落盘存储,提供数据存储的数据结构设计
  • 时序图:主要模块功能的流程时序图
  • 兼容性:与旧版本WeCross、已搭建的WeCross跨链网络的兼容性分析
  • 安全分析:跨链数据、账户、资产和通信的安全性分析

CIP工作流

CIP遵循一套预设的工作流,所有CIP的进展会公示在Issue中,有独特的标签,CIP工作流包含以下阶段:

  1. 提案阶段(Proposal):发起人按照CIP模板,填写CIP的功能简介,提交Issue,由WeCross核心开发者审核
  2. 方案阶段(Draft):WeCross核心开发者认可该CIP提案后,为Issue赋予明确的标签。发起人需要在14天内将CIP提案模板中的所有章节补全,期间,发起人可以与核心开发者进行多轮共同沟通,共同完善方案
  3. 投票阶段(Vote):CIP的所有章节完成以后,WeCross团队审阅CIP方案,并发起讨论和投票,决定是否采纳该CIP
  4. 采纳阶段(Accepted):WeCross团队将此CIP纳入版本规划,发起者可以一起参与开发
  5. 结束(Final):CIP功能随WeCross版本发布后,将该CIP标识为结束状态
  6. 拒绝(Reject):CIP功能未通过投票或被放弃,该CIP标识为拒绝状态

一个正常采纳的CIP工作流为:提案 -> 方案 -> 投票 -> 采纳 -> 结束
一个被拒绝的CIP工作流为:提案 -> 方案 -> 投票 -> 拒绝

CIP激励

对于热心提交CIP、评论CIP并最终被采纳的用户,WeCross团队根据行为的不同,给予相应激励:

  • 提交CIP并被采纳:
  • 评论CIP并被采纳:

参考资料:EIP方案

EIP全称Ethereum Improvement Proposals,是以太坊标准的提案格式。

EIP1介绍了EIP的标准格式和分类(https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1.md)

EIP包含多种类型,包括:

  • Core:核心提案,指对以太坊的核心功能,如EVM等模块的提案,例如EIP5,提出了对CALL和RETURN的gas计算方案。(https://github.com/ethereum/EIPs/blob/master/EIPS/eip-5.md)
  • Networking:网络提案,涉及P2P模块、网络协议和轻客户端协议等,例如EIP8提出了基本的RLP编解码协议、包头协议和握手协议等等。(https://github.com/ethereum/EIPs/blob/master/EIPS/eip-8.md)
  • Interface:接口提案,与API、RPC和ABI相关,如EIP6提出了将SUICIDE的语法改名为SELFDESTRUCT,还有ABI编解码协议。
  • ERC:应用层面的提案,如智能合约、命名协议、dapp目录结构规范等,如知名的ERC20(ethereum/EIPs#2 )合约。

其它的诸如Meta EIP和Informational EIP则是相对没那么正式的EIP,用于一些讨论、建议等场景。

遵循EIP1的描述,一个正式的EIP包含以下内容:

  • Preamble:RFC 822风格的内容概要,包括EIP编号、作者等信息
  • Abstract:200字以内的EIP内容概要
  • Specification:规格描述
  • Backwards Compatibility:前向兼容性,该EIP与旧版本的兼容性
  • Test Cases:测试用例
  • Implementations:实现的详细描述,可以用代码描述
  • Security Considerations:安全因素,包括账户安全、密码学安全等一些跟安全相关的考量
  • Copyright Waiver:版权相关

EIP遵循如下流程和步骤:

  1. Idea:简单描述EIP的想法,并提交一个草案PR到EIP项目
  2. Draft:PR被合入以后,在期限内继续完善EIP的内容,期限通常是14天(可协商)
  3. Last Call:期限到达前,EIP会在项目网页上展示,如果设计理念改变、或是有无法解决的争议,EIP会回到Draft状态,否则进入下一个状态(https://eips.ethereum.org/)
  4. Accepted:EIP被接受,开始规划开发、是否要硬分叉等事项
  5. Final:EIP实现后,该EIP转为Final状态

截至目前(2020-05-14),以太坊的所有EIP中,55个EIP是已实现(Final)状态,184个EIP是草案(Draft)状态,5个EIP是展示(Last Call)状态,1个EIP是接受(Accepted)状态,正在开发。从作者来看,大部分已实现(Final)状态的EIP,都是由以太坊的核心成员如Vitalik Buterin、Christian Reitwiessner、Alex Beregszaszi等人提出,草案(Draft)状态的EIP,来源比较多样。

Task: 为WeCross demo添加Dockerfile

WeCross Demo是一个供用户快速体验的集成环境。Demo搭建了一个WeCross跨链网络,连接FISCO BCOS和Hyperledger Fabric区块链。用户可通过WeCross控制台,对不同的链上资源进行操作。

为了让用户更加方便快捷地部署Demo,可将其封装成一个Docker镜像,欢迎贡献Dockerfile!

Task: Make java sdk more lighter

目前Java SDK主要的功能是实现RPC服务的访问,提供了同步和异步的调用接口。同步接口使用Apache的Httpclient作为客户端,并使用RestTemplate封装Http请求;异步接口则是基于Netty实现的,性能较高。

显而易见,目前SDK的依赖非常重,包括Appach Httpcomponents和Spring Boot。既然异步接口已经有了,那么用其它的方式实现一套同步接口必要性不大,直接对异步接口再封装转成同步就可以了。

这个任务比较有挑战,不过极客的你定能漂亮地完成!

Task: macos 默认没有md5sum

BUG描述
macos 默认没有md5sum

重现方式
重现 BUG 的操作步骤。
例如:

  1. 下载 '...'
  2. 执行脚本 '....'
  3. 输入控制台命令 '....'
  4. 查询余额 '....'

预期结果
详细描述上述操作的预期结果。

截图
image

环境

  • 操作系统: [例如 Ubuntu、CentOS、MACOS]
  • 运行库 [例如 libc, java ]
  • 版本 [操作系统和运行库的版本]

更多信息
关于该 BUG 的更多信息

问题:WeCrossProxy chaincode容器的关系是什么

57U84M295Z 3I@10M_J9MET

我尝试关闭sacc容器 在wecross-console调用链码时 容器会重新启动 我猜测他们是有关系的。

想问下 生成的这4个容器 有什么关系 ? 我依然可以像Fabric去调用sacc 但是我并不太了解WeCrossProxy是怎么工作的。

刚接触wecross希望能够解答 谢谢

Task: 合约跨链调用优化

WeCross支持合约发起跨链调用,原理及用法参见技术文档

背景:目前跨链调用调度器InterchainScheduler在处理跨链请求时,一定会进行回调操作。因此,在合约里发起跨链调用时必须要有回调。

任务:InterchainScheduler新增回调资源路径的判断,如果为空,则不进行回调,而是将目标链的调用结果注册到桥接合约。

Task: 为跨链接口取个更合适的名字

目前,WeCross调用合约分为callsendTransaction两个接口,一个用于查询,一个用于发交易。

对于区块链内部,一个交易(Transacion)就是一个事务(Transacion)。但是对于跨链,事务特指多链多笔交易的一致性,所以事务和交易就得区分开来,显然跨链场景下sendTransaction就有歧义了。

快帮忙想个更好的名字吧,在issue区留意即可。

Task: 优化代码格式化工具

WeCross项目使用google-java-format作为代码格式化工具,不过当函数过长时,就出现了如下的尴尬局面,请修复:

                                                        if (logger
                                                                                                    .isDebugEnabled()) {
                                                                                                logger
                                                                                                        .debug(
                                                                                                                " hash: {}, response: {}",
                                                                                                                receipt
                                                                                                                        .getTransactionHash(),
                                                                                                                transactionResponse);
                                                                                            }
                                                                                        } catch (
                                                                                                BCOSStubException
                                                                                                        e) {
                                                                                            logger
                                                                                                    .warn(
                                                                                                            " e: ",
                                                                                                            e);
                                                                                            callback
                                                                                                    .onTransactionResponse(
                                                                                                            new TransactionException(
                                                                                                                    e
                                                                                                                            .getErrorCode(),
                                                                                                                    e
                                                                                                                            .getMessage()),
                                                                                                            null);
                                                                                        }

项目列表:

有大佬嘛

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Download '...'
  2. Run script '....'
  3. Enter command '....'
  4. Query information '....'

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. Ubuntu, CentOS, MACOS]
  • Runtime: [e.g. libc, java]
  • Version [e.g. openjdk 1.8]

Additional context
Add any other context about the problem here.

Task: 补充单元测试

想了解WeCross源码!那么补充单元测试绝对是最便捷最高效的方式之一。以类为单位,了解各个小功能的代码执行流程,理清模块之间的依赖关系,点滴之间,凝汇拳拳劲流。

Task: 给stub增加一个RequestFactory

Driver接口的实例化类如BCOSDriver中有一个私有的requestBuilder方法,用来构造请求,这个方法比较通用,可以移到Stub包中,通过工厂类构造,工厂类如下:

    public class RequestFactory {
        public static Request requestBuilder(int type, String content) {
            return requestBuilder(type, content.getBytes(StandardCharsets.UTF_8));
        }

        public static Request requestBuilder(int type, byte[] content) {
            Request request = new Request();
            request.setType(type);
            request.setData(content);
            return request;
        }
    }

为什么运行demo时出现WeCrossProxy has not been deployed to: [Org1, Org2]的错误?

Describe the bug
错误如下
WeCross start failed
See logs/error.log for details
Error log
2020-09-21 23:38:17.348 [main] ERROR FabricStubFactory() - newConnection exception: java.lang.Exception: WeCrossProxy has not been deployed to all org
2020-09-21 23:38:17.349 [main] ERROR ZonesConfig() - Init localConnection: classpath:chains/fabric-Fabric1.4 failed
2020-09-21 23:38:17.349 [main] ERROR ZonesConfig() - Init localConnection failed
Start log

. ____ _ __ _ _
/\ / ' __ _ () __ __ _ \ \ \
( ( )_
_ | '_ | '| | ' / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) )
' |
| .__|| ||| |_, | / / / /
=========|
|==============|/=////
:: Spring Boot :: (v2.1.13.RELEASE)

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/demo/demo/routers-payment/127.0.0.1-8251-25501/lib/log4j-slf4j-impl-2.11.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/demo/demo/routers-payment/127.0.0.1-8251-25501/plugin/bcos2-stub-1.0.0-rc4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/demo/demo/routers-payment/127.0.0.1-8251-25501/plugin/bcos2-stub-gm-1.0.0-rc4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Load classpath:wecross.toml ...
Initializing StubManager...
Initializing ZoneMap ...
WeCrossProxy has not been deployed to: [Org1, Org2]
Usage:
java -cp 'conf/:lib/:plugin/' com.webank.wecross.stub.fabric.proxy.ProxyChaincodeDeployment check [chainName]
java -cp 'conf/:lib/:plugin/' com.webank.wecross.stub.fabric.proxy.ProxyChaincodeDeployment deploy [chainName]
java -cp 'conf/:lib/:plugin/' com.webank.wecross.stub.fabric.proxy.ProxyChaincodeDeployment upgrade [chainName]
Example:
java -cp 'conf/:lib/:plugin/' com.webank.wecross.stub.fabric.proxy.ProxyChaincodeDeployment check chains/fabric
java -cp 'conf/:lib/:plugin/' com.webank.wecross.stub.fabric.proxy.ProxyChaincodeDeployment deploy chains/fabric
java -cp 'conf/:lib/:plugin/' com.webank.wecross.stub.fabric.proxy.ProxyChaincodeDeployment upgrade chains/fabric

[ERROR] BCOS-RPC port 8545 is not avaliable. Are there any other blockchain is running?

BUG描述
[ERROR] BCOS-RPC port 8545 is not avaliable. Are there any other blockchain is running?

重现方式

  1. 停止本地运行的FISCO BCOS,cd fisco/nodes/127.0.0.1 bash stop_all.sh
  2. 查看端口,netstat -lntpu,已经没有8545

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 466/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 587/sshd
tcp6 0 0 :::7946 :::* LISTEN 586/dockerd
udp 0 0 127.0.0.53:53 0.0.0.0:* 466/systemd-resolve
udp 0 0 172.26.86.56:68 0.0.0.0:* 24251/systemd-netwo
udp 0 0 127.0.0.1:323 0.0.0.0:* 599/chronyd
udp 0 0 0.0.0.0:4789 0.0.0.0:* -
udp6 0 0 ::1:323 :::* 599/chronyd
udp6 0 0 :::7946 :::* 586/dockerd

  1. 运行wecross安装脚本,bash clear.sh bash build.sh
  2. 报错:[ERROR] BCOS-RPC port 8545 is not avaliable. Are there any other blockchain is running?

环境

  • 操作系统: Ubuntu 18.04

CIP-002: Two-phase commit protocol

两阶段事务

功能简介

两阶段事务是一种原子性的分布式事务算法,在数据库和分布式系统等领域的应用非常广泛,两阶段事务用于应对分布式系统可能遇到的网络故障、宕机、程序异常和断电等故障。区块链跨链网络中,多个相互联通的区块链构成了一个更大规模的分布式系统,这意味着有更多的网络连接和更多故障的可能性,因此两阶段事务对于跨链同样具有很大的意义。

模块架构

与传统分布式系统的两阶段事务一样,用于跨链的两阶段事务的逻辑架构中一样有事务管理器(Transaction Manager)和资源管理器(Resource Manager)两种角色,其中,事务管理器以事务为维度管理事务的进度和状态,资源管理器以资源为维度管理参与事务资源的状态。

图片

WeCross中,事务管理器和资源管理器均由智能合约或链码(Fabric,后统称为智能合约)来实现,物理架构根据是否有治理链,分两种情况:

无治理链的架构

图片

有治理链的架构

图片

功能列表

分析一个标准的两阶段事务,分成功和失败两种场景。

成功场景:

图片

失败场景:

图片

可见,两阶段事务包含以下核心功能:

  • 事务管理:查看当前所有事务的状态,筛选进行中、成功或失败的事务
  • 事务发起:指定参与事务的资源,并发起一次事务操作,返回事务ID
  • 事务提交:根据事务ID,结束某个事务,并解除该事务中所有资源的锁定
  • 事务回滚:根据事务ID,结束某个事务,并撤销该事务中所有资源的变更
  • 资源隔离:隔离同时参与到两个事务的资源

接口设计

两阶段事务,包含事务代理合约和可选的事务列表合约。

事务代理合约接口:

接口 参数 返回值 说明
开始事务 事务ID, 合约地址列表 是否已经成功开始事务 开始事务,锁定相关合约非本事务的写操作和事务操作
提交事务 事务ID 是否已经成功及提交事务 提交事务,解除相关合约写操作与事务操作的锁定
回滚事务 事务ID 是否已经成功回滚事务 回滚事务,解除相关合约写操作与事务操作的锁定
调用 事务ID, 步骤编号, 合约地址, 合约函数ABI, 参数encoded 调用结果, 调用结果encoded 执行调用,受隔离级别影响
发送交易 事务ID, 步骤编号, 合约地址, 合约函数ABI, 参数encoded 交易执行结果, 交易执行结果encoded 执行交易,受事务状态影响
获取事务交易历史 事务ID 交易历史数组(包括步骤编号、合约地址、合约函数ABI、参数encoded) 获取某个事务ID所有的操作历史

事务代理合约Solidity接口代码

pragma solidity >=0.4.22 <0.7.0;

contract TransactionAgent {
    
    function begin(string transactionID, address[] resources) returns(int) public;
    
    function commit(string transactionID) returns(int) public;
    
    function rollback(string transactionID) returns(int) public;
    
    function call(string transactionID, int step, address resourceAddress, string functionABI, byte[] functionArguments) returns (int, byte[] functionReturns) public;
    
    function sendTransaction(string transactionID, int step, address resourceAddress, string functionABI, byte[] functionArguments) returns (int, byte[] functionReturns) public;
    
    function getTransactionHistory(string transactionID) returns (int[], address[], string[], byte[][]) public;
}

数据结构

事务执行的过程中,事务代理合约会将事务的步骤和结果保存到数据表中,表结构如下:

字段 数据类型 例子 描述
事务ID 数值 1 事务ID,作为主键,包含多个Entry
操作者 字符串 c1228ce3dc5f7f71351246429802573d 操作者的账号
操作类型 枚举 Begin、End、Transaction、Rollback 步骤的操作类型,是正常的交易还是回滚,包括Begin和End两种特殊类型
资源路径 字符串 zone.chain.resource 步骤操作的资源路径
交易函数 字符串 "prepare" 步骤的操作函数
交易参数 字符串 "arg1","arg2","arg3" 步骤的操作参数
交易状态 枚举 'Start'、'Success'、'Failed' 步骤的操作状态,Start标识已记录准备开始,Success标识成功,Failed标识已失败
时间戳 时间 2020-05-06 16:00:00 步骤的时间戳

时序图

一个正常的两阶段事务流程由WeCross Router发起,由Router结束,流程如下:

图片

其中,事务列表合约仅在有管理链时使用,无管理链时,事务列表合约的时序可以省略。

如果事务执行到中途发生了任何异常,用户可以自行判断是否要取消事务,调用事务代理合约的rollback接口回滚事务。如果用户的系统发生了异常,无法调用rollback接口,WeCross Router会在一定时间后,自动调用rollback回滚事务。

上述的事务流程会在数表中存入以下数据:

事务ID 操作者 操作类型 资源路径 交易函数 交易参数 交易状态 时间戳
0 A Begin zone.chain.resources1, zone.chain.resources2 Start 2020-05-06 15:00:00
0 A Transaction zone.chain.resources1 begin 0 Start 2020-05-06 15:00:00
0 A Transaction zone.chain.resources1 begin 0 Success 2020-05-06 15:00:00
0 A Transaction zone.chain.resources2 begin 0 Start 2020-05-06 15:00:00
0 A Transaction zone.chain.resources2 begin 0 Success 2020-05-06 15:00:00
0 A Begin zone.chain.resources1, zone.chain.resources2 Success 2020-05-06 15:00:00
0 A Transaction zone.chain.resources1 tx1 args1 Start 2020-05-06 15:00:00
0 A Transaction zone.chain.resources1 tx1 args1 Success 2020-05-06 15:00:00
0 A Transaction zone.chain.resources2 tx2 args2 Start 2020-05-06 15:00:00
0 A Transaction zone.chain.resources2 tx2 args2 Success 2020-05-06 15:00:00
0 A Commit zone.chain.resources1, zone.chain.resources2 Start 2020-05-06 15:00:00
0 A Transaction zone.chain.resources1 commit 0 Start 2020-05-06 15:00:00
0 A Transaction zone.chain.resources1 commit 0 Success 2020-05-06 15:00:00
0 A Transaction zone.chain.resources2 commit 0 Start 2020-05-06 15:00:00
0 A Transaction zone.chain.resources2 commit 0 Success 2020-05-06 15:00:00
0 A Commit zone.chain.resources1, zone.chain.resources2 Success 2020-05-06 15:00:00

兼容性

两阶段事务是全新的特性,除了新增的两阶段事务接口begin()、commit()和rollback(),原接口跟旧版本WeCross是一致的,因此不存在与旧版本的兼容性问题。

安全分析

两阶段事务重在解决一致性和可用性的问题,对于区块链的安全性并无太多考虑,两阶段事务需要Router有极大的权限来操作参与事务的所有资源,此处的权限控制留给后续的权限CIP解决。

Task: 一起参与跨链接口设计

目前WeCross Router和区块链之间的交互接口包括:

  • call:查询
  • sendTransaction:发交易
  • customCommand:自定义命令
  • getBlockNumber:获取块高
  • getBlock:获取区块
  • registerEvent:注册事件

有没有不合适的,或者需要增加的,欢迎在留言区提出你的想法。

Task: Do a big deal

目前, WeCross提供了两种区块链Stub:

一起开发一个新的Stub吧,期待好汉揭榜! 😍

这是一个极具挑战的任务,如果感兴趣,请留言,社区将协助你完成开发。

ERROR: asyncCustomCommand instantiate error: Invoke orderer timeout(Have you configured all endorsements policy required peers in resource?)

诸位大佬:麻烦看个问题
接入fabric 部署代理合约的时候报错:
ERROR: asyncCustomCommand instantiate error: Invoke orderer timeout(Have you configured all endorsements policy required peers in resource?)
fabric docker 日志:
2020-10-29 07:22:39.420 UTC [endorser] ProcessProposal -> ERRO 0ee [channel-1][415643ea] simulateProposal() resulted in chaincode name:"WeCrossProxy" response status 500 for txid: 415643ea060e143f5c301ebfde041af70ec008adae376c4e4ae2f218d92b7336

router在192.168.1.39
fabric-peer0.org1在192.168.1.17:7051
fabric-orderer在192.168.1.18:7050
局域网,无网络策略

CIP-003: Unify the usage of BCOS and Hyperledger fabric using CNS

思路如下:(可在评论中直接讨论)
如果需要router调用BCOS任意地址的合约,可以实现一个由sdk发起的注册CNS操作,把address和abi发给router,router注册CNS,如果注册成功,就可以直接用path调用链上资源,不需要在router里配abi或者resource了

Task: 优化日志依赖(LF4J: Class path contains multiple SLF4J bindings.)

在进行接入bcos链时,在对应目录下执行部署代理合约命令时
java -cp 'conf/:lib/*:plugin/*' com.webank.wecross.stub.bcos.normal.proxy.ProxyContractDeployment deploy chains/bcos bcos_user1 # deploy conf下的链配置位置 账户名
返回如下错误:```
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/demo/routers-payment/127.0.0.1-8250-25500/lib/log4j-slf4j-impl-2.11.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/demo/routers-payment/127.0.0.1-8250-25500/plugin/bcos2-stub-1.0.0-rc4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/demo/routers-payment/127.0.0.1-8250-25500/plugin/bcos2-stub-gm-1.0.0-rc4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

在成功执行newHTLCTransferProposal payment.bcos.htlc bcos_user1 ......命令后,在bcos router报了如下错误,不知到是什么原因?

routers-payment/127.0.0.1-8250-25500]$ tail -f logs/warn.log 2020-05-13 18:29:06.067 [QuartzScheduler_Worker-1] WARN HTLCJob() - current round failed, path: payment.bcos.htlc, errorMessage: error in getNewContractTxInfo, internalMessage: Fabric driver call exception: java.lang.Exception: Illegal account type for fabric call: BCOS2.0 2020-05-13 18:29:08.030 [QuartzScheduler_Worker-1] ERROR FabricDriver() - Fabric driver call exception: java.lang.Exception: Illegal account type for fabric call: BCOS2.0 2020-05-13 18:29:08.030 [QuartzScheduler_Worker-1] ERROR WeCrossHTLC() - call, method: getNewContractTxInfo, errorCode: 3101, errorMsg: Fabric driver call exception: java.lang.Exception: Illegal account type for fabric call: BCOS2.0

Task: 给插件Jar包瘦个身

BCOS StubFabric Stub插件的build.gradle文件中可以使用minimize()命令最优化jar包大小。例如:

// 找到shadowJar任务,在末尾添加minimize()
shadowJar {
    // do task 

    // Enable this leads to tcnative core
    minimize()
}

Task: 把Generator的局部变量ApplicationContext改为成员变量

WeCross项目内的com.webank.wecross.Generator类,main函数内包含了类型为ApplicationContext的context局部变量,该变量打开后没有任何释放机制,可能导致内存泄漏,请将该变量的声明移动到Generator类

原代码(部分):

public class Generator {

    public static void main(String[] args) {
        ApplicationContext context =
                new AnnotationConfigApplicationContext(StubManagerConfig.class);

修改为:

public class Generator {

    private static ApplicationContext context;

	public static void main(String[] args) {
        context = new AnnotationConfigApplicationContext(StubManagerConfig.class);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.