From 6be44109ee7d125ef7813ffc0d8f47ba54d42cfc Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Fri, 16 Apr 2021 16:36:03 +0800 Subject: [PATCH 01/23] add support for Neo N3 --- go.mod | 10 +- go.sum | 228 ++---------------- .../cross_chain_manager/neo/neo_handler.go | 16 +- .../neo/neo_handler_test.go | 60 +++-- .../service/cross_chain_manager/neo/utils.go | 35 ++- native/service/header_sync/neo/header_sync.go | 10 +- .../header_sync/neo/header_sync_test.go | 169 ++++++------- native/service/header_sync/neo/states.go | 53 ++-- native/service/header_sync/neo/states_test.go | 72 +++--- native/service/header_sync/neo/utils.go | 22 +- 10 files changed, 243 insertions(+), 432 deletions(-) diff --git a/go.mod b/go.mod index 7b090dab4..f5131e4bd 100644 --- a/go.mod +++ b/go.mod @@ -15,18 +15,18 @@ require ( github.com/hashicorp/golang-lru v0.5.4 github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c github.com/itchyny/base58-go v0.1.0 - github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43 - github.com/ontio/ontology v1.11.1-0.20200812075204-26cf1fa5dd47 + github.com/joeqian10/neo3-gogogo v0.2.4 + github.com/ontio/ontology v1.11.0 github.com/ontio/ontology-crypto v1.0.9 github.com/ontio/ontology-eventbus v0.9.1 github.com/pborman/uuid v1.2.0 github.com/polynetwork/poly-io-test v0.0.0-20200819093740-8cf514b07750 - github.com/stretchr/testify v1.6.1 + github.com/stretchr/testify v1.7.0 github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d github.com/tendermint/tendermint v0.33.7 github.com/urfave/cli v1.22.4 github.com/valyala/bytebufferpool v1.0.0 - golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de - golang.org/x/net v0.0.0-20200822124328-c89045814202 + golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 + golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 gotest.tools v2.2.0+incompatible ) diff --git a/go.sum b/go.sum index 936b56289..276517451 100644 --- a/go.sum +++ b/go.sum @@ -14,14 +14,9 @@ github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxB github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM= github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/ChainSafe/go-schnorrkel v0.0.0-20200102211924-4bcbc698314f h1:4O1om+UVU+Hfcihr1timk8YNXHxzZWgCo7ofnrZRApw= -github.com/ChainSafe/go-schnorrkel v0.0.0-20200102211924-4bcbc698314f/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= -github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw= github.com/JohnCGriffin/overflow v0.0.0-20170615021017-4d914c927216 h1:2ZboyJ8vl75fGesnG9NpMTD2DyQI3FzMXy4x752rGF0= github.com/JohnCGriffin/overflow v0.0.0-20170615021017-4d914c927216/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= @@ -32,43 +27,13 @@ github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWX github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= -github.com/VictoriaMetrics/fastcache v1.5.3 h1:2odJnXLbFZcoV9KYtQ+7TH1UOq3dn3AssMgieaezkR4= github.com/VictoriaMetrics/fastcache v1.5.3/go.mod h1:+jv9Ckb+za/P1ZRg/sulP5Ni1v49daAVERr0H3CuscE= github.com/VictoriaMetrics/fastcache v1.5.7 h1:4y6y0G8PRzszQUYIQHHssv/jgPHAb5qQuuDNdCbyAgw= github.com/VictoriaMetrics/fastcache v1.5.7/go.mod h1:ptDBkNMQI4RtmVo8VS/XwRY6RoTu1dAWCbrk+6WsEM8= -github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= github.com/Workiva/go-datastructures v1.0.50/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA= github.com/Workiva/go-datastructures v1.0.52 h1:PLSK6pwn8mYdaoaCZEMsXBpBotr4HHn9abU0yMQt0NI= github.com/Workiva/go-datastructures v1.0.52/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221223316-fa21b26136c3 h1:U7Rpz5sHKYXMKx+x5AtMZqowrzB9AF2LzKBjbUGdY4w= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221223316-fa21b26136c3/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221224655-4a190da9743c h1:Xdgvo2JsPSCmHkAuHcsNDzbTIiZ04EA0JiCix4CYuAw= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221224655-4a190da9743c/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222031549-be0171a2848e h1:N+LHi8pQAsuiLNCYByERSXGrEd37HM7A3IkWKAelRjY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222031549-be0171a2848e/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222041657-f2d916e9fa86 h1:4Tk3PPz36Ckl2benfFgzVJFVJzLKd+o7S6842wJnKdo= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222041657-f2d916e9fa86/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222044512-f9f981909bf0 h1:G5eD0MmOqfyKXNYWV3L7b038XSPO7/I5bNp/UAq5aSM= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222044512-f9f981909bf0/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210223061604-4372d19745a4 h1:9fab1dN76wi1L8vKV4tAaYlexT4xgJcqVu1SJ88y/8c= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210223061604-4372d19745a4/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210223065323-8198821bf3da h1:zztmcri2+an/tR6zIhpc4EU1gOS+77GPJ4Lr6ahSL7c= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210223065323-8198821bf3da/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210223100546-8646af49b631 h1:nBGQt5tYWtsoNv/fzZl87BgeS11lw+eO1zJw5uuTYYg= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210223100546-8646af49b631/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210224063818-149d3a57a8fb h1:q3NpDNqH91DSkZsu0qJFL6s9EvGBXnqdWGvuvxAU0s8= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210224063818-149d3a57a8fb/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210224071519-7d353133524a h1:SkLbmwz+D6btAzXPmGbWhi6ajfGvveQsu/MyqR+zpIQ= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210224071519-7d353133524a/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210224095650-0f974c79345b h1:vE7Bhxe291jW59cW278jpoNnfqK03FYMQ5+fKgVrVKY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210224095650-0f974c79345b/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210303111409-fe5756ee1456 h1:XrMAFNS1zhOP9qcFrkyznMgJCnuIK9wIe74A0MYmi4I= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210303111409-fe5756ee1456/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210304105042-c4327211a4ba h1:o5WzAWqRXTI8RMwkkS1DJsNg/8TQMk2Z19HaH3bmtOs= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210304105042-c4327211a4ba/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210322040052-2d1a2d35fded h1:FqdR17dbnKxTKA/9Vxbvoe4tvSwADBj3Mg1gbsPo9Bs= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210322040052-2d1a2d35fded/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210329093354-1b8e0a7a2e25 h1:DFzNXEpvnU8Wdo2+51OptoHY/WJQenrhJFslbQydRR0= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210329093354-1b8e0a7a2e25/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= @@ -77,7 +42,6 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= @@ -95,7 +59,6 @@ github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZw github.com/bartekn/go-bip39 v0.0.0-20171116152956-a05967ea095d/go.mod h1:icNx/6QdFblhsEjZehARqbNumymUT/ydwlLojFdv7Sk= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= @@ -114,10 +77,8 @@ github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3L github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= -github.com/btcsuite/goleveldb v1.0.0 h1:Tvd0BfvqX9o823q1j2UZ/epQo09eJh6dTcRp79ilIN4= github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= -github.com/btcsuite/snappy-go v1.0.0 h1:ZxaA6lo2EpxGddsA8JwWOcxlzRybb444sgmeJQMJGQE= github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= @@ -133,7 +94,6 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod h1:1MxXX1Ux4x6mqPmjkUgTP1CdXIBXKX7T+Jk9Gxrmx+U= -github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= @@ -145,11 +105,6 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cosmos/cosmos-sdk v0.38.4 h1:jPZOvhMQkm7wwwzcLxuluhVpKfuIgddNGt999pAiz/Y= -github.com/cosmos/cosmos-sdk v0.38.4/go.mod h1:rzWOofbKfRt3wxiylmYWEFHnxxGj0coyqgWl2I9obAw= -github.com/cosmos/cosmos-sdk v0.38.5 h1:hLSrm4pvhqbA+zhyY+ltEfpynjLGeKFefctK8kHG6TE= -github.com/cosmos/cosmos-sdk v0.38.5/go.mod h1:o5V2eXScgPWh8BkKr2Z2Zq+NEt1RFW8l1HBk87JG+PY= -github.com/cosmos/cosmos-sdk v0.39.0 h1:lWZQLFxLYQ4ydD01cDZF7tRF8IN2xclDmoNPIJ5Kw44= github.com/cosmos/cosmos-sdk v0.39.1 h1:vhjf9PZh9ph8btAj9aBpHoVITgVVjNBpM3x5Gl/Vwac= github.com/cosmos/cosmos-sdk v0.39.1/go.mod h1:ry2ROl5n+f2/QXpKJo3rdWNJwll00z7KhIVcxNcl16M= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= @@ -175,17 +130,13 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8 github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/dop251/goja v0.0.0-20200219165308-d1232e640a87/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA= -github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM= -github.com/dvyukov/go-fuzz v0.0.0-20200318091601-be3528f3a813/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/edsrzf/mmap-go v0.0.0-20160512033002-935e0e8a636c/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= -github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= -github.com/elastic/gosigar v0.8.1-0.20180330100440-37f05ff46ffa h1:XKAhUk/dtp+CV0VO6mhG2V7jA9vbcGcnYF/Ay9NjZrY= github.com/elastic/gosigar v0.8.1-0.20180330100440-37f05ff46ffa/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTyCIo22xvs= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= @@ -194,37 +145,23 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= -github.com/ethereum/go-ethereum v1.9.1/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= -github.com/ethereum/go-ethereum v1.9.13 h1:rOPqjSngvs1VSYH2H+PMPiWt4VEulvNRbFgqiGqJM3E= github.com/ethereum/go-ethereum v1.9.13/go.mod h1:qwN9d1GLyDh0N7Ab8bMGd0H9knaji2jOBm2RrMGjXls= github.com/ethereum/go-ethereum v1.9.15 h1:wrWl+QrtutRUJ9LZXdUqBoGoo2b1tOCYRDrAOQhCY3A= github.com/ethereum/go-ethereum v1.9.15/go.mod h1:slT8bPPRhXsyNTwHQxrOnjuTZ1sDXRajW11EkJ84QJ0= -github.com/ethereum/go-ethereum v1.9.24 h1:6AK+ORt3EMDO+FTjzXy/AQwHMbu52J2nYHIjyQX9azQ= -github.com/ethereum/go-ethereum v1.9.24/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM= -github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= -github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= -github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 h1:E2s37DuLxFhQDg5gKsWoLBOB0n+ZW8s599zru8FJ2/Y= github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= -github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/gcash/bchd v0.14.7/go.mod h1:Gk/O1ktRVW5Kao0RsnVXp3bWxeYQadqawZ1Im9HE78M= github.com/gcash/bchd v0.15.2/go.mod h1:k9wIjgwnhbrAw+ruIPZ2tHZMzfFNdyUnORZZX7lqXGY= -github.com/gcash/bchd v0.16.4 h1:+aq3sk3MDTLLwfDldvJaQBbpALCiDMH1bT32qIeHYos= -github.com/gcash/bchd v0.16.4/go.mod h1:gR67ljCexTNwbKYN3wjbRHi9lYLp4rMomy1UQ3E1USA= github.com/gcash/bchd v0.16.5 h1:hkLUecfvcf2wf5vy05vp5X0OG9I5xWKnxdHU2/KI8PM= github.com/gcash/bchd v0.16.5/go.mod h1:gR67ljCexTNwbKYN3wjbRHi9lYLp4rMomy1UQ3E1USA= github.com/gcash/bchlog v0.0.0-20180913005452-b4f036f92fa6 h1:3pZvWJ8MSfWstGrb8Hfh4ZpLyZNcXypcGx2Ju4ZibVM= @@ -235,8 +172,6 @@ github.com/gcash/bchutil v0.0.0-20200229194731-128fc9884722/go.mod h1:wB++2ZcHUv github.com/gcash/bchutil v0.0.0-20200506001747-c2894cd54b33 h1:HNO6rKAfeYm6hE+0KXMfRomDZ8cQNlBmWirH8PSk9MY= github.com/gcash/bchutil v0.0.0-20200506001747-c2894cd54b33/go.mod h1:wB++2ZcHUvGLN1OgO9swBmJK1vmyshJLW9SNS+apXwc= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.10.0 h1:dXFJfIHVvUcpSgDOV+Ne6t7jXri8Tfv2uOLHUZ2XNuo= @@ -247,10 +182,6 @@ github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= @@ -267,7 +198,6 @@ github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129 h1:tT8iWCYw4uOem71yYA3htfH+LNopJvcqZQshm56G5L4= github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= @@ -281,33 +211,25 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26 h1:lMm2hD9Fy0ynom5+85/pbdkiYcBqM1JWmhpAXLmy0fw= -github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= -github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= @@ -322,8 +244,6 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gosuri/uilive v0.0.3 h1:kvo6aB3pez9Wbudij8srWo4iY6SFTTxTKOkb+uRCE8I= github.com/gosuri/uilive v0.0.3/go.mod h1:qkLSc0A5EXSP6B04TrN4oQoxqFI7A8XvoXSlJi8cwk8= -github.com/gosuri/uilive v0.0.4 h1:hUEBpQDj8D8jXgtCdBu7sWsy5sbW/5GhuO8KBwJ2jyY= -github.com/gosuri/uilive v0.0.4/go.mod h1:V/epo5LjjlDE5RJUcqx8dbw+zc93y5Ya3yg8tfZ74VI= github.com/gosuri/uiprogress v0.0.1 h1:0kpv/XY/qTmFWl/SkaJykZXrBBzwwadmW8fRb7RJSxw= github.com/gosuri/uiprogress v0.0.1/go.mod h1:C1RTYn4Sc7iEyf6j8ft5dyoZ4212h8G1ol9QQluh5+0= github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= @@ -333,7 +253,6 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= -github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f h1:8N8XWLZelZNibkhM1FuF+3Ad3YIbgirjdMiVA0eUkaM= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= github.com/gtank/merlin v0.1.1 h1:eQ90iG7K9pOhtereWsmyRJ6RAwcP4tHTDBHXNg+u5is= github.com/gtank/merlin v0.1.1/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= @@ -359,32 +278,25 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/holiman/uint256 v1.1.1 h1:4JywC80b+/hSfljFlEBLHrrh+CIONLDz9NuFl0af4Mw= -github.com/holiman/uint256 v1.1.1/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c h1:aY2hhxLhjEAbfXOx2nRJxCXezC6CO2V/yN+OCr1srtk= github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/huin/goupnp v0.0.0-20161224104101-679507af18f3/go.mod h1:MZ2ZmwcBpvOoJ22IJsc7va19ZwoheaBk43rKg12SKag= -github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo= github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= github.com/improbable-eng/grpc-web v0.9.1/go.mod h1:6hRR09jOEG81ADP5wCQju1z71g6OL4eEvELdran/3cs= github.com/improbable-eng/grpc-web v0.12.0/go.mod h1:6hRR09jOEG81ADP5wCQju1z71g6OL4eEvELdran/3cs= -github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= github.com/itchyny/base58-go v0.1.0 h1:zF5spLDo956exUAD17o+7GamZTRkXOZlqJjRciZwd1I= github.com/itchyny/base58-go v0.1.0/go.mod h1:SrMWPE3DFuJJp1M/RUhu4fccp/y9AlB8AL3o3duPToU= -github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 h1:6OvNmYgJyexcZ3pYbTI9jWx5tHo1Dee/tWbLMfPe2TA= github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v0.0.0-20181221193153-c0795c8afcf4/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -392,21 +304,23 @@ github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJS github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= -github.com/joeqian10/neo-gogogo v0.0.0-20200611102831-c17de5e1f0f8 h1:C+PIS6p7oQ4DwT+1IJkIvS+BMLn9TodglcqcGzhE+fQ= -github.com/joeqian10/neo-gogogo v0.0.0-20200611102831-c17de5e1f0f8/go.mod h1:1fVDp4U1ROZQBRIooecbGNHHJpfs3bG9528sqlZ096g= github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43 h1:KkErIktuwCqqZYWV8iBbD7NEsgIbyGw6xxtuylqdyu0= github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43/go.mod h1:1fVDp4U1ROZQBRIooecbGNHHJpfs3bG9528sqlZ096g= +github.com/joeqian10/neo3-gogogo v0.2.2 h1:SEZdGZqn44pIQeUTb/+mOWZj/JX+QNG+xaTRIzbfchk= +github.com/joeqian10/neo3-gogogo v0.2.2/go.mod h1:yvYQyEha3An0uYFhzR9asMU/O9HyeYy6RApRnLGPEtM= +github.com/joeqian10/neo3-gogogo v0.2.3 h1:Ucg28066O2Q/G7jGFMWuyiAxhzWWv9+A2RDEWitbkjQ= +github.com/joeqian10/neo3-gogogo v0.2.3/go.mod h1:yvYQyEha3An0uYFhzR9asMU/O9HyeYy6RApRnLGPEtM= +github.com/joeqian10/neo3-gogogo v0.2.4 h1:0aM+e/8UzTJhOr+aQlTq2aD2MlJ1y750N6Ht9g7hHSM= +github.com/joeqian10/neo3-gogogo v0.2.4/go.mod h1:yvYQyEha3An0uYFhzR9asMU/O9HyeYy6RApRnLGPEtM= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356 h1:I/yrLt2WilKxlQKCM52clh5rGzTKpVctGT1lH4Dc8Jw= github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= @@ -417,20 +331,15 @@ github.com/kkdai/bstream v0.0.0-20181106074824-b3251f7901ec/go.mod h1:J+Gs4SYgM6 github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOSqcmlfs= github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= @@ -446,7 +355,6 @@ github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 h1:hLDRPB66XQT/8+wG9WsDpiCvZf1yKO7sz7scAjSlBa0= @@ -459,7 +367,6 @@ github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eI github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -476,7 +383,6 @@ github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzE github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= @@ -486,26 +392,16 @@ github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c h1:1RHs3t github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo= github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/ontio/go-bip32 v0.0.0-20190520025953-d3cea6894a2b/go.mod h1:J0eVc7BEMmVVXbGv9PHoxjRSEwOwLr0qfzPk8Rdl5iw= -github.com/ontio/ontology v1.10.0/go.mod h1:iok/imHJVQXi5/Yr88dcbrKBRHGdiota1ZC6qh6l6Rc= github.com/ontio/ontology v1.11.0 h1:0T/hxFDHQqRcs1+yEdgaym5YIvGx5yebOsHYdKVWgHI= github.com/ontio/ontology v1.11.0/go.mod h1:Qw74bfTBlIQka+jQX4nXuWvyOYGGt368/V7XFxaf4tY= -github.com/ontio/ontology v1.11.1-0.20200812075204-26cf1fa5dd47 h1:9iZitqJe7SBGF8f6jOHjhotrB7ZLKKMM+g6S0tMbOL4= -github.com/ontio/ontology v1.11.1-0.20200812075204-26cf1fa5dd47/go.mod h1:aoLM6pLdjBLx2CwC/AUtxdHvLZzAVqYH/xehh6/sRP4= github.com/ontio/ontology-crypto v1.0.9 h1:6fxBsz3W4CcdJk4/9QO7j0Qq7NdlP2ixPrViu8XpzzM= github.com/ontio/ontology-crypto v1.0.9/go.mod h1:h/jeqqb9Ma/Leszxqh6zY3eTF2yks44hyRKikMni+YQ= github.com/ontio/ontology-eventbus v0.9.1 h1:nt3AXWx3gOyqtLiU4EwI92Yc4ik/pWHu9xRK15uHSOs= github.com/ontio/ontology-eventbus v0.9.1/go.mod h1:hCQIlbdPckcfykMeVUdWrqHZ8d30TBdmLfXCVWGkYhM= -github.com/ontio/ontology-go-sdk v1.11.4/go.mod h1:fRhHYhFfYiUuIlTVtcXLVziiXOneBwVCSAX72+N7XVI= github.com/ontio/wagon v0.4.1/go.mod h1:oTPdgWT7WfPlEyzVaHSn1vQPMSbOpQPv+WphxibWlhg= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= @@ -524,10 +420,8 @@ github.com/pborman/uuid v0.0.0-20170112150404-1b00554d8222/go.mod h1:VyrYX9gd7ir github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pelletier/go-toml v1.6.0 h1:aetoXYr0Tv7xRU/V4B4IZJ2QcbtMUFoNb3ORp7TzIK4= github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= -github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= @@ -538,43 +432,29 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polynetwork/btc-vendor-tools v0.0.0-20200813091748-3b19a5fd7666/go.mod h1:U8rR9X6vemlkBAJWfvzwSoalcJjX8B2aQjB0kPRhBUA= -github.com/polynetwork/cosmos-poly-module v0.0.0-20200810030259-95d586518759/go.mod h1:VMBJZ8GSZeoWBntd/rWx2Rr5roRKofO7siP1qd6A6pY= -github.com/polynetwork/eth-contracts v0.0.0-20200814062128-70f58e22b014/go.mod h1:TeePrYZfWJAwuksPlie7RPequ51Ujp5l/JY6TcutsFc= -github.com/polynetwork/poly v0.0.0-20200710095239-0596a3d7afe5/go.mod h1:UzlGEWk0eCGsuMJOZfBoZjRbmu4Yw/SudKAIFe1gPnY= -github.com/polynetwork/poly v0.0.0-20200715030435-4f1d1a0adb44/go.mod h1:UzlGEWk0eCGsuMJOZfBoZjRbmu4Yw/SudKAIFe1gPnY= -github.com/polynetwork/poly-go-sdk v0.0.0-20200722030827-6875b6018b93/go.mod h1:a1wMo/VFoUAKX2yVjipvFug6Yu5BPhf/2tP5xywqfIc= -github.com/polynetwork/poly-go-sdk v0.0.0-20200730112529-d9c0c7ddf3d8/go.mod h1:a1wMo/VFoUAKX2yVjipvFug6Yu5BPhf/2tP5xywqfIc= -github.com/polynetwork/poly-io-test v0.0.0-20200819093740-8cf514b07750 h1:deB0JDwuU95U36gnOjBXHGihUenU6/mLK0MSGBb/UxU= -github.com/polynetwork/poly-io-test v0.0.0-20200819093740-8cf514b07750/go.mod h1:Y/xz9uHdO0HPz0p+x0bZxNuo1ufVcln3dDjmchSUgso= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= -github.com/prometheus/client_golang v1.5.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= -github.com/prometheus/client_golang v1.5.1 h1:bdHYieyGlH+6OLEk2YQha8THib30KP0/yD0YH9m6xcA= github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= -github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= github.com/prometheus/tsdb v0.6.2-0.20190402121629-4f204dcbc150/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA= @@ -582,7 +462,6 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T github.com/rakyll/statik v0.1.6/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/rjeczalik/notify v0.9.1 h1:CLCKso/QK1snAlnhNR/CNvNiFU2saUtjV0bx3EwNeCE= github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -594,20 +473,15 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/scylladb/go-set v1.0.2/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shirou/gopsutil v2.20.5-0.20200531151128-663af789c085+incompatible h1:+gAR1bMhuoQnZMTWFIvp7ukynULPsteLzG+siZKLtD8= github.com/shirou/gopsutil v2.20.5-0.20200531151128-663af789c085+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/shirou/gopsutil v2.20.5+incompatible h1:tYH07UPoQt0OCQdgWWMgYHy3/a9bcxNpBIysykNIP7I= -github.com/shirou/gopsutil v2.20.5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa/go.mod h1:oJyF+mSPHbB5mVY2iO9KV3pTt/QbIkGaO8gQ2WrDbP4= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -615,26 +489,17 @@ github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.0.1-0.20190317074736-539464a789e9/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M= github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= -github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= -github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= -github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= -github.com/spf13/viper v1.6.3 h1:pDDu1OyEDTKzpJwdq4TiuLyMsUgRa/BT5cn5O62NoHs= github.com/spf13/viper v1.6.3/go.mod h1:jUMtyi0/lB5yZH/FjyGAoH7IMNrIhlBf6pXZmbMDvzw= -github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 h1:Gb2Tyox57NRNuZ2d3rmvB3pcmbu7O1RS3m8WRx7ilrg= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 h1:gIlAHnH1vJb5vwEjIp5kBj/eu99p/bl0Ay2goiPe5xE= github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw= @@ -645,23 +510,17 @@ github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3 github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= -github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= -github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca h1:Ld/zXl5t4+D69SiV4JoN7kkfvJdOWlPpfxrzxpLMoUk= -github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca/go.mod h1:u2MKkTVTVJWe5D1rCvame8WqhBd88EuIwODJZ1VHCPM= github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok= github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U= @@ -669,47 +528,27 @@ github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso= github.com/tendermint/go-amino v0.15.1 h1:D2uk35eT4iTsvJd9jWIetzthE5C0/k2QmMFkCN+4JgQ= github.com/tendermint/go-amino v0.15.1/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= -github.com/tendermint/iavl v0.12.4/go.mod h1:8LHakzt8/0G3/I8FUU0ReNx98S/EP6eyPJkAUvEXT/o= -github.com/tendermint/iavl v0.13.2 h1:O1m08/Ciy53l9IYmf75uIRVvrNsfjEbre8u/yCu/oqk= -github.com/tendermint/iavl v0.13.2/go.mod h1:vE1u0XAGXYjHykd4BLp8p/yivrw2PF1TuoljBcsQoGA= github.com/tendermint/iavl v0.14.0 h1:Jkff+IFrXxRWtH9Jn/ga/2cxNnzMTv58xEKgCJsKUBg= github.com/tendermint/iavl v0.14.0/go.mod h1:QmfViflFiXzxKLQE4tAUuWQHq+RSuQFxablW5oJZ6sE= -github.com/tendermint/tendermint v0.33.2/go.mod h1:25DqB7YvV1tN3tHsjWoc2vFtlwICfrub9XO6UBO+4xk= -github.com/tendermint/tendermint v0.33.3 h1:6lMqjEoCGejCzAghbvfQgmw87snGSqEhDTo/jw+W8CI= -github.com/tendermint/tendermint v0.33.3/go.mod h1:25DqB7YvV1tN3tHsjWoc2vFtlwICfrub9XO6UBO+4xk= -github.com/tendermint/tendermint v0.33.4 h1:NM3G9618yC5PaaxGrcAySc5ylc1PAANeIx42u2Re/jo= -github.com/tendermint/tendermint v0.33.4/go.mod h1:6NW9DVkvsvqmCY6wbRsOo66qGDhMXglRL70aXajvBEA= github.com/tendermint/tendermint v0.33.5/go.mod h1:0yUs9eIuuDq07nQql9BmI30FtYGcEC60Tu5JzB5IezM= -github.com/tendermint/tendermint v0.33.6 h1:W4UOsXY4ROJZ3TLLGVVv71VXD4WK2gJRb3gzeced+mg= -github.com/tendermint/tendermint v0.33.6/go.mod h1:0yUs9eIuuDq07nQql9BmI30FtYGcEC60Tu5JzB5IezM= github.com/tendermint/tendermint v0.33.7 h1:b5CQD8ggDtl4u0EbXzabi0MaOw9NrcXker6ijEkAE74= github.com/tendermint/tendermint v0.33.7/go.mod h1:0yUs9eIuuDq07nQql9BmI30FtYGcEC60Tu5JzB5IezM= -github.com/tendermint/tm-db v0.1.1/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw= -github.com/tendermint/tm-db v0.2.0/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw= -github.com/tendermint/tm-db v0.4.1/go.mod h1:JsJ6qzYkCGiGwm5GHl/H5GLI9XLb6qZX7PRe425dHAY= -github.com/tendermint/tm-db v0.5.0 h1:qtM5UTr1dlRnHtDY6y7MZO5Di8XAE2j3lc/pCnKJ5hQ= -github.com/tendermint/tm-db v0.5.0/go.mod h1:lSq7q5WRR/njf1LnhiZ/lIJHk2S8Y1Zyq5oP/3o9C2U= github.com/tendermint/tm-db v0.5.1 h1:H9HDq8UEA7Eeg13kdYckkgwwkQLBnJGgX4PgLJRhieY= github.com/tendermint/tm-db v0.5.1/go.mod h1:g92zWjHpCYlEvQXvy9M168Su8V1IBEeawpXVVBaK4f4= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= -github.com/tyler-smith/go-bip39 v1.0.2 h1:+t3w+KwLXO6154GNJY+qUtIxLTmFjfUmpguQT1OlOT8= github.com/tyler-smith/go-bip39 v1.0.2/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= -github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= -github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA= github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208 h1:1cngl9mPEoITZG8s8cVcUy5CeIBYhEESkOB7m6Gmkrk= github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208/go.mod h1:IotVbo4F+mw0EzQ08zFqg7pK3FebNXpaMsRy2RT+Ees= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -github.com/ybbus/jsonrpc v2.1.2+incompatible h1:V4mkE9qhbDQ92/MLMIhlhMSbz8jNXdagC3xBR5NDwaQ= github.com/ybbus/jsonrpc v2.1.2+incompatible/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= github.com/zquestz/grab v0.0.0-20190224022517-abcee96e61b1 h1:1qKTeMTSIEvRIjvVYzgcRp0xVp0eoiRTTiHSncb5gD8= @@ -745,25 +584,18 @@ golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200406173513-056763e48d71/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w= +golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20200801112145-973feb4309de/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -790,12 +622,9 @@ golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= -golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -820,26 +649,20 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 h1:5B6i6EAiSYyejWfvc5Rc9BbI3rzIsrrXfAQBWnYfn+w= golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed h1:J22ig1FUekjjkmZUM7pTKixYm8DvrYsvrBZdunYeIuQ= -golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 h1:AvbQYmiaaaza3cW3QXRyPo5kYgpFIzOAfeAAN7m3qQ4= -golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -853,7 +676,6 @@ golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= @@ -861,14 +683,10 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -895,10 +713,8 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.28.0 h1:bO/TA4OxCOummhSf10siHuG7vJOiwh7SpRpFZDkOgl4= google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= google.golang.org/grpc v1.28.1/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= -google.golang.org/grpc v1.29.1 h1:EC2SB8S04d2r73uptxphDSUG+kTKVgjRPF+N3xpxRB4= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.30.0 h1:M5a8xTlYTxwMn5ZFkwhRabsygDY5G8TYLyQDBxJNAxE= google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= @@ -907,30 +723,23 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0 h1:cJv5/xdbk1NnMPR1VP9+HU6gupuG9MLBoH1r6RHZ2MY= google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= -gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200316214253-d7b0ff38cac9/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns= gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200603215123-a4a8cb9d2cbc/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns= -gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= @@ -939,18 +748,13 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/native/service/cross_chain_manager/neo/neo_handler.go b/native/service/cross_chain_manager/neo/neo_handler.go index 3f6af92a3..8a996d346 100644 --- a/native/service/cross_chain_manager/neo/neo_handler.go +++ b/native/service/cross_chain_manager/neo/neo_handler.go @@ -19,6 +19,7 @@ package neo import ( "fmt" + "github.com/joeqian10/neo3-gogogo/helper" "github.com/polynetwork/poly/common" "github.com/polynetwork/poly/native" scom "github.com/polynetwork/poly/native/service/cross_chain_manager/common" @@ -27,6 +28,7 @@ import ( ) type NEOHandler struct { + ccmcId *int } func NewNEOHandler() *NEOHandler { @@ -51,7 +53,14 @@ func (this *NEOHandler) MakeDepositProposal(service *native.NativeService) (*sco if err != nil { return nil, fmt.Errorf("neo MakeDepositProposal, side_chain_manager.GetSideChain error: %v", err) } - value, err := verifyFromNeoTx(params.Proof, crossChainMsg, sideChain.CCMCAddress) + + // convert neo contract address bytes to id, it is different from other chains, it stores int in a []byte, contract id can be get from "getcontractstate" api + // todo, when register neo N3, convert ccmc id to []byte; native contracts have negative ids, while custom contracts have positive ones + if this.ccmcId == nil { + this.SetCcmcId(sideChain.CCMCAddress) + } + + value, err := verifyFromNeoTx(params.Proof, crossChainMsg, *this.ccmcId) if err != nil { return nil, fmt.Errorf("neo MakeDepositProposal, VerifyFromNeoTx error: %v", err) } @@ -64,3 +73,8 @@ func (this *NEOHandler) MakeDepositProposal(service *native.NativeService) (*sco } return value, nil } + +func (this *NEOHandler) SetCcmcId(idBytes []byte) { + id := int(int32(helper.BytesToUInt32(idBytes))) + this.ccmcId = &id +} diff --git a/native/service/cross_chain_manager/neo/neo_handler_test.go b/native/service/cross_chain_manager/neo/neo_handler_test.go index e2e9c1bfe..b236147ed 100644 --- a/native/service/cross_chain_manager/neo/neo_handler_test.go +++ b/native/service/cross_chain_manager/neo/neo_handler_test.go @@ -18,11 +18,10 @@ package neo import ( - "encoding/binary" "encoding/hex" - "github.com/joeqian10/neo-gogogo/block" - "github.com/joeqian10/neo-gogogo/helper" - tx2 "github.com/joeqian10/neo-gogogo/tx" + "github.com/joeqian10/neo3-gogogo/crypto" + "github.com/joeqian10/neo3-gogogo/helper" + tx2 "github.com/joeqian10/neo3-gogogo/tx" "github.com/ontio/ontology-crypto/keypair" "github.com/polynetwork/poly/account" "github.com/polynetwork/poly/common" @@ -40,6 +39,7 @@ import ( "github.com/polynetwork/poly/native/service/utils" "github.com/polynetwork/poly/native/storage" "github.com/stretchr/testify/assert" + "log" "testing" ) @@ -88,29 +88,28 @@ func Test_Neo_MakeDepositProposal(t *testing.T) { var native *native.NativeService { prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - merKleRoot, _ := helper.UInt256FromString("0xee3ba4cd680d1acd06b067a7d57fd20e47f79203a23e99f28915e57b4e6c1058") - nextConsensus, _ := helper.AddressToScriptHash("AdP4zfgVEgn8nhRN5s76aVNEcDaftkqbyW") - consensusData := binary.BigEndian.Uint64(helper.HexToBytes("000000007c2bac1d")) - genesisHeader := &neo.NeoBlockHeader{ - &block.BlockHeader{ - Version: 0, - PrevHash: prevHash, - MerkleRoot: merKleRoot, - Timestamp: 1468595301, - Index: 0, - NextConsensus: nextConsensus, - ConsensusData: consensusData, - Witness: &tx2.Witness{ - InvocationScript: []byte{0}, - VerificationScript: []byte{81}, - }, - }, + merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) + vs, _ := crypto.Base64Decode("EQ==") + witness := tx2.Witness{ + InvocationScript: []byte{}, + VerificationScript: vs, } + genesisHeader := &neo.NeoBlockHeader{} + genesisHeader.SetVersion(0) + genesisHeader.SetPrevHash(prevHash) + genesisHeader.SetMerkleRoot(merkleRoot) + genesisHeader.SetTimeStamp(1468595301000) + genesisHeader.SetIndex(0) + genesisHeader.SetPrimaryIndex(0x00) + genesisHeader.SetNextConsensus(nextConsensus) + genesisHeader.SetWitnesses([]tx2.Witness{witness}) + param := new(hscom.SyncGenesisHeaderParam) param.ChainID = 4 var err error sink := common.NewZeroCopySink(nil) - genesisHeader.Serialization(sink) + err = genesisHeader.Serialization(sink) param.GenesisHeader = sink.Bytes() if err != nil { t.Errorf("NeoBlockHeaderToBytes error:%v", err) @@ -158,5 +157,22 @@ func Test_Neo_MakeDepositProposal(t *testing.T) { _, err = neoHandler.MakeDepositProposal(native) assert.Nil(t, err) } +} + +func TestNEOHandler_SetCcmcId(t *testing.T) { + // test positive int + idp := 5 + idpBytes := helper.IntToBytes(idp) + log.Println(helper.BytesToHex(idpBytes)) + + idp2 := int(helper.BytesToUInt32(idpBytes)) + assert.Equal(t, idp, idp2) + + // test negative int + idn := -5 + idnBytes := helper.IntToBytes(idn) + log.Println(helper.BytesToHex(idnBytes)) + idn2 := int(int32(helper.BytesToUInt32(idnBytes))) + assert.Equal(t, idn, idn2) } diff --git a/native/service/cross_chain_manager/neo/utils.go b/native/service/cross_chain_manager/neo/utils.go index 3f905f8d7..7f1cf38fd 100644 --- a/native/service/cross_chain_manager/neo/utils.go +++ b/native/service/cross_chain_manager/neo/utils.go @@ -17,46 +17,43 @@ package neo import ( - "bytes" - "encoding/hex" "fmt" - "github.com/joeqian10/neo-gogogo/helper" - "github.com/joeqian10/neo-gogogo/mpt" + "github.com/joeqian10/neo3-gogogo/helper" + "github.com/joeqian10/neo3-gogogo/mpt" "github.com/polynetwork/poly/common" scom "github.com/polynetwork/poly/native/service/cross_chain_manager/common" "github.com/polynetwork/poly/native/service/header_sync/neo" ) -func verifyFromNeoTx(proof []byte, crosschainMsg *neo.NeoCrossChainMsg, contractAddr []byte) (*scom.MakeTxParam, error) { - crossStateProofRoot, err := helper.UInt256FromString(crosschainMsg.StateRoot.StateRoot) +func verifyFromNeoTx(proof []byte, crossChainMsg *neo.NeoCrossChainMsg, contractId int) (*scom.MakeTxParam, error) { + crossStateProofRoot, err := helper.UInt256FromString(crossChainMsg.StateRoot.RootHash) if err != nil { - return nil, fmt.Errorf("verifyFromNeoTx, decode cross state proof root from string error:%s", err) + return nil, fmt.Errorf("verifyFromNeoTx, decode cross state proof root from string error: %s", err) } - value, err := VerifyNeoCrossChainProof(proof, crossStateProofRoot.Bytes(), contractAddr) + value, err := VerifyNeoCrossChainProof(proof, crossStateProofRoot.ToByteArray(), contractId) if err != nil { - return nil, fmt.Errorf("VerifyFromNeoTx, Verify Neo cross chain proof error:%v", err) + return nil, fmt.Errorf("VerifyFromNeoTx, Verify Neo cross chain proof error: %v", err) } source := common.NewZeroCopySource(value) txParam := new(scom.MakeTxParam) if err := txParam.Deserialization(source); err != nil { - return nil, fmt.Errorf("VerifyFromNeoTx, deserialize merkleValue error:%s", err) + return nil, fmt.Errorf("VerifyFromNeoTx, deserialize merkleValue error: %s", err) } return txParam, nil } -func VerifyNeoCrossChainProof(proof []byte, stateRoot []byte, contractAddr []byte) ([]byte, error) { - scriptHash, key, proofs, err := mpt.ResolveProof(proof) +func VerifyNeoCrossChainProof(proof []byte, stateRoot []byte, contractId int) ([]byte, error) { + id, key, proofs, err := mpt.ResolveProof(proof) if err != nil { - return nil, fmt.Errorf("VerifyNeoCrossChainProof, joeqian10/neo-gogogo/mpt.ResolveProof error:%v", err) + return nil, fmt.Errorf("VerifyNeoCrossChainProof, neo3-gogogo mpt.ResolveProof error: %v", err) } - if !bytes.Equal(scriptHash.Bytes(), contractAddr) { - return nil, fmt.Errorf("VerifyNeoCrossChainProof, error:scriptHash is not CCMC contract address, expected:%s, but got %s", hex.EncodeToString(common.ToArrayReverse(contractAddr)), scriptHash.String()) + if id != contractId { + return nil, fmt.Errorf("VerifyNeoCrossChainProof, error: id is not CCMC contract id, expected: %d, but got %d", contractId, id) } - value, err := mpt.VerifyProof(stateRoot, scriptHash, key, proofs) + root := helper.UInt256FromBytes(stateRoot) + value, err := mpt.VerifyProof(root, contractId, key, proofs) if err != nil { - return nil, fmt.Errorf("VerifyNeoCrossChainProof, joeqian10/neo-gogogo/mpt.VerifyProof error:%v", err) + return nil, fmt.Errorf("VerifyNeoCrossChainProof, neo3-gogogo mpt.VerifyProof error: %v", err) } - return value, nil - } diff --git a/native/service/header_sync/neo/header_sync.go b/native/service/header_sync/neo/header_sync.go index c6b9acabf..d3d2fd74a 100644 --- a/native/service/header_sync/neo/header_sync.go +++ b/native/service/header_sync/neo/header_sync.go @@ -58,8 +58,8 @@ func (this *NEOHandler) SyncGenesisHeader(native *native.NativeService) error { // Put NeoConsensus.NextConsensus into storage if err = putConsensusValByChainId(native, &NeoConsensus{ ChainID: params.ChainID, - Height: header.Index, - NextConsensus: header.NextConsensus, + Height: header.GetIndex(), + NextConsensus: header.GetNextConsensus(), }); err != nil { return fmt.Errorf("NeoHandler SyncGenesisHeader, update ConsensusPeer error: %v", err) } @@ -82,14 +82,14 @@ func (this *NEOHandler) SyncBlockHeader(native *native.NativeService) error { if err := header.Deserialization(common.NewZeroCopySource(v)); err != nil { return fmt.Errorf("SyncBlockHeader, NeoBlockHeaderFromBytes error: %v", err) } - if !header.NextConsensus.Equals(neoConsensus.NextConsensus) && header.Index > neoConsensus.Height { + if !header.GetNextConsensus().Equals(neoConsensus.NextConsensus) && header.GetIndex() > neoConsensus.Height { if err = verifyHeader(native, params.ChainID, header); err != nil { return fmt.Errorf("SyncBlockHeader, verifyHeader error: %v", err) } newNeoConsensus = &NeoConsensus{ ChainID: neoConsensus.ChainID, - Height: header.Index, - NextConsensus: header.NextConsensus, + Height: header.GetIndex(), + NextConsensus: header.GetNextConsensus(), } } } diff --git a/native/service/header_sync/neo/header_sync_test.go b/native/service/header_sync/neo/header_sync_test.go index cc5d0a3d8..3939755af 100644 --- a/native/service/header_sync/neo/header_sync_test.go +++ b/native/service/header_sync/neo/header_sync_test.go @@ -18,14 +18,10 @@ package neo import ( - "encoding/hex" - "testing" - - "encoding/binary" - "github.com/joeqian10/neo-gogogo/block" - "github.com/joeqian10/neo-gogogo/helper" - tx2 "github.com/joeqian10/neo-gogogo/tx" - "github.com/joeqian10/neo-gogogo/wallet" + "github.com/joeqian10/neo3-gogogo/block" + "github.com/joeqian10/neo3-gogogo/crypto" + "github.com/joeqian10/neo3-gogogo/helper" + tx2 "github.com/joeqian10/neo3-gogogo/tx" "github.com/ontio/ontology-crypto/keypair" "github.com/polynetwork/poly/account" "github.com/polynetwork/poly/common" @@ -37,13 +33,14 @@ import ( scom "github.com/polynetwork/poly/native/service/header_sync/common" "github.com/polynetwork/poly/native/storage" "github.com/stretchr/testify/assert" + "testing" ) var ( - neoAcct = func() *wallet.Account { - acct, _ := wallet.NewAccount() - return acct - }() + //neoAcct = func() *wallet.Account { + // acct, _ := wallet.NewAccount() + // return acct + //}() acct *account.Account = account.NewAccount("") getNativeFunc = func() *native.NativeService { store, _ := leveldbstore.NewMemLevelDBStore() @@ -74,24 +71,23 @@ func NewNative(args []byte, tx *types.Transaction, db *storage.CacheDB) *native. func TestSyncGenesisHeader(t *testing.T) { prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - merKleRoot, _ := helper.UInt256FromString("0x803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4") - nextConsensus, _ := helper.AddressToScriptHash("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") - consensusData := binary.BigEndian.Uint64(helper.HexToBytes("000000007c2bac1d")) - genesisHeader := &NeoBlockHeader{ - &block.BlockHeader{ - Version: 0, - PrevHash: prevHash, - MerkleRoot: merKleRoot, - Timestamp: 1468595301, - Index: 0, - NextConsensus: nextConsensus, - ConsensusData: consensusData, - Witness: &tx2.Witness{ - InvocationScript: []byte{0}, - VerificationScript: []byte{81}, - }, - }, + merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) + vs, _ := crypto.Base64Decode("EQ==") + witness := tx2.Witness{ + InvocationScript: []byte{}, + VerificationScript: vs, } + genesisHeader := &NeoBlockHeader{Header:new(block.Header)} + genesisHeader.SetVersion(0) + genesisHeader.SetPrevHash(prevHash) + genesisHeader.SetMerkleRoot(merkleRoot) + genesisHeader.SetTimeStamp(1468595301000) + genesisHeader.SetIndex(0) + genesisHeader.SetPrimaryIndex(0x00) + genesisHeader.SetNextConsensus(nextConsensus) + genesisHeader.SetWitnesses([]tx2.Witness{witness}) + param := new(scom.SyncGenesisHeaderParam) param.ChainID = 4 sink := common.NewZeroCopySink(nil) @@ -105,7 +101,8 @@ func TestSyncGenesisHeader(t *testing.T) { tx := &types.Transaction{ SignedAddr: []common.Address{acct.Address}, } - + //cdb := new(storage.CacheDB) + //cdb.Put() native := NewNative(sink.Bytes(), tx, nil) neoHandler := NewNEOHandler() err = neoHandler.SyncGenesisHeader(native) @@ -113,80 +110,73 @@ func TestSyncGenesisHeader(t *testing.T) { } func TestSyncBlockHeader(t *testing.T) { - prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - merKleRoot, _ := helper.UInt256FromString("0x803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4") - nextConsensus, _ := helper.AddressToScriptHash("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") - consensusData := binary.BigEndian.Uint64(helper.HexToBytes("000000007c2bac1d")) - genesisHeader := &NeoBlockHeader{ - &block.BlockHeader{ - Version: 0, - PrevHash: prevHash, - MerkleRoot: merKleRoot, - Timestamp: 1468595301, - Index: 0, - NextConsensus: nextConsensus, - ConsensusData: consensusData, - Witness: &tx2.Witness{ - InvocationScript: []byte{0}, - VerificationScript: []byte{81}, - }, - }, + merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) + is := []byte{} + vs, _ := crypto.Base64Decode("EQ==") + witness := tx2.Witness{ + InvocationScript: is, + VerificationScript: vs, } + genesisHeader := &NeoBlockHeader{Header:new(block.Header)} + genesisHeader.SetVersion(0) + genesisHeader.SetPrevHash(prevHash) + genesisHeader.SetMerkleRoot(merkleRoot) + genesisHeader.SetTimeStamp(1468595301000) + genesisHeader.SetIndex(0) + genesisHeader.SetPrimaryIndex(0x00) + genesisHeader.SetNextConsensus(nextConsensus) + genesisHeader.SetWitnesses([]tx2.Witness{witness}) sink := common.NewZeroCopySink(nil) if err := genesisHeader.Serialization(sink); err != nil { t.Errorf("NeoBlockHeaderToBytes error:%v", err) } neoGenesisHeaderbs := sink.Bytes() - - prevHash, _ = helper.UInt256FromString("0x07e53bcbe93de88784e01401f8dae061934d34747e76b6a18b63e4213f3de220") - merKleRoot, _ = helper.UInt256FromString("0xbf6a0b78bede3ad758e09479b8712f60cb225a4047265847169b3864e23a3bc8") - nextConsensus, _ = helper.AddressToScriptHash("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") - consensusData = binary.BigEndian.Uint64(helper.HexToBytes("d9d3b5ccf2eedde1")) - is100, _ := hex.DecodeString("40424db765bc1e92e530292ec04ff8ddffb79bec13f04fd9f85c00163328aa9d64f0b40b74ca8c4b56445c9048c50e6a67df57ab221593612c6165251d9770f7e140465f1d1d3b532fcaa8a98633316e24a07358c857a3565f7cc9a1b87dd3e6dcbb191a7c78c1b57889924e813a0daacea5281884ce814d10469560f43c9d567cf440fd7252d9607389e9b61c577a8705b1d74165979dd9440c4a71d47443fc1014e46957b0a537e1244fd9b4363aefb2df5971749daf9073cfd014aecb7dba2b13ab40c141f6c63267ad12ebadb154a83a3444eccff046de534cda6f29059e531de58bfce6287ca68a62b45766df5522dfed449b3d1bdc0a319ab07d21cf8839f5b59240fee381887b2dc82447fbe9e6db6c1aa9adff8f7a7d2998cea4f901c002098115d7ba7e6218275c8690f86b92e8b641d59152243f2253ff86fa9c2b6413a52256") - vs100, _ := hex.DecodeString("552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae") - neoHeader100 := &NeoBlockHeader{ - &block.BlockHeader{ - Version: 0, - PrevHash: prevHash, - MerkleRoot: merKleRoot, - Timestamp: 1476649243, - Index: 100, - NextConsensus: nextConsensus, - ConsensusData: consensusData, - Witness: &tx2.Witness{ - InvocationScript: is100, - VerificationScript: vs100, - }, - }, + // block 100 + prevHash, _ = helper.UInt256FromString("0xcee650e843a8f8cf78f7c62a2bc2108375df93bfa9a912de64bea2d8948fec31") + merkleRoot, _ = helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ = crypto.AddressToScriptHash("NYmMriQPYAiNxHC7tziV4ABJku5Yqe79N4", helper.DefaultAddressVersion) + is, _ = crypto.Base64Decode("DEAF2siXzBq5rCzpaNvAxTPuebSgsn3XX7bKMvuf1RzQx1QqJDLBn/XxMyCzAOnsolp67X8eLZ8xuc4bovqSMf4lDECxfs8iV5/5yLs2hVW0tB1d1n7R1J3HEoJ8vNCJr/xrqt3bJRoOFL+eObBmjyo+ZSk5M6GrGH+UqpglZqr0upu8DEAX9lh0LKdbFTOg5GfZ8gP9UdGURu/xbM288BKFUBXhTH1p/2Y4hqZzJoXes+DdlRCwWzhToCMa468OnmTHkxDoDEB4etR6RX+B69qB5cv7QjihqnTowYWzU3Zhec+yz+2wgETkD0aD4uUafiSGpCK7xNB7aknDbFgMJXWSK7cM+c3NDEDw4z4PxskKUfJ1cmXKXxhtdzo/05iEi6c/n2rfZHPLd/YA0aBPQuWf3QSWizQYsmsYyA2uriKR2PA7asqYYB60") + vs, _ = crypto.Base64Decode("FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhAj6bMuqJuU0GbmSbEk/VDjlu6RNp6OKmrhsRwXDQIiVtDCEDQI3NQWOW9keDrFh+oeFZPFfZ/qiAyKahkg6SollHeAYMIQKng0vpsy4pgdFXy1u9OstCz9EepcOxAiTXpE6YxZEPGwwhAroscPWZbzV6QxmHBYWfriz+oT4RcpYoAHcrPViKnUq9F0F7zmyl") + witness = tx2.Witness{ + InvocationScript: is, + VerificationScript: vs, } + neoHeader100 := &NeoBlockHeader{Header:new(block.Header)} + neoHeader100.SetVersion(0) + neoHeader100.SetPrevHash(prevHash) + neoHeader100.SetMerkleRoot(merkleRoot) + neoHeader100.SetTimeStamp(1616577294488) + neoHeader100.SetIndex(100) + neoHeader100.SetPrimaryIndex(0x00) + neoHeader100.SetNextConsensus(nextConsensus) + neoHeader100.SetWitnesses([]tx2.Witness{witness}) sink = common.NewZeroCopySink(nil) if err := neoHeader100.Serialization(sink); err != nil { t.Errorf("NeoBlockHeaderToBytes error:%v", err) } neoHeader100bs := sink.Bytes() - prevHash, _ = helper.UInt256FromString("0xb4cabbcde5e5d5ecf0429cb4726f7a4d857e195e12bdc568cb1df2097c2d918d") - merKleRoot, _ = helper.UInt256FromString("0xb230e8bc2e0f35eff5279de5d6f9a6b1c26c5757247c4f33d744676919bfb3d1") - nextConsensus, _ = helper.AddressToScriptHash("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") - consensusData = binary.BigEndian.Uint64(helper.HexToBytes("ab01a2420960665a")) - is200, _ := hex.DecodeString("409de7102817ffda29e13e96e3ff541ea1c7498805504d39d2145990c9862f2aacdb748b631233c14a63cc1483f730843eced2abab80a9c5bbe4c7b5a552569cac40d3fde603e228e2ca3ee25ebf7651692be1bfa50cbc0230242719cd2d045d21c2fe44dc80e48dd8fd8ab741be0ce527b8aeada80f8c09f86af83ae6ed4f5e1e3940382bd5b00bf1778c09d402165b36756d6cbc8e7970fed080ba9805b96cc7ba5ff0606b7824585e6d4f318cb7b69dd1d7b5dbd82644aa9d329e73828225521f7e401d568aaef9d790358fc8475154d0c541ac7cef4f4fb51a18ddc5c1fab4f49bb138d4a7dad2f259579e7686819e668c28f024be117cc3aaa7a2dcad77336a0427404ab053cae9db932d988884f9e5c9026e18f762aad9d0bb143edc9e6c808f1f5585ed951103c251dcc331a6db3865faf22b778ce05e68e351608528c8fb1b172b") - vs200, _ := hex.DecodeString("552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae") - neoHeader200 := &NeoBlockHeader{ - &block.BlockHeader{ - Version: 0, - PrevHash: prevHash, - MerkleRoot: merKleRoot, - Timestamp: 1476651132, - Index: 200, - NextConsensus: nextConsensus, - ConsensusData: consensusData, - Witness: &tx2.Witness{ - InvocationScript: is200, - VerificationScript: vs200, - }, - }, + // block 200 + prevHash, _ = helper.UInt256FromString("0xe22cd5bb35d832e59554dc2d4165a48bed56b2d7f9df379639078cca35ecc770") + merkleRoot, _ = helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ = crypto.AddressToScriptHash("NYmMriQPYAiNxHC7tziV4ABJku5Yqe79N4", helper.DefaultAddressVersion) + is, _ = crypto.Base64Decode("DEBGAk7oudrv67j+GFWetgK8W0Hu6m/15ceMxaq3sl6aKfjTQckmQfqzzGgzJ/rrdWMCyCsjYkgc14MdFvI/GnopDEBj9dRQtcKyu9K2qOyvqqkUoqK/9A32kdj0LbXpYPw+WDrz0DlvjNQF8dc2EuvmwTrYuQ5fUTrHvaPXKTmOPl3IDEAKtZf8AaZmY+onQejV8jqkEN5DGKKWthYGpVza5jueTvx4Hi1B5Uh7k6jW5Z6Y7mUVGuIUAGLbeULsp/MAQiyjDEBibp/Gy0rg5h1Hm3TokJi12KfYSMizn973+rkMDjKiWW1ySq6Sif3BEqlHi1prbuFPYSQf7xiJgs3+P0aFXfPzDEBdqKNocAkjWPBbxrHCHq0DRJoXBgmrXA9BSmytymp/pdU4xt2Y/Gxb/GBBXOAorOumjZ46DxWwnqfVpJ9adHMj") + vs, _ = crypto.Base64Decode("FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhAj6bMuqJuU0GbmSbEk/VDjlu6RNp6OKmrhsRwXDQIiVtDCEDQI3NQWOW9keDrFh+oeFZPFfZ/qiAyKahkg6SollHeAYMIQKng0vpsy4pgdFXy1u9OstCz9EepcOxAiTXpE6YxZEPGwwhAroscPWZbzV6QxmHBYWfriz+oT4RcpYoAHcrPViKnUq9F0F7zmyl") + witness = tx2.Witness{ + InvocationScript: is, + VerificationScript: vs, } + neoHeader200 := &NeoBlockHeader{Header:new(block.Header)} + neoHeader200.SetVersion(0) + neoHeader200.SetPrevHash(prevHash) + neoHeader200.SetMerkleRoot(merkleRoot) + neoHeader200.SetTimeStamp(1616578903762) + neoHeader200.SetIndex(200) + neoHeader200.SetPrimaryIndex(0x00) + neoHeader200.SetNextConsensus(nextConsensus) + neoHeader200.SetWitnesses([]tx2.Witness{witness}) sink = common.NewZeroCopySink(nil) if err := neoHeader200.Serialization(sink); err != nil { t.Errorf("NeoBlockHeaderToBytes error:%v", err) @@ -228,5 +218,4 @@ func TestSyncBlockHeader(t *testing.T) { err := neoHandler.SyncBlockHeader(native) assert.NoError(t, err) } - } diff --git a/native/service/header_sync/neo/states.go b/native/service/header_sync/neo/states.go index 2370a1fc3..0d7947c43 100644 --- a/native/service/header_sync/neo/states.go +++ b/native/service/header_sync/neo/states.go @@ -18,26 +18,25 @@ package neo import ( - "encoding/hex" "fmt" - "github.com/joeqian10/neo-gogogo/block" - "github.com/joeqian10/neo-gogogo/crypto" - "github.com/joeqian10/neo-gogogo/helper" - "github.com/joeqian10/neo-gogogo/helper/io" - "github.com/joeqian10/neo-gogogo/mpt" + "github.com/joeqian10/neo3-gogogo/block" + "github.com/joeqian10/neo3-gogogo/crypto" + "github.com/joeqian10/neo3-gogogo/helper" + "github.com/joeqian10/neo3-gogogo/io" + "github.com/joeqian10/neo3-gogogo/mpt" "github.com/polynetwork/poly/common" ) type NeoConsensus struct { ChainID uint64 Height uint32 - NextConsensus helper.UInt160 + NextConsensus *helper.UInt160 } func (this *NeoConsensus) Serialization(sink *common.ZeroCopySink) { sink.WriteUint64(this.ChainID) sink.WriteUint32(this.Height) - sink.WriteVarBytes(this.NextConsensus.Bytes()) + sink.WriteVarBytes(this.NextConsensus.ToByteArray()) } func (this *NeoConsensus) Deserialization(source *common.ZeroCopySource) error { @@ -54,23 +53,20 @@ func (this *NeoConsensus) Deserialization(source *common.ZeroCopySource) error { return fmt.Errorf("NeoConsensus.Deserialization, NextConsensus NextVarBytes error") } - var err error - if this.NextConsensus, err = helper.UInt160FromBytes(nextConsensusBs); err != nil { - return fmt.Errorf("NeoConsensus.Deserialization, NextConsensus UInt160FromBytes error:%s", err) - } + this.NextConsensus = helper.UInt160FromBytes(nextConsensusBs); return nil } type NeoBlockHeader struct { - *block.BlockHeader + *block.Header } func (this *NeoBlockHeader) Deserialization(source *common.ZeroCopySource) error { - this.BlockHeader = new(block.BlockHeader) + this.Header = new(block.Header) br := io.NewBinaryReaderFromBuf(source.Bytes()) - this.BlockHeader.Deserialize(br) + this.Header.Deserialize(br) if br.Err != nil { - return fmt.Errorf("joeqian10/neo-gogogo/block.BlockHeader Deserialize error:%s", br.Err) + return fmt.Errorf("neo3-gogogo Header Deserialize error: %s", br.Err) } return nil } @@ -79,7 +75,7 @@ func (this *NeoBlockHeader) Serialization(sink *common.ZeroCopySink) error { bw := io.NewBufBinaryWriter() this.Serialize(bw.BinaryWriter) if bw.Err != nil { - return fmt.Errorf("joeqian10/neo-gogogo/block.BlockHeader Serialize error:%s", bw.Err) + return fmt.Errorf("neo3-gogogo Header Serialize error: %s", bw.Err) } sink.WriteBytes(bw.Bytes()) return nil @@ -89,7 +85,7 @@ func (this *NeoBlockHeader) GetMessage() ([]byte, error) { buf := io.NewBufBinaryWriter() this.SerializeUnsigned(buf.BinaryWriter) if buf.Err != nil { - return nil, fmt.Errorf("GetHashData of NeoBlockHeader joeqian10/neo-gogogo/block.BlockHeader SerializeUnsigned error:%s", buf.Err) + return nil, fmt.Errorf("neo3-gogogo Header SerializeUnsigned error: %s", buf.Err) } return buf.Bytes(), nil } @@ -103,7 +99,7 @@ func (this *NeoCrossChainMsg) Deserialization(source *common.ZeroCopySource) err br := io.NewBinaryReaderFromBuf(source.Bytes()) this.Deserialize(br) if br.Err != nil { - return fmt.Errorf("joeqian10/neo-gogogo/mpt.StateRoot Deserialize error:%s", br.Err) + return fmt.Errorf("neo3-gogogo mpt.StateRoot Deserialize error: %s", br.Err) } return nil } @@ -112,24 +108,21 @@ func (this *NeoCrossChainMsg) Serialization(sink *common.ZeroCopySink) error { bw := io.NewBufBinaryWriter() this.Serialize(bw.BinaryWriter) if bw.Err != nil { - return fmt.Errorf("joeqian10/neo-gogogo/mpt.StateRoot Serialize error:%s", bw.Err) + return fmt.Errorf("neo3-gogogo mpt.StateRoot Serialize error: %s", bw.Err) } sink.WriteBytes(bw.Bytes()) return nil } -func (this *NeoCrossChainMsg) GetScriptHash() (helper.UInt160, error) { - verificationScriptBs, err := hex.DecodeString(this.Witness.VerificationScript) +func (this *NeoCrossChainMsg) GetScriptHash() (*helper.UInt160, error) { + verificationScriptBs, err := crypto.Base64Decode(this.Witness.Verification) // base64 if err != nil { - return helper.UInt160{}, fmt.Errorf("NeoCrossChainMsg.Witness.VerificationScript decode to bytes error:%s", err) - } - if len(verificationScriptBs) == 0 { - return helper.UInt160{}, fmt.Errorf("NeoCrossChainMsg.Witness.VerificationScript length is 0 ") + return nil, fmt.Errorf("NeoCrossChainMsg.Witness.Verification decode error: %s", err) } - scriptHash, err := helper.UInt160FromBytes(crypto.Hash160(verificationScriptBs)) - if err != nil { - return helper.UInt160{}, fmt.Errorf("joeqian10/neo-gogogo/tx.Witness GetScriptHash error:%s", err) + if len(verificationScriptBs) != 20 { + return nil, fmt.Errorf("NeoCrossChainMsg.Witness.VerificationScript wrong length") } + scriptHash := helper.UInt160FromBytes(crypto.Hash160(verificationScriptBs)) return scriptHash, nil } @@ -137,7 +130,7 @@ func (this *NeoCrossChainMsg) GetMessage() ([]byte, error) { buf := io.NewBufBinaryWriter() this.SerializeUnsigned(buf.BinaryWriter) if buf.Err != nil { - return nil, fmt.Errorf("GetHashData of NeoBlockHeader joeqian10/neo-gogogo/mpt.StateRoot SerializeUnsigned error:%s", buf.Err) + return nil, fmt.Errorf("neo3-gogogo mpt.StateRoot SerializeUnsigned error: %s", buf.Err) } return buf.Bytes(), nil } diff --git a/native/service/header_sync/neo/states_test.go b/native/service/header_sync/neo/states_test.go index cb6321a45..1de6d0a8d 100644 --- a/native/service/header_sync/neo/states_test.go +++ b/native/service/header_sync/neo/states_test.go @@ -18,19 +18,19 @@ package neo import ( + "github.com/joeqian10/neo3-gogogo/crypto" + "github.com/joeqian10/neo3-gogogo/rpc/models" "testing" - "encoding/binary" - "github.com/joeqian10/neo-gogogo/block" - "github.com/joeqian10/neo-gogogo/helper" - "github.com/joeqian10/neo-gogogo/mpt" - tx2 "github.com/joeqian10/neo-gogogo/tx" + "github.com/joeqian10/neo3-gogogo/helper" + "github.com/joeqian10/neo3-gogogo/mpt" + tx2 "github.com/joeqian10/neo3-gogogo/tx" "github.com/polynetwork/poly/common" "github.com/stretchr/testify/assert" ) func Test_NeoConsensus_Serialization(t *testing.T) { - nextConsensus, _ := helper.UInt160FromString("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") + nextConsensus, _ := crypto.AddressToScriptHash("NYmMriQPYAiNxHC7tziV4ABJku5Yqe79N4", helper.DefaultAddressVersion) paramSerialize := &NeoConsensus{ ChainID: 4, Height: 100, @@ -46,30 +46,31 @@ func Test_NeoConsensus_Serialization(t *testing.T) { } func Test_NeoBlockHeader_Serialization(t *testing.T) { - paramSerialize := new(NeoBlockHeader) prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - merKleRoot, _ := helper.UInt256FromString("0x803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4") - nextConsensus, _ := helper.AddressToScriptHash("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") - consensusData := binary.BigEndian.Uint64(helper.HexToBytes("000000007c2bac1d")) - genesisHeader := &block.BlockHeader{ - Version: 0, - PrevHash: prevHash, - MerkleRoot: merKleRoot, - Timestamp: 1468595301, - Index: 0, - NextConsensus: nextConsensus, - ConsensusData: consensusData, - Witness: &tx2.Witness{ - InvocationScript: []byte{0}, - VerificationScript: []byte{81}, - }, + merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) + vs, _ := crypto.Base64Decode("EQ==") + witness := tx2.Witness{ + InvocationScript: []byte{}, + VerificationScript: vs, } - paramSerialize.BlockHeader = genesisHeader + genesisHeader := &NeoBlockHeader{} + genesisHeader.SetVersion(0) + genesisHeader.SetPrevHash(prevHash) + genesisHeader.SetMerkleRoot(merkleRoot) + genesisHeader.SetTimeStamp(1468595301000) + genesisHeader.SetIndex(0) + genesisHeader.SetPrimaryIndex(0x00) + genesisHeader.SetNextConsensus(nextConsensus) + genesisHeader.SetWitnesses([]tx2.Witness{witness}) + paramSerialize := new(NeoBlockHeader) + paramSerialize.Header = genesisHeader.Header sink := common.NewZeroCopySink(nil) - paramSerialize.Serialization(sink) + err := paramSerialize.Serialization(sink) + assert.Nil(t, err) paramDeserialize := new(NeoBlockHeader) - err := paramDeserialize.Deserialization(common.NewZeroCopySource(sink.Bytes())) + err = paramDeserialize.Deserialization(common.NewZeroCopySource(sink.Bytes())) assert.Nil(t, err) assert.Equal(t, paramDeserialize, paramSerialize) } @@ -77,25 +78,22 @@ func Test_NeoBlockHeader_Serialization(t *testing.T) { func Test_NeoCrossChainMsg_Serialization(t *testing.T) { paramSerialize := &NeoCrossChainMsg{ StateRoot: &mpt.StateRoot{ - Version: 1, - Index: 100, - PreHash: "803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4", - StateRoot: "803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4", - Witness: struct { - InvocationScript string `json:"invocation"` - VerificationScript string `json:"verification"` - }{ - InvocationScript: "40424db765bc1e92e530292ec04ff8ddffb79bec13f04fd9f85c00163328aa9d64f0b40b74ca8c4b56445c9048c50e6a67df57ab221593612c6165251d9770f7e140465f1d1d3b532fcaa8a98633316e24a07358c857a3565f7cc9a1b87dd3e6dcbb191a7c78c1b57889924e813a0daacea5281884ce814d10469560f43c9d567cf440fd7252d9607389e9b61c577a8705b1d74165979dd9440c4a71d47443fc1014e46957b0a537e1244fd9b4363aefb2df5971749daf9073cfd014aecb7dba2b13ab40c141f6c63267ad12ebadb154a83a3444eccff046de534cda6f29059e531de58bfce6287ca68a62b45766df5522dfed449b3d1bdc0a319ab07d21cf8839f5b59240fee381887b2dc82447fbe9e6db6c1aa9adff8f7a7d2998cea4f901c002098115d7ba7e6218275c8690f86b92e8b641d59152243f2253ff86fa9c2b6413a52256", - VerificationScript: "552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae", + Version: 0, + Index: 1000, + RootHash: "0x53360e02b03f548c6fc2f74f760d82a6749df6a844fd117ad7b62504390c8f8c", + Witness: models.RpcWitness { + Invocation: "DEBnIRHFS8tG/6pw4cqZQbOQZri6rboaQPUJTCVS2ZD/HwOZG2m9IG3NJ8E/gTV++o7G1r35l+p5aQcAbqwoP1wTDECeyQcx2M1DP/irLP7sQy/tNRyina2rdK6ATV/QY+Ib4tJ3sYpXaiPx4iGo+AgqUeTRDmD8anfUNtYzjYgos6x9DEDS+medyKx59813WgtCusxLIK0tx50H36tbMGmTUQxR5nHzrpG8nzQ8HKNKRNMgQNBoT4U3pcHMpwJY9bXUge4R", + Verification: "EwwhAnIujtkuXxpCUIyfti3TyTtoOhUd/wjLU4lwdHzBhsu6DCECkeyvwoMh29AA30IiQMankxndS3LESLsUGkLoTzfm/doMIQOyS9DtdzAVHs/Ne1yheExdO8NYTw1NkKyi1i4gd5tG1wwhA/sZ1ZOuaNWI9PnKa/3WYbE9xjnVVYWhVYYXFD38xLJWFEF7zmyl", }, }, } sink := common.NewZeroCopySink(nil) - paramSerialize.Serialization(sink) + err := paramSerialize.Serialization(sink) + assert.Nil(t, err) paramDeserialize := new(NeoCrossChainMsg) - err := paramDeserialize.Deserialization(common.NewZeroCopySource(sink.Bytes())) + err = paramDeserialize.Deserialization(common.NewZeroCopySource(sink.Bytes())) assert.Nil(t, err) assert.Equal(t, paramDeserialize, paramSerialize) } diff --git a/native/service/header_sync/neo/utils.go b/native/service/header_sync/neo/utils.go index 43be21294..1a03e4d22 100644 --- a/native/service/header_sync/neo/utils.go +++ b/native/service/header_sync/neo/utils.go @@ -20,7 +20,7 @@ package neo import ( "encoding/hex" "fmt" - "github.com/joeqian10/neo-gogogo/tx" + "github.com/joeqian10/neo3-gogogo/tx" "github.com/polynetwork/poly/common" cstates "github.com/polynetwork/poly/core/states" "github.com/polynetwork/poly/native" @@ -33,10 +33,10 @@ import ( func verifyHeader(native *native.NativeService, chainID uint64, header *NeoBlockHeader) error { neoConsensus, err := getConsensusValByChainId(native, chainID) if err != nil { - return fmt.Errorf("verifyHeader, get Consensus error:%s", err) + return fmt.Errorf("verifyHeader, get Consensus error: %s", err) } if neoConsensus.NextConsensus != header.Witness.GetScriptHash() { - return fmt.Errorf("verifyHeader, invalid script hash in header error, expected:%s, got:%s", neoConsensus.NextConsensus.String(), header.Witness.GetScriptHash().String()) + return fmt.Errorf("verifyHeader, invalid script hash in header error, expected: %s, got: %s", neoConsensus.NextConsensus.String(), header.Witness.GetScriptHash().String()) } msg, err := header.GetMessage() @@ -44,7 +44,7 @@ func verifyHeader(native *native.NativeService, chainID uint64, header *NeoBlock return fmt.Errorf("verifyHeader, unable to get hash data of header") } if verified := tx.VerifyMultiSignatureWitness(msg, header.Witness); !verified { - return fmt.Errorf("verifyHeader, VerifyMultiSignatureWitness error:%s, height:%d", err, header.Index) + return fmt.Errorf("verifyHeader, VerifyMultiSignatureWitness error: %s, height: %d", err, header.GetIndex()) } return nil } @@ -52,27 +52,27 @@ func verifyHeader(native *native.NativeService, chainID uint64, header *NeoBlock func VerifyCrossChainMsgSig(native *native.NativeService, chainID uint64, crossChainMsg *NeoCrossChainMsg) error { neoConsensus, err := getConsensusValByChainId(native, chainID) if err != nil { - return fmt.Errorf("verifyCrossChainMsg, get ConsensusPeer error:%v", err) + return fmt.Errorf("verifyCrossChainMsg, get ConsensusPeer error: %v", err) } crossChainMsgConsensus, err := crossChainMsg.GetScriptHash() if err != nil { - return fmt.Errorf("verifyCrossChainMsg, getScripthash error:%v", err) + return fmt.Errorf("verifyCrossChainMsg, getScripthash error: %v", err) } if neoConsensus.NextConsensus != crossChainMsgConsensus { - return fmt.Errorf("verifyCrossChainMsg, invalid script hash in NeoCrossChainMsg error, expected:%s, got:%s", neoConsensus.NextConsensus.String(), crossChainMsgConsensus.String()) + return fmt.Errorf("verifyCrossChainMsg, invalid script hash in NeoCrossChainMsg error, expected: %s, got: %s", neoConsensus.NextConsensus.String(), crossChainMsgConsensus.String()) } msg, err := crossChainMsg.GetMessage() if err != nil { return fmt.Errorf("verifyCrossChainMsg, unable to get unsigned message of neo crossChainMsg") } - invScript, _ := hex.DecodeString(crossChainMsg.Witness.InvocationScript) - verScript, _ := hex.DecodeString(crossChainMsg.Witness.VerificationScript) + invScript, _ := hex.DecodeString(crossChainMsg.Witness.Invocation) + verScript, _ := hex.DecodeString(crossChainMsg.Witness.Verification) witness := &tx.Witness{ InvocationScript: invScript, VerificationScript: verScript, } if verified := tx.VerifyMultiSignatureWitness(msg, witness); !verified { - return fmt.Errorf("verifyCrossChainMsg, VerifyMultiSignatureWitness error:%s, height:%d", "verified failed", crossChainMsg.Index) + return fmt.Errorf("verifyCrossChainMsg, VerifyMultiSignatureWitness error: %s, height: %d", "verification failed", crossChainMsg.Index) } return nil } @@ -89,7 +89,7 @@ func getConsensusValByChainId(native *native.NativeService, chainID uint64) (*Ne } neoConsensusBytes, err := cstates.GetValueFromRawStorageItem(neoConsensusStore) if err != nil { - return nil, fmt.Errorf("getConsensusPeerByHeight, deserialize from raw storage item err:%v", err) + return nil, fmt.Errorf("getConsensusPeerByHeight, deserialize from raw storage item err: %v", err) } neoConsensus := new(NeoConsensus) if err := neoConsensus.Deserialization(common.NewZeroCopySource(neoConsensusBytes)); err != nil { From 4cd36cb12ee6c74fac727708bfe7feed2173719b Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Fri, 16 Apr 2021 16:53:16 +0800 Subject: [PATCH 02/23] fix typo --- native/service/header_sync/neo/states.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/service/header_sync/neo/states.go b/native/service/header_sync/neo/states.go index 0d7947c43..05be7b5c6 100644 --- a/native/service/header_sync/neo/states.go +++ b/native/service/header_sync/neo/states.go @@ -119,8 +119,8 @@ func (this *NeoCrossChainMsg) GetScriptHash() (*helper.UInt160, error) { if err != nil { return nil, fmt.Errorf("NeoCrossChainMsg.Witness.Verification decode error: %s", err) } - if len(verificationScriptBs) != 20 { - return nil, fmt.Errorf("NeoCrossChainMsg.Witness.VerificationScript wrong length") + if len(verificationScriptBs) == 0 { + return nil, fmt.Errorf("NeoCrossChainMsg.Witness.VerificationScript is empty") } scriptHash := helper.UInt160FromBytes(crypto.Hash160(verificationScriptBs)) return scriptHash, nil From ca4d9ca07eefd2090a1baa26880349764d0d7582 Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Fri, 16 Apr 2021 18:30:10 +0800 Subject: [PATCH 03/23] add neo2 back --- go.mod | 1 + go.sum | 3 + .../service/cross_chain_manager/entrance.go | 5 +- .../cross_chain_manager/neo/neo_handler.go | 20 +- .../neo/neo_handler_test.go | 63 ++--- .../service/cross_chain_manager/neo/utils.go | 29 +-- .../cross_chain_manager/neo3/neo_handler.go | 80 +++++++ .../neo3/neo_handler_test.go | 177 ++++++++++++++ .../service/cross_chain_manager/neo3/utils.go | 59 +++++ native/service/header_sync/entrance.go | 5 +- native/service/header_sync/neo/header_sync.go | 10 +- .../header_sync/neo/header_sync_test.go | 168 ++++++------- native/service/header_sync/neo/states.go | 51 ++-- native/service/header_sync/neo/states_test.go | 62 ++--- native/service/header_sync/neo/utils.go | 8 +- .../service/header_sync/neo3/header_sync.go | 106 +++++++++ .../header_sync/neo3/header_sync_test.go | 221 ++++++++++++++++++ native/service/header_sync/neo3/states.go | 136 +++++++++++ .../service/header_sync/neo3/states_test.go | 99 ++++++++ native/service/header_sync/neo3/utils.go | 108 +++++++++ native/service/utils/params.go | 1 + 21 files changed, 1200 insertions(+), 212 deletions(-) create mode 100644 native/service/cross_chain_manager/neo3/neo_handler.go create mode 100644 native/service/cross_chain_manager/neo3/neo_handler_test.go create mode 100644 native/service/cross_chain_manager/neo3/utils.go create mode 100644 native/service/header_sync/neo3/header_sync.go create mode 100644 native/service/header_sync/neo3/header_sync_test.go create mode 100644 native/service/header_sync/neo3/states.go create mode 100644 native/service/header_sync/neo3/states_test.go create mode 100644 native/service/header_sync/neo3/utils.go diff --git a/go.mod b/go.mod index f5131e4bd..3a0ef9f8d 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/hashicorp/golang-lru v0.5.4 github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c github.com/itchyny/base58-go v0.1.0 + github.com/joeqian10/neo-gogogo v1.1.0 github.com/joeqian10/neo3-gogogo v0.2.4 github.com/ontio/ontology v1.11.0 github.com/ontio/ontology-crypto v1.0.9 diff --git a/go.sum b/go.sum index 276517451..64c97ecfd 100644 --- a/go.sum +++ b/go.sum @@ -306,6 +306,8 @@ github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43 h1:KkErIktuwCqqZYWV8iBbD7NEsgIbyGw6xxtuylqdyu0= github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43/go.mod h1:1fVDp4U1ROZQBRIooecbGNHHJpfs3bG9528sqlZ096g= +github.com/joeqian10/neo-gogogo v1.1.0 h1:TjqBwFQnNCtw6LK3QMog3yHa9sTZaZmqP+zqGOZ3SZ0= +github.com/joeqian10/neo-gogogo v1.1.0/go.mod h1:1fVDp4U1ROZQBRIooecbGNHHJpfs3bG9528sqlZ096g= github.com/joeqian10/neo3-gogogo v0.2.2 h1:SEZdGZqn44pIQeUTb/+mOWZj/JX+QNG+xaTRIzbfchk= github.com/joeqian10/neo3-gogogo v0.2.2/go.mod h1:yvYQyEha3An0uYFhzR9asMU/O9HyeYy6RApRnLGPEtM= github.com/joeqian10/neo3-gogogo v0.2.3 h1:Ucg28066O2Q/G7jGFMWuyiAxhzWWv9+A2RDEWitbkjQ= @@ -510,6 +512,7 @@ github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3 github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/native/service/cross_chain_manager/entrance.go b/native/service/cross_chain_manager/entrance.go index ac62b9c58..74632490e 100644 --- a/native/service/cross_chain_manager/entrance.go +++ b/native/service/cross_chain_manager/entrance.go @@ -19,6 +19,8 @@ package cross_chain_manager import ( "encoding/hex" "fmt" + "github.com/polynetwork/poly/native/service/cross_chain_manager/neo" + "github.com/polynetwork/poly/native/service/cross_chain_manager/neo3" "github.com/polynetwork/poly/common" "github.com/polynetwork/poly/native" @@ -29,7 +31,6 @@ import ( "github.com/polynetwork/poly/native/service/cross_chain_manager/eth" "github.com/polynetwork/poly/native/service/cross_chain_manager/heco" "github.com/polynetwork/poly/native/service/cross_chain_manager/msc" - "github.com/polynetwork/poly/native/service/cross_chain_manager/neo" "github.com/polynetwork/poly/native/service/cross_chain_manager/ont" "github.com/polynetwork/poly/native/service/cross_chain_manager/quorum" "github.com/polynetwork/poly/native/service/cross_chain_manager/zilliqa" @@ -65,6 +66,8 @@ func GetChainHandler(router uint64) (scom.ChainHandler, error) { return ont.NewONTHandler(), nil case utils.NEO_ROUTER: return neo.NewNEOHandler(), nil + case utils.NEO3_ROUTER: + return neo3.NewNEOHandler(), nil case utils.COSMOS_ROUTER: return cosmos.NewCosmosHandler(), nil case utils.QUORUM_ROUTER: diff --git a/native/service/cross_chain_manager/neo/neo_handler.go b/native/service/cross_chain_manager/neo/neo_handler.go index 8a996d346..56b3b9fa6 100644 --- a/native/service/cross_chain_manager/neo/neo_handler.go +++ b/native/service/cross_chain_manager/neo/neo_handler.go @@ -19,7 +19,6 @@ package neo import ( "fmt" - "github.com/joeqian10/neo3-gogogo/helper" "github.com/polynetwork/poly/common" "github.com/polynetwork/poly/native" scom "github.com/polynetwork/poly/native/service/cross_chain_manager/common" @@ -28,7 +27,6 @@ import ( ) type NEOHandler struct { - ccmcId *int } func NewNEOHandler() *NEOHandler { @@ -53,28 +51,16 @@ func (this *NEOHandler) MakeDepositProposal(service *native.NativeService) (*sco if err != nil { return nil, fmt.Errorf("neo MakeDepositProposal, side_chain_manager.GetSideChain error: %v", err) } - - // convert neo contract address bytes to id, it is different from other chains, it stores int in a []byte, contract id can be get from "getcontractstate" api - // todo, when register neo N3, convert ccmc id to []byte; native contracts have negative ids, while custom contracts have positive ones - if this.ccmcId == nil { - this.SetCcmcId(sideChain.CCMCAddress) - } - - value, err := verifyFromNeoTx(params.Proof, crossChainMsg, *this.ccmcId) + value, err := verifyFromNeoTx(params.Proof, crossChainMsg, sideChain.CCMCAddress) if err != nil { return nil, fmt.Errorf("neo MakeDepositProposal, VerifyFromNeoTx error: %v", err) } // Ensure the tx has not been processed before, and mark the tx as processed if err := scom.CheckDoneTx(service, value.CrossChainID, params.SourceChainID); err != nil { - return nil, fmt.Errorf("neo MakeDepositProposal, check done transaction error:%s", err) + return nil, fmt.Errorf("neo MakeDepositProposal, check done transaction error: %s", err) } if err = scom.PutDoneTx(service, value.CrossChainID, params.SourceChainID); err != nil { - return nil, fmt.Errorf("neo MakeDepositProposal, putDoneTx error:%s", err) + return nil, fmt.Errorf("neo MakeDepositProposal, putDoneTx error: %s", err) } return value, nil } - -func (this *NEOHandler) SetCcmcId(idBytes []byte) { - id := int(int32(helper.BytesToUInt32(idBytes))) - this.ccmcId = &id -} diff --git a/native/service/cross_chain_manager/neo/neo_handler_test.go b/native/service/cross_chain_manager/neo/neo_handler_test.go index b236147ed..e04607d24 100644 --- a/native/service/cross_chain_manager/neo/neo_handler_test.go +++ b/native/service/cross_chain_manager/neo/neo_handler_test.go @@ -18,10 +18,11 @@ package neo import ( + "encoding/binary" "encoding/hex" - "github.com/joeqian10/neo3-gogogo/crypto" - "github.com/joeqian10/neo3-gogogo/helper" - tx2 "github.com/joeqian10/neo3-gogogo/tx" + "github.com/joeqian10/neo-gogogo/block" + "github.com/joeqian10/neo-gogogo/helper" + tx2 "github.com/joeqian10/neo-gogogo/tx" "github.com/ontio/ontology-crypto/keypair" "github.com/polynetwork/poly/account" "github.com/polynetwork/poly/common" @@ -39,7 +40,6 @@ import ( "github.com/polynetwork/poly/native/service/utils" "github.com/polynetwork/poly/native/storage" "github.com/stretchr/testify/assert" - "log" "testing" ) @@ -88,32 +88,31 @@ func Test_Neo_MakeDepositProposal(t *testing.T) { var native *native.NativeService { prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) - vs, _ := crypto.Base64Decode("EQ==") - witness := tx2.Witness{ - InvocationScript: []byte{}, - VerificationScript: vs, + merKleRoot, _ := helper.UInt256FromString("0xee3ba4cd680d1acd06b067a7d57fd20e47f79203a23e99f28915e57b4e6c1058") + nextConsensus, _ := helper.AddressToScriptHash("AdP4zfgVEgn8nhRN5s76aVNEcDaftkqbyW") + consensusData := binary.BigEndian.Uint64(helper.HexToBytes("000000007c2bac1d")) + genesisHeader := &neo.NeoBlockHeader{ + &block.BlockHeader{ + Version: 0, + PrevHash: prevHash, + MerkleRoot: merKleRoot, + Timestamp: 1468595301, + Index: 0, + NextConsensus: nextConsensus, + ConsensusData: consensusData, + Witness: &tx2.Witness{ + InvocationScript: []byte{0}, + VerificationScript: []byte{81}, + }, + }, } - genesisHeader := &neo.NeoBlockHeader{} - genesisHeader.SetVersion(0) - genesisHeader.SetPrevHash(prevHash) - genesisHeader.SetMerkleRoot(merkleRoot) - genesisHeader.SetTimeStamp(1468595301000) - genesisHeader.SetIndex(0) - genesisHeader.SetPrimaryIndex(0x00) - genesisHeader.SetNextConsensus(nextConsensus) - genesisHeader.SetWitnesses([]tx2.Witness{witness}) - param := new(hscom.SyncGenesisHeaderParam) param.ChainID = 4 var err error sink := common.NewZeroCopySink(nil) err = genesisHeader.Serialization(sink) param.GenesisHeader = sink.Bytes() - if err != nil { - t.Errorf("NeoBlockHeaderToBytes error:%v", err) - } + assert.Nil(t, err) sink = common.NewZeroCopySink(nil) param.Serialization(sink) @@ -158,21 +157,3 @@ func Test_Neo_MakeDepositProposal(t *testing.T) { assert.Nil(t, err) } } - -func TestNEOHandler_SetCcmcId(t *testing.T) { - // test positive int - idp := 5 - idpBytes := helper.IntToBytes(idp) - log.Println(helper.BytesToHex(idpBytes)) - - idp2 := int(helper.BytesToUInt32(idpBytes)) - assert.Equal(t, idp, idp2) - - // test negative int - idn := -5 - idnBytes := helper.IntToBytes(idn) - log.Println(helper.BytesToHex(idnBytes)) - - idn2 := int(int32(helper.BytesToUInt32(idnBytes))) - assert.Equal(t, idn, idn2) -} diff --git a/native/service/cross_chain_manager/neo/utils.go b/native/service/cross_chain_manager/neo/utils.go index 7f1cf38fd..3988fc5a3 100644 --- a/native/service/cross_chain_manager/neo/utils.go +++ b/native/service/cross_chain_manager/neo/utils.go @@ -17,20 +17,22 @@ package neo import ( + "bytes" + "encoding/hex" "fmt" - "github.com/joeqian10/neo3-gogogo/helper" - "github.com/joeqian10/neo3-gogogo/mpt" + "github.com/joeqian10/neo-gogogo/helper" + "github.com/joeqian10/neo-gogogo/mpt" "github.com/polynetwork/poly/common" scom "github.com/polynetwork/poly/native/service/cross_chain_manager/common" "github.com/polynetwork/poly/native/service/header_sync/neo" ) -func verifyFromNeoTx(proof []byte, crossChainMsg *neo.NeoCrossChainMsg, contractId int) (*scom.MakeTxParam, error) { - crossStateProofRoot, err := helper.UInt256FromString(crossChainMsg.StateRoot.RootHash) +func verifyFromNeoTx(proof []byte, crosschainMsg *neo.NeoCrossChainMsg, contractAddr []byte) (*scom.MakeTxParam, error) { + crossStateProofRoot, err := helper.UInt256FromString(crosschainMsg.StateRoot.StateRoot) if err != nil { return nil, fmt.Errorf("verifyFromNeoTx, decode cross state proof root from string error: %s", err) } - value, err := VerifyNeoCrossChainProof(proof, crossStateProofRoot.ToByteArray(), contractId) + value, err := VerifyNeoCrossChainProof(proof, crossStateProofRoot.Bytes(), contractAddr) if err != nil { return nil, fmt.Errorf("VerifyFromNeoTx, Verify Neo cross chain proof error: %v", err) } @@ -42,18 +44,19 @@ func verifyFromNeoTx(proof []byte, crossChainMsg *neo.NeoCrossChainMsg, contract return txParam, nil } -func VerifyNeoCrossChainProof(proof []byte, stateRoot []byte, contractId int) ([]byte, error) { - id, key, proofs, err := mpt.ResolveProof(proof) +func VerifyNeoCrossChainProof(proof []byte, stateRoot []byte, contractAddr []byte) ([]byte, error) { + scriptHash, key, proofs, err := mpt.ResolveProof(proof) if err != nil { - return nil, fmt.Errorf("VerifyNeoCrossChainProof, neo3-gogogo mpt.ResolveProof error: %v", err) + return nil, fmt.Errorf("VerifyNeoCrossChainProof, neo-gogogo mpt.ResolveProof error: %v", err) } - if id != contractId { - return nil, fmt.Errorf("VerifyNeoCrossChainProof, error: id is not CCMC contract id, expected: %d, but got %d", contractId, id) + if !bytes.Equal(scriptHash.Bytes(), contractAddr) { + return nil, fmt.Errorf("VerifyNeoCrossChainProof, error:scriptHash is not CCMC contract address, expected: %s, but got: %s", hex.EncodeToString(common.ToArrayReverse(contractAddr)), scriptHash.String()) } - root := helper.UInt256FromBytes(stateRoot) - value, err := mpt.VerifyProof(root, contractId, key, proofs) + value, err := mpt.VerifyProof(stateRoot, scriptHash, key, proofs) if err != nil { - return nil, fmt.Errorf("VerifyNeoCrossChainProof, neo3-gogogo mpt.VerifyProof error: %v", err) + return nil, fmt.Errorf("VerifyNeoCrossChainProof, neo-gogogo mpt.VerifyProof error: %v", err) } + return value, nil + } diff --git a/native/service/cross_chain_manager/neo3/neo_handler.go b/native/service/cross_chain_manager/neo3/neo_handler.go new file mode 100644 index 000000000..878dbc935 --- /dev/null +++ b/native/service/cross_chain_manager/neo3/neo_handler.go @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2020 The poly network Authors + * This file is part of The poly network library. + * + * The poly network is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The poly network is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The poly network . If not, see . + */ + +package neo3 + +import ( + "fmt" + "github.com/joeqian10/neo3-gogogo/helper" + "github.com/polynetwork/poly/common" + "github.com/polynetwork/poly/native" + scom "github.com/polynetwork/poly/native/service/cross_chain_manager/common" + "github.com/polynetwork/poly/native/service/governance/side_chain_manager" + "github.com/polynetwork/poly/native/service/header_sync/neo3" +) + +type NEOHandler struct { + ccmcId *int +} + +func NewNEOHandler() *NEOHandler { + return &NEOHandler{} +} + +func (this *NEOHandler) MakeDepositProposal(service *native.NativeService) (*scom.MakeTxParam, error) { + params := new(scom.EntranceParam) + if err := params.Deserialization(common.NewZeroCopySource(service.GetInput())); err != nil { + return nil, fmt.Errorf("neo3 MakeDepositProposal, contract params deserialize error: %v", err) + } + // Deserialize neo cross chain msg and verify its signature + crossChainMsg := new(neo3.NeoCrossChainMsg) + if err := crossChainMsg.Deserialization(common.NewZeroCopySource(params.HeaderOrCrossChainMsg)); err != nil { + return nil, fmt.Errorf("neo3 MakeDepositProposal, deserialize crossChainMsg error: %v", err) + } + if err := neo3.VerifyCrossChainMsgSig(service, params.SourceChainID, crossChainMsg); err != nil { + return nil, fmt.Errorf("neo3 MakeDepositProposal, VerifyCrossChainMsg error: %v", err) + } + // Verify the validity of proof with the help of state root in verified neo cross chain msg + sideChain, err := side_chain_manager.GetSideChain(service, params.SourceChainID) + if err != nil { + return nil, fmt.Errorf("neo3 MakeDepositProposal, side_chain_manager.GetSideChain error: %v", err) + } + + // convert neo contract address bytes to id, it is different from other chains, it stores int in a []byte, contract id can be get from "getcontractstate" api + // todo, when register neo N3, convert ccmc id to []byte; native contracts have negative ids, while custom contracts have positive ones + if this.ccmcId == nil { + this.SetCcmcId(sideChain.CCMCAddress) + } + + value, err := verifyFromNeoTx(params.Proof, crossChainMsg, *this.ccmcId) + if err != nil { + return nil, fmt.Errorf("neo3 MakeDepositProposal, VerifyFromNeoTx error: %v", err) + } + // Ensure the tx has not been processed before, and mark the tx as processed + if err := scom.CheckDoneTx(service, value.CrossChainID, params.SourceChainID); err != nil { + return nil, fmt.Errorf("neo3 MakeDepositProposal, check done transaction error:%s", err) + } + if err = scom.PutDoneTx(service, value.CrossChainID, params.SourceChainID); err != nil { + return nil, fmt.Errorf("neo3 MakeDepositProposal, putDoneTx error:%s", err) + } + return value, nil +} + +func (this *NEOHandler) SetCcmcId(idBytes []byte) { + id := int(int32(helper.BytesToUInt32(idBytes))) + this.ccmcId = &id +} diff --git a/native/service/cross_chain_manager/neo3/neo_handler_test.go b/native/service/cross_chain_manager/neo3/neo_handler_test.go new file mode 100644 index 000000000..053f38c99 --- /dev/null +++ b/native/service/cross_chain_manager/neo3/neo_handler_test.go @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2020 The poly network Authors + * This file is part of The poly network library. + * + * The poly network is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The poly network is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The poly network . If not, see . + */ + +package neo3 + +import ( + "encoding/hex" + "github.com/joeqian10/neo3-gogogo/crypto" + "github.com/joeqian10/neo3-gogogo/helper" + tx2 "github.com/joeqian10/neo3-gogogo/tx" + "github.com/ontio/ontology-crypto/keypair" + "github.com/polynetwork/poly/account" + "github.com/polynetwork/poly/common" + "github.com/polynetwork/poly/core/genesis" + cstates "github.com/polynetwork/poly/core/states" + "github.com/polynetwork/poly/core/store/leveldbstore" + "github.com/polynetwork/poly/core/store/overlaydb" + "github.com/polynetwork/poly/core/types" + "github.com/polynetwork/poly/native" + scom "github.com/polynetwork/poly/native/service/cross_chain_manager/common" + "github.com/polynetwork/poly/native/service/governance/side_chain_manager" + hscom "github.com/polynetwork/poly/native/service/header_sync/common" + "github.com/polynetwork/poly/native/service/header_sync/neo3" + "github.com/polynetwork/poly/native/service/utils" + "github.com/polynetwork/poly/native/storage" + "github.com/stretchr/testify/assert" + "log" + "testing" +) + +var ( + acct *account.Account = account.NewAccount("") + getNativeFunc = func() *native.NativeService { + store, _ := leveldbstore.NewMemLevelDBStore() + cacheDB := storage.NewCacheDB(overlaydb.NewOverlayDB(store)) + service, _ := native.NewNativeService(cacheDB, new(types.Transaction), 0, 200, common.Uint256{}, 0, nil, false) + return service + } + getNeoHanderFunc = func() *NEOHandler { + return NewNEOHandler() + } + setBKers = func() { + genesis.GenesisBookkeepers = []keypair.PublicKey{acct.PublicKey} + } +) + +func init() { + setBKers() +} +func NewNative(args []byte, tx *types.Transaction, db *storage.CacheDB) *native.NativeService { + if db == nil { + store, _ := leveldbstore.NewMemLevelDBStore() + db = storage.NewCacheDB(overlaydb.NewOverlayDB(store)) + } + ns, _ := native.NewNativeService(db, tx, 0, 0, common.Uint256{0}, 0, args, false) + return ns +} +func SetContract(ns *native.NativeService, contractAddr string) { + contaractAddr, _ := hex.DecodeString(contractAddr) + side := &side_chain_manager.SideChain{ + Name: "neo", + ChainId: 4, + BlocksToWait: 1, + Router: 4, + CCMCAddress: contaractAddr, + } + sink := common.NewZeroCopySink(nil) + _ = side.Serialization(sink) + ns.GetCacheDB().Put(utils.ConcatKey(utils.SideChainManagerContractAddress, []byte(side_chain_manager.SIDE_CHAIN), utils.GetUint64Bytes(side.ChainId)), cstates.GenRawStorageItem(sink.Bytes())) +} + +func Test_Neo_MakeDepositProposal(t *testing.T) { + var native *native.NativeService + { + prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) + vs, _ := crypto.Base64Decode("EQ==") + witness := tx2.Witness{ + InvocationScript: []byte{}, + VerificationScript: vs, + } + genesisHeader := &neo3.NeoBlockHeader{} + genesisHeader.SetVersion(0) + genesisHeader.SetPrevHash(prevHash) + genesisHeader.SetMerkleRoot(merkleRoot) + genesisHeader.SetTimeStamp(1468595301000) + genesisHeader.SetIndex(0) + genesisHeader.SetPrimaryIndex(0x00) + genesisHeader.SetNextConsensus(nextConsensus) + genesisHeader.SetWitnesses([]tx2.Witness{witness}) + + param := new(hscom.SyncGenesisHeaderParam) + param.ChainID = 4 + var err error + sink := common.NewZeroCopySink(nil) + err = genesisHeader.Serialization(sink) + param.GenesisHeader = sink.Bytes() + if err != nil { + t.Errorf("NeoBlockHeaderToBytes error:%v", err) + } + + sink = common.NewZeroCopySink(nil) + param.Serialization(sink) + + tx := &types.Transaction{ + SignedAddr: []common.Address{acct.Address}, + } + + native = NewNative(sink.Bytes(), tx, nil) + neoHandler := neo3.NewNEOHandler() + err = neoHandler.SyncGenesisHeader(native) + assert.NoError(t, err) + } + + { + neoCrossChainMsgBs, _ := hex.DecodeString("004b0a01000f2adbe1d4c5022f34f7c4d1e5f033ea68102e716d66d70cdd194ae6dd7ed1b415f4c0ae08b37c51bd71a78b6aa5e79408f920a3b7b93e38d781985444b93b2b01c34059d48e180101adff905300e5e2074bfd12dee1d72e6a767cc00b384633fe64bfa2119811685c5062fc2ac947da15c08953dd603be791c41666f4ae759cb9ca8440b7201eb7d39052b22826a5445f4d7da896d337ffbec6dad0c08e413d5f1ec3f79caba079d77da11bc6ed800bccb9f689f34b4e85d7b4bb0dee14cbda75c5fedc40b7a409837de5e709f7e0b3e9f730f2475f6ddd8ba61d95849f16c97a78e9980879a740d8ab98bc012619b57170496fb7c6c515ae1d58eed50e9854667028acaf8b5321030f59a5482a4e42a2e5a848608dac4e84a698e567e2860e0ca5f23fc9e818d37c21032e78261370d4d62cf4c13584ca90f46c5565117b5b97544312f2e7b7c36b9eba21026e271722c21c482f0ac74dd932e61cdc2a2dd889633a2c5d8ecef43f2769f51e2103d55bfbcd493d06ab49c09cde0cea5d9ba890d81331a2fcd6f68d329932d0398f54ae") + proofBs, _ := hex.DecodeString("25b0d4f20da68a6007d4fb7eac374b5566a5b0e229010202040000000000000000000000000c0bfd12010020f1bd34e03cf87844472bd97a245f6b4647f3da831101e8d35887b128447610cd0000205bb1e7f44a1a49702f37ec5b3c3ef254d9a55e84e30e91292e40b1a77b587c3520136df7bf0b604a15046281d14ff737f289fee06dcc21d2f5ebc3c879fe0b8f8100207f4fa0a7ca13b5712eae6df66b34c837134b1b3c206e35c8b08f58fd60eb95d9207dc275d32b07c66e4a7a85ca95812fe2bea2bc54205304db207789be9cdd9b440020ce58021310ac771901181d08fe4ea849214f5f8e8838325f88193589d06b5a6300209fc6b8cf16051f2cb0f16797064f3766ab90a0c7afe00a5ed205165a8ceb44da000020b235652da7f7892fd833b3f09656f3e74de8783896f85aa25a6315542d214d3700004a0127000d040f02000d0a06080a060000070d040f0b070e0a0c0307040b050506060a050b000e020209206fbaa1762862f38fcd56430a143632403b149491372122aed7a76252965008f85200206768e94d8cf974b35d8b20f36d4fd96a2a9ebdcb256c6cbccd67c741d8f3680500000020b532982b4fa5b52549439b9d6ab21dcdf1bdd08148573ce2cd8dbcfdc0647cd800000000000000000000000023010020584d7456e1a12be332ebe31e69970dfa18fa2bb7657c392fc63a44e01ed7f0dd92000020811d835143c81eb6d89295d33376ad7f2051fe9c12e97609373ab40983e3509d2075766bf9049fd5e20d14ffed1647f318518c125203de2dfc6473a03952cfc3e22068ea98f2f5f7d6e2c602885e57888adadd3e08e6c05043de7f1075fbfeb07f8f20c744e54af45aff995db84a5de396d73b916beed7cb54dcfadbde06e3845ada250000000000000000000000002401010020eff43eb246bba849c55908a9eca858194e43e89191555331dc2b6924621224875200002064022d7bf83e18daa3f0c521d74a430d4e9fca91edf56c484f249590378570bc20749a992c424e0da9d810b9954787b060190d631a83712f50134ac45bae43891f0000000000000000000000000000260103000200200d0c0166a089785a1f5dee523d1db836b6d30b6c226c5bd1e00493040e3b244b920000206f8cd767796594997c184b946d11a0305dc70c43bdc4ec142ec45ed1c10fd0b620409e5d22bbb60d53fb8043f823478024e7ebc89d635cd32efe27f0c301ea457e20cdf35a6da5556e432caba8db1559441a4ce2e79869340a964fda9637babf94d8209f4169310ee7c01aeacc88d3310f65cd2521d69da42a03c0ba56e1fe455e5cea0000000000000000000000003d011a000000000000000000000000000000000000000000000000000c201714f5861026fc3968ef442517da5bc15744770e2a48d55271ef40ed62aebbb1cb03c900c620dcb71d056f3cf1063bd47cd5466a0d0f480493bb963a1729f5b6119bbb2fb1002064084b8f53a425764bffd9c8d42ccef4550a6f298e92a57b339d9cbb37190751146591ea90e4cc4490f8bdd1a714f5f5d36a23711e020000000000000014a4260d6f81c436b8cbc99673eaf81e632c4e9d7d06756e6c6f636b4a14f8e41a74d1a9053acfc052df3686370452bb83c5140b24abdd39185055311aaa27082f9deb294a7255100000000000000000000000000000000000000000000000000000000000000000") + param := &scom.EntranceParam{ + SourceChainID: 4, + Height: 7006, + Proof: proofBs, + RelayerAddress: acct.Address[:], + Extra: []byte{}, + HeaderOrCrossChainMsg: neoCrossChainMsgBs, + } + + var err error + sink := common.NewZeroCopySink(nil) + param.Serialization(sink) + + sink = common.NewZeroCopySink(nil) + param.Serialization(sink) + + tx := &types.Transaction{ + SignedAddr: []common.Address{acct.Address}, + } + + native = NewNative(sink.Bytes(), tx, native.GetCacheDB()) + neoHandler := NewNEOHandler() + SetContract(native, "b0d4f20da68a6007d4fb7eac374b5566a5b0e229") + _, err = neoHandler.MakeDepositProposal(native) + assert.Nil(t, err) + } +} + +func TestNEOHandler_SetCcmcId(t *testing.T) { + // test positive int + idp := 5 + idpBytes := helper.IntToBytes(idp) + log.Println(helper.BytesToHex(idpBytes)) + + idp2 := int(helper.BytesToUInt32(idpBytes)) + assert.Equal(t, idp, idp2) + + // test negative int + idn := -5 + idnBytes := helper.IntToBytes(idn) + log.Println(helper.BytesToHex(idnBytes)) + + idn2 := int(int32(helper.BytesToUInt32(idnBytes))) + assert.Equal(t, idn, idn2) +} diff --git a/native/service/cross_chain_manager/neo3/utils.go b/native/service/cross_chain_manager/neo3/utils.go new file mode 100644 index 000000000..71c489966 --- /dev/null +++ b/native/service/cross_chain_manager/neo3/utils.go @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2020 The poly network Authors + * This file is part of The poly network library. + * + * The poly network is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The poly network is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The poly network . If not, see . + */ +package neo3 + +import ( + "fmt" + "github.com/joeqian10/neo3-gogogo/helper" + "github.com/joeqian10/neo3-gogogo/mpt" + "github.com/polynetwork/poly/common" + scom "github.com/polynetwork/poly/native/service/cross_chain_manager/common" + "github.com/polynetwork/poly/native/service/header_sync/neo3" +) + +func verifyFromNeoTx(proof []byte, crossChainMsg *neo3.NeoCrossChainMsg, contractId int) (*scom.MakeTxParam, error) { + crossStateProofRoot, err := helper.UInt256FromString(crossChainMsg.StateRoot.RootHash) + if err != nil { + return nil, fmt.Errorf("verifyFromNeoTx, decode cross state proof root from string error: %s", err) + } + value, err := VerifyNeoCrossChainProof(proof, crossStateProofRoot.ToByteArray(), contractId) + if err != nil { + return nil, fmt.Errorf("VerifyFromNeoTx, Verify Neo cross chain proof error: %v", err) + } + source := common.NewZeroCopySource(value) + txParam := new(scom.MakeTxParam) + if err := txParam.Deserialization(source); err != nil { + return nil, fmt.Errorf("VerifyFromNeoTx, deserialize merkleValue error: %s", err) + } + return txParam, nil +} + +func VerifyNeoCrossChainProof(proof []byte, stateRoot []byte, contractId int) ([]byte, error) { + id, key, proofs, err := mpt.ResolveProof(proof) + if err != nil { + return nil, fmt.Errorf("VerifyNeoCrossChainProof, neo3-gogogo mpt.ResolveProof error: %v", err) + } + if id != contractId { + return nil, fmt.Errorf("VerifyNeoCrossChainProof, error: id is not CCMC contract id, expected: %d, but got: %d", contractId, id) + } + root := helper.UInt256FromBytes(stateRoot) + value, err := mpt.VerifyProof(root, contractId, key, proofs) + if err != nil { + return nil, fmt.Errorf("VerifyNeoCrossChainProof, neo3-gogogo mpt.VerifyProof error: %v", err) + } + return value, nil +} diff --git a/native/service/header_sync/entrance.go b/native/service/header_sync/entrance.go index fbd0e405e..a4ee39868 100644 --- a/native/service/header_sync/entrance.go +++ b/native/service/header_sync/entrance.go @@ -19,6 +19,8 @@ package header_sync import ( "fmt" + "github.com/polynetwork/poly/native/service/header_sync/neo" + "github.com/polynetwork/poly/native/service/header_sync/neo3" "github.com/polynetwork/poly/native/service/header_sync/heco" "github.com/polynetwork/poly/native/service/header_sync/msc" @@ -31,7 +33,6 @@ import ( hscommon "github.com/polynetwork/poly/native/service/header_sync/common" "github.com/polynetwork/poly/native/service/header_sync/cosmos" "github.com/polynetwork/poly/native/service/header_sync/eth" - "github.com/polynetwork/poly/native/service/header_sync/neo" "github.com/polynetwork/poly/native/service/header_sync/ont" "github.com/polynetwork/poly/native/service/header_sync/quorum" "github.com/polynetwork/poly/native/service/header_sync/zilliqa" @@ -61,6 +62,8 @@ func GetChainHandler(router uint64) (hscommon.HeaderSyncHandler, error) { return ont.NewONTHandler(), nil case utils.NEO_ROUTER: return neo.NewNEOHandler(), nil + case utils.NEO3_ROUTER: + return neo3.NewNEOHandler(), nil case utils.COSMOS_ROUTER: return cosmos.NewCosmosHandler(), nil case utils.QUORUM_ROUTER: diff --git a/native/service/header_sync/neo/header_sync.go b/native/service/header_sync/neo/header_sync.go index d3d2fd74a..c6b9acabf 100644 --- a/native/service/header_sync/neo/header_sync.go +++ b/native/service/header_sync/neo/header_sync.go @@ -58,8 +58,8 @@ func (this *NEOHandler) SyncGenesisHeader(native *native.NativeService) error { // Put NeoConsensus.NextConsensus into storage if err = putConsensusValByChainId(native, &NeoConsensus{ ChainID: params.ChainID, - Height: header.GetIndex(), - NextConsensus: header.GetNextConsensus(), + Height: header.Index, + NextConsensus: header.NextConsensus, }); err != nil { return fmt.Errorf("NeoHandler SyncGenesisHeader, update ConsensusPeer error: %v", err) } @@ -82,14 +82,14 @@ func (this *NEOHandler) SyncBlockHeader(native *native.NativeService) error { if err := header.Deserialization(common.NewZeroCopySource(v)); err != nil { return fmt.Errorf("SyncBlockHeader, NeoBlockHeaderFromBytes error: %v", err) } - if !header.GetNextConsensus().Equals(neoConsensus.NextConsensus) && header.GetIndex() > neoConsensus.Height { + if !header.NextConsensus.Equals(neoConsensus.NextConsensus) && header.Index > neoConsensus.Height { if err = verifyHeader(native, params.ChainID, header); err != nil { return fmt.Errorf("SyncBlockHeader, verifyHeader error: %v", err) } newNeoConsensus = &NeoConsensus{ ChainID: neoConsensus.ChainID, - Height: header.GetIndex(), - NextConsensus: header.GetNextConsensus(), + Height: header.Index, + NextConsensus: header.NextConsensus, } } } diff --git a/native/service/header_sync/neo/header_sync_test.go b/native/service/header_sync/neo/header_sync_test.go index 3939755af..6ef011366 100644 --- a/native/service/header_sync/neo/header_sync_test.go +++ b/native/service/header_sync/neo/header_sync_test.go @@ -18,10 +18,14 @@ package neo import ( - "github.com/joeqian10/neo3-gogogo/block" - "github.com/joeqian10/neo3-gogogo/crypto" - "github.com/joeqian10/neo3-gogogo/helper" - tx2 "github.com/joeqian10/neo3-gogogo/tx" + "encoding/hex" + "testing" + + "encoding/binary" + "github.com/joeqian10/neo-gogogo/block" + "github.com/joeqian10/neo-gogogo/helper" + tx2 "github.com/joeqian10/neo-gogogo/tx" + "github.com/joeqian10/neo-gogogo/wallet" "github.com/ontio/ontology-crypto/keypair" "github.com/polynetwork/poly/account" "github.com/polynetwork/poly/common" @@ -33,14 +37,13 @@ import ( scom "github.com/polynetwork/poly/native/service/header_sync/common" "github.com/polynetwork/poly/native/storage" "github.com/stretchr/testify/assert" - "testing" ) var ( - //neoAcct = func() *wallet.Account { - // acct, _ := wallet.NewAccount() - // return acct - //}() + neoAcct = func() *wallet.Account { + acct, _ := wallet.NewAccount() + return acct + }() acct *account.Account = account.NewAccount("") getNativeFunc = func() *native.NativeService { store, _ := leveldbstore.NewMemLevelDBStore() @@ -71,23 +74,24 @@ func NewNative(args []byte, tx *types.Transaction, db *storage.CacheDB) *native. func TestSyncGenesisHeader(t *testing.T) { prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) - vs, _ := crypto.Base64Decode("EQ==") - witness := tx2.Witness{ - InvocationScript: []byte{}, - VerificationScript: vs, + merKleRoot, _ := helper.UInt256FromString("0x803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4") + nextConsensus, _ := helper.AddressToScriptHash("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") + consensusData := binary.BigEndian.Uint64(helper.HexToBytes("000000007c2bac1d")) + genesisHeader := &NeoBlockHeader{ + &block.BlockHeader{ + Version: 0, + PrevHash: prevHash, + MerkleRoot: merKleRoot, + Timestamp: 1468595301, + Index: 0, + NextConsensus: nextConsensus, + ConsensusData: consensusData, + Witness: &tx2.Witness{ + InvocationScript: []byte{0}, + VerificationScript: []byte{81}, + }, + }, } - genesisHeader := &NeoBlockHeader{Header:new(block.Header)} - genesisHeader.SetVersion(0) - genesisHeader.SetPrevHash(prevHash) - genesisHeader.SetMerkleRoot(merkleRoot) - genesisHeader.SetTimeStamp(1468595301000) - genesisHeader.SetIndex(0) - genesisHeader.SetPrimaryIndex(0x00) - genesisHeader.SetNextConsensus(nextConsensus) - genesisHeader.SetWitnesses([]tx2.Witness{witness}) - param := new(scom.SyncGenesisHeaderParam) param.ChainID = 4 sink := common.NewZeroCopySink(nil) @@ -101,8 +105,7 @@ func TestSyncGenesisHeader(t *testing.T) { tx := &types.Transaction{ SignedAddr: []common.Address{acct.Address}, } - //cdb := new(storage.CacheDB) - //cdb.Put() + native := NewNative(sink.Bytes(), tx, nil) neoHandler := NewNEOHandler() err = neoHandler.SyncGenesisHeader(native) @@ -110,73 +113,80 @@ func TestSyncGenesisHeader(t *testing.T) { } func TestSyncBlockHeader(t *testing.T) { + prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) - is := []byte{} - vs, _ := crypto.Base64Decode("EQ==") - witness := tx2.Witness{ - InvocationScript: is, - VerificationScript: vs, + merKleRoot, _ := helper.UInt256FromString("0x803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4") + nextConsensus, _ := helper.AddressToScriptHash("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") + consensusData := binary.BigEndian.Uint64(helper.HexToBytes("000000007c2bac1d")) + genesisHeader := &NeoBlockHeader{ + &block.BlockHeader{ + Version: 0, + PrevHash: prevHash, + MerkleRoot: merKleRoot, + Timestamp: 1468595301, + Index: 0, + NextConsensus: nextConsensus, + ConsensusData: consensusData, + Witness: &tx2.Witness{ + InvocationScript: []byte{0}, + VerificationScript: []byte{81}, + }, + }, } - genesisHeader := &NeoBlockHeader{Header:new(block.Header)} - genesisHeader.SetVersion(0) - genesisHeader.SetPrevHash(prevHash) - genesisHeader.SetMerkleRoot(merkleRoot) - genesisHeader.SetTimeStamp(1468595301000) - genesisHeader.SetIndex(0) - genesisHeader.SetPrimaryIndex(0x00) - genesisHeader.SetNextConsensus(nextConsensus) - genesisHeader.SetWitnesses([]tx2.Witness{witness}) sink := common.NewZeroCopySink(nil) if err := genesisHeader.Serialization(sink); err != nil { t.Errorf("NeoBlockHeaderToBytes error:%v", err) } neoGenesisHeaderbs := sink.Bytes() - // block 100 - prevHash, _ = helper.UInt256FromString("0xcee650e843a8f8cf78f7c62a2bc2108375df93bfa9a912de64bea2d8948fec31") - merkleRoot, _ = helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - nextConsensus, _ = crypto.AddressToScriptHash("NYmMriQPYAiNxHC7tziV4ABJku5Yqe79N4", helper.DefaultAddressVersion) - is, _ = crypto.Base64Decode("DEAF2siXzBq5rCzpaNvAxTPuebSgsn3XX7bKMvuf1RzQx1QqJDLBn/XxMyCzAOnsolp67X8eLZ8xuc4bovqSMf4lDECxfs8iV5/5yLs2hVW0tB1d1n7R1J3HEoJ8vNCJr/xrqt3bJRoOFL+eObBmjyo+ZSk5M6GrGH+UqpglZqr0upu8DEAX9lh0LKdbFTOg5GfZ8gP9UdGURu/xbM288BKFUBXhTH1p/2Y4hqZzJoXes+DdlRCwWzhToCMa468OnmTHkxDoDEB4etR6RX+B69qB5cv7QjihqnTowYWzU3Zhec+yz+2wgETkD0aD4uUafiSGpCK7xNB7aknDbFgMJXWSK7cM+c3NDEDw4z4PxskKUfJ1cmXKXxhtdzo/05iEi6c/n2rfZHPLd/YA0aBPQuWf3QSWizQYsmsYyA2uriKR2PA7asqYYB60") - vs, _ = crypto.Base64Decode("FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhAj6bMuqJuU0GbmSbEk/VDjlu6RNp6OKmrhsRwXDQIiVtDCEDQI3NQWOW9keDrFh+oeFZPFfZ/qiAyKahkg6SollHeAYMIQKng0vpsy4pgdFXy1u9OstCz9EepcOxAiTXpE6YxZEPGwwhAroscPWZbzV6QxmHBYWfriz+oT4RcpYoAHcrPViKnUq9F0F7zmyl") - witness = tx2.Witness{ - InvocationScript: is, - VerificationScript: vs, + + prevHash, _ = helper.UInt256FromString("0x07e53bcbe93de88784e01401f8dae061934d34747e76b6a18b63e4213f3de220") + merKleRoot, _ = helper.UInt256FromString("0xbf6a0b78bede3ad758e09479b8712f60cb225a4047265847169b3864e23a3bc8") + nextConsensus, _ = helper.AddressToScriptHash("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") + consensusData = binary.BigEndian.Uint64(helper.HexToBytes("d9d3b5ccf2eedde1")) + is100, _ := hex.DecodeString("40424db765bc1e92e530292ec04ff8ddffb79bec13f04fd9f85c00163328aa9d64f0b40b74ca8c4b56445c9048c50e6a67df57ab221593612c6165251d9770f7e140465f1d1d3b532fcaa8a98633316e24a07358c857a3565f7cc9a1b87dd3e6dcbb191a7c78c1b57889924e813a0daacea5281884ce814d10469560f43c9d567cf440fd7252d9607389e9b61c577a8705b1d74165979dd9440c4a71d47443fc1014e46957b0a537e1244fd9b4363aefb2df5971749daf9073cfd014aecb7dba2b13ab40c141f6c63267ad12ebadb154a83a3444eccff046de534cda6f29059e531de58bfce6287ca68a62b45766df5522dfed449b3d1bdc0a319ab07d21cf8839f5b59240fee381887b2dc82447fbe9e6db6c1aa9adff8f7a7d2998cea4f901c002098115d7ba7e6218275c8690f86b92e8b641d59152243f2253ff86fa9c2b6413a52256") + vs100, _ := hex.DecodeString("552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae") + neoHeader100 := &NeoBlockHeader{ + &block.BlockHeader{ + Version: 0, + PrevHash: prevHash, + MerkleRoot: merKleRoot, + Timestamp: 1476649243, + Index: 100, + NextConsensus: nextConsensus, + ConsensusData: consensusData, + Witness: &tx2.Witness{ + InvocationScript: is100, + VerificationScript: vs100, + }, + }, } - neoHeader100 := &NeoBlockHeader{Header:new(block.Header)} - neoHeader100.SetVersion(0) - neoHeader100.SetPrevHash(prevHash) - neoHeader100.SetMerkleRoot(merkleRoot) - neoHeader100.SetTimeStamp(1616577294488) - neoHeader100.SetIndex(100) - neoHeader100.SetPrimaryIndex(0x00) - neoHeader100.SetNextConsensus(nextConsensus) - neoHeader100.SetWitnesses([]tx2.Witness{witness}) sink = common.NewZeroCopySink(nil) if err := neoHeader100.Serialization(sink); err != nil { t.Errorf("NeoBlockHeaderToBytes error:%v", err) } neoHeader100bs := sink.Bytes() - // block 200 - prevHash, _ = helper.UInt256FromString("0xe22cd5bb35d832e59554dc2d4165a48bed56b2d7f9df379639078cca35ecc770") - merkleRoot, _ = helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - nextConsensus, _ = crypto.AddressToScriptHash("NYmMriQPYAiNxHC7tziV4ABJku5Yqe79N4", helper.DefaultAddressVersion) - is, _ = crypto.Base64Decode("DEBGAk7oudrv67j+GFWetgK8W0Hu6m/15ceMxaq3sl6aKfjTQckmQfqzzGgzJ/rrdWMCyCsjYkgc14MdFvI/GnopDEBj9dRQtcKyu9K2qOyvqqkUoqK/9A32kdj0LbXpYPw+WDrz0DlvjNQF8dc2EuvmwTrYuQ5fUTrHvaPXKTmOPl3IDEAKtZf8AaZmY+onQejV8jqkEN5DGKKWthYGpVza5jueTvx4Hi1B5Uh7k6jW5Z6Y7mUVGuIUAGLbeULsp/MAQiyjDEBibp/Gy0rg5h1Hm3TokJi12KfYSMizn973+rkMDjKiWW1ySq6Sif3BEqlHi1prbuFPYSQf7xiJgs3+P0aFXfPzDEBdqKNocAkjWPBbxrHCHq0DRJoXBgmrXA9BSmytymp/pdU4xt2Y/Gxb/GBBXOAorOumjZ46DxWwnqfVpJ9adHMj") - vs, _ = crypto.Base64Decode("FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhAj6bMuqJuU0GbmSbEk/VDjlu6RNp6OKmrhsRwXDQIiVtDCEDQI3NQWOW9keDrFh+oeFZPFfZ/qiAyKahkg6SollHeAYMIQKng0vpsy4pgdFXy1u9OstCz9EepcOxAiTXpE6YxZEPGwwhAroscPWZbzV6QxmHBYWfriz+oT4RcpYoAHcrPViKnUq9F0F7zmyl") - witness = tx2.Witness{ - InvocationScript: is, - VerificationScript: vs, + prevHash, _ = helper.UInt256FromString("0xb4cabbcde5e5d5ecf0429cb4726f7a4d857e195e12bdc568cb1df2097c2d918d") + merKleRoot, _ = helper.UInt256FromString("0xb230e8bc2e0f35eff5279de5d6f9a6b1c26c5757247c4f33d744676919bfb3d1") + nextConsensus, _ = helper.AddressToScriptHash("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") + consensusData = binary.BigEndian.Uint64(helper.HexToBytes("ab01a2420960665a")) + is200, _ := hex.DecodeString("409de7102817ffda29e13e96e3ff541ea1c7498805504d39d2145990c9862f2aacdb748b631233c14a63cc1483f730843eced2abab80a9c5bbe4c7b5a552569cac40d3fde603e228e2ca3ee25ebf7651692be1bfa50cbc0230242719cd2d045d21c2fe44dc80e48dd8fd8ab741be0ce527b8aeada80f8c09f86af83ae6ed4f5e1e3940382bd5b00bf1778c09d402165b36756d6cbc8e7970fed080ba9805b96cc7ba5ff0606b7824585e6d4f318cb7b69dd1d7b5dbd82644aa9d329e73828225521f7e401d568aaef9d790358fc8475154d0c541ac7cef4f4fb51a18ddc5c1fab4f49bb138d4a7dad2f259579e7686819e668c28f024be117cc3aaa7a2dcad77336a0427404ab053cae9db932d988884f9e5c9026e18f762aad9d0bb143edc9e6c808f1f5585ed951103c251dcc331a6db3865faf22b778ce05e68e351608528c8fb1b172b") + vs200, _ := hex.DecodeString("552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae") + neoHeader200 := &NeoBlockHeader{ + &block.BlockHeader{ + Version: 0, + PrevHash: prevHash, + MerkleRoot: merKleRoot, + Timestamp: 1476651132, + Index: 200, + NextConsensus: nextConsensus, + ConsensusData: consensusData, + Witness: &tx2.Witness{ + InvocationScript: is200, + VerificationScript: vs200, + }, + }, } - neoHeader200 := &NeoBlockHeader{Header:new(block.Header)} - neoHeader200.SetVersion(0) - neoHeader200.SetPrevHash(prevHash) - neoHeader200.SetMerkleRoot(merkleRoot) - neoHeader200.SetTimeStamp(1616578903762) - neoHeader200.SetIndex(200) - neoHeader200.SetPrimaryIndex(0x00) - neoHeader200.SetNextConsensus(nextConsensus) - neoHeader200.SetWitnesses([]tx2.Witness{witness}) sink = common.NewZeroCopySink(nil) if err := neoHeader200.Serialization(sink); err != nil { t.Errorf("NeoBlockHeaderToBytes error:%v", err) diff --git a/native/service/header_sync/neo/states.go b/native/service/header_sync/neo/states.go index 05be7b5c6..349d276ad 100644 --- a/native/service/header_sync/neo/states.go +++ b/native/service/header_sync/neo/states.go @@ -18,25 +18,26 @@ package neo import ( + "encoding/hex" "fmt" - "github.com/joeqian10/neo3-gogogo/block" - "github.com/joeqian10/neo3-gogogo/crypto" - "github.com/joeqian10/neo3-gogogo/helper" - "github.com/joeqian10/neo3-gogogo/io" - "github.com/joeqian10/neo3-gogogo/mpt" + "github.com/joeqian10/neo-gogogo/block" + "github.com/joeqian10/neo-gogogo/crypto" + "github.com/joeqian10/neo-gogogo/helper" + "github.com/joeqian10/neo-gogogo/helper/io" + "github.com/joeqian10/neo-gogogo/mpt" "github.com/polynetwork/poly/common" ) type NeoConsensus struct { ChainID uint64 Height uint32 - NextConsensus *helper.UInt160 + NextConsensus helper.UInt160 } func (this *NeoConsensus) Serialization(sink *common.ZeroCopySink) { sink.WriteUint64(this.ChainID) sink.WriteUint32(this.Height) - sink.WriteVarBytes(this.NextConsensus.ToByteArray()) + sink.WriteVarBytes(this.NextConsensus.Bytes()) } func (this *NeoConsensus) Deserialization(source *common.ZeroCopySource) error { @@ -53,20 +54,23 @@ func (this *NeoConsensus) Deserialization(source *common.ZeroCopySource) error { return fmt.Errorf("NeoConsensus.Deserialization, NextConsensus NextVarBytes error") } - this.NextConsensus = helper.UInt160FromBytes(nextConsensusBs); + var err error + if this.NextConsensus, err = helper.UInt160FromBytes(nextConsensusBs); err != nil { + return fmt.Errorf("NeoConsensus.Deserialization, NextConsensus UInt160FromBytes error: %s", err) + } return nil } type NeoBlockHeader struct { - *block.Header + *block.BlockHeader } func (this *NeoBlockHeader) Deserialization(source *common.ZeroCopySource) error { - this.Header = new(block.Header) + this.BlockHeader = new(block.BlockHeader) br := io.NewBinaryReaderFromBuf(source.Bytes()) - this.Header.Deserialize(br) + this.BlockHeader.Deserialize(br) if br.Err != nil { - return fmt.Errorf("neo3-gogogo Header Deserialize error: %s", br.Err) + return fmt.Errorf("joeqian10/neo-gogogo/block.BlockHeader Deserialize error: %s", br.Err) } return nil } @@ -75,7 +79,7 @@ func (this *NeoBlockHeader) Serialization(sink *common.ZeroCopySink) error { bw := io.NewBufBinaryWriter() this.Serialize(bw.BinaryWriter) if bw.Err != nil { - return fmt.Errorf("neo3-gogogo Header Serialize error: %s", bw.Err) + return fmt.Errorf("joeqian10/neo-gogogo/block.BlockHeader Serialize error: %s", bw.Err) } sink.WriteBytes(bw.Bytes()) return nil @@ -85,7 +89,7 @@ func (this *NeoBlockHeader) GetMessage() ([]byte, error) { buf := io.NewBufBinaryWriter() this.SerializeUnsigned(buf.BinaryWriter) if buf.Err != nil { - return nil, fmt.Errorf("neo3-gogogo Header SerializeUnsigned error: %s", buf.Err) + return nil, fmt.Errorf("GetHashData of NeoBlockHeader neo-gogogo block.BlockHeader SerializeUnsigned error: %s", buf.Err) } return buf.Bytes(), nil } @@ -99,7 +103,7 @@ func (this *NeoCrossChainMsg) Deserialization(source *common.ZeroCopySource) err br := io.NewBinaryReaderFromBuf(source.Bytes()) this.Deserialize(br) if br.Err != nil { - return fmt.Errorf("neo3-gogogo mpt.StateRoot Deserialize error: %s", br.Err) + return fmt.Errorf("neo-gogogo mpt.StateRoot Deserialize error: %s", br.Err) } return nil } @@ -108,21 +112,24 @@ func (this *NeoCrossChainMsg) Serialization(sink *common.ZeroCopySink) error { bw := io.NewBufBinaryWriter() this.Serialize(bw.BinaryWriter) if bw.Err != nil { - return fmt.Errorf("neo3-gogogo mpt.StateRoot Serialize error: %s", bw.Err) + return fmt.Errorf("neo-gogogo mpt.StateRoot Serialize error: %s", bw.Err) } sink.WriteBytes(bw.Bytes()) return nil } -func (this *NeoCrossChainMsg) GetScriptHash() (*helper.UInt160, error) { - verificationScriptBs, err := crypto.Base64Decode(this.Witness.Verification) // base64 +func (this *NeoCrossChainMsg) GetScriptHash() (helper.UInt160, error) { + verificationScriptBs, err := hex.DecodeString(this.Witness.VerificationScript) if err != nil { - return nil, fmt.Errorf("NeoCrossChainMsg.Witness.Verification decode error: %s", err) + return helper.UInt160{}, fmt.Errorf("NeoCrossChainMsg.Witness.VerificationScript decode to bytes error: %s", err) } if len(verificationScriptBs) == 0 { - return nil, fmt.Errorf("NeoCrossChainMsg.Witness.VerificationScript is empty") + return helper.UInt160{}, fmt.Errorf("NeoCrossChainMsg.Witness.VerificationScript length is 0 ") + } + scriptHash, err := helper.UInt160FromBytes(crypto.Hash160(verificationScriptBs)) + if err != nil { + return helper.UInt160{}, fmt.Errorf("neo-gogogo tx.Witness GetScriptHash error: %s", err) } - scriptHash := helper.UInt160FromBytes(crypto.Hash160(verificationScriptBs)) return scriptHash, nil } @@ -130,7 +137,7 @@ func (this *NeoCrossChainMsg) GetMessage() ([]byte, error) { buf := io.NewBufBinaryWriter() this.SerializeUnsigned(buf.BinaryWriter) if buf.Err != nil { - return nil, fmt.Errorf("neo3-gogogo mpt.StateRoot SerializeUnsigned error: %s", buf.Err) + return nil, fmt.Errorf("GetHashData of NeoBlockHeader neo-gogogo mpt.StateRoot SerializeUnsigned error: %s", buf.Err) } return buf.Bytes(), nil } diff --git a/native/service/header_sync/neo/states_test.go b/native/service/header_sync/neo/states_test.go index 1de6d0a8d..9223ac7a9 100644 --- a/native/service/header_sync/neo/states_test.go +++ b/native/service/header_sync/neo/states_test.go @@ -18,19 +18,19 @@ package neo import ( - "github.com/joeqian10/neo3-gogogo/crypto" - "github.com/joeqian10/neo3-gogogo/rpc/models" "testing" - "github.com/joeqian10/neo3-gogogo/helper" - "github.com/joeqian10/neo3-gogogo/mpt" - tx2 "github.com/joeqian10/neo3-gogogo/tx" + "encoding/binary" + "github.com/joeqian10/neo-gogogo/block" + "github.com/joeqian10/neo-gogogo/helper" + "github.com/joeqian10/neo-gogogo/mpt" + tx2 "github.com/joeqian10/neo-gogogo/tx" "github.com/polynetwork/poly/common" "github.com/stretchr/testify/assert" ) func Test_NeoConsensus_Serialization(t *testing.T) { - nextConsensus, _ := crypto.AddressToScriptHash("NYmMriQPYAiNxHC7tziV4ABJku5Yqe79N4", helper.DefaultAddressVersion) + nextConsensus, _ := helper.UInt160FromString("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") paramSerialize := &NeoConsensus{ ChainID: 4, Height: 100, @@ -46,25 +46,25 @@ func Test_NeoConsensus_Serialization(t *testing.T) { } func Test_NeoBlockHeader_Serialization(t *testing.T) { + paramSerialize := new(NeoBlockHeader) prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") - nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) - vs, _ := crypto.Base64Decode("EQ==") - witness := tx2.Witness{ - InvocationScript: []byte{}, - VerificationScript: vs, + merKleRoot, _ := helper.UInt256FromString("0x803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4") + nextConsensus, _ := helper.AddressToScriptHash("APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR") + consensusData := binary.BigEndian.Uint64(helper.HexToBytes("000000007c2bac1d")) + genesisHeader := &block.BlockHeader{ + Version: 0, + PrevHash: prevHash, + MerkleRoot: merKleRoot, + Timestamp: 1468595301, + Index: 0, + NextConsensus: nextConsensus, + ConsensusData: consensusData, + Witness: &tx2.Witness{ + InvocationScript: []byte{0}, + VerificationScript: []byte{81}, + }, } - genesisHeader := &NeoBlockHeader{} - genesisHeader.SetVersion(0) - genesisHeader.SetPrevHash(prevHash) - genesisHeader.SetMerkleRoot(merkleRoot) - genesisHeader.SetTimeStamp(1468595301000) - genesisHeader.SetIndex(0) - genesisHeader.SetPrimaryIndex(0x00) - genesisHeader.SetNextConsensus(nextConsensus) - genesisHeader.SetWitnesses([]tx2.Witness{witness}) - paramSerialize := new(NeoBlockHeader) - paramSerialize.Header = genesisHeader.Header + paramSerialize.BlockHeader = genesisHeader sink := common.NewZeroCopySink(nil) err := paramSerialize.Serialization(sink) assert.Nil(t, err) @@ -78,12 +78,16 @@ func Test_NeoBlockHeader_Serialization(t *testing.T) { func Test_NeoCrossChainMsg_Serialization(t *testing.T) { paramSerialize := &NeoCrossChainMsg{ StateRoot: &mpt.StateRoot{ - Version: 0, - Index: 1000, - RootHash: "0x53360e02b03f548c6fc2f74f760d82a6749df6a844fd117ad7b62504390c8f8c", - Witness: models.RpcWitness { - Invocation: "DEBnIRHFS8tG/6pw4cqZQbOQZri6rboaQPUJTCVS2ZD/HwOZG2m9IG3NJ8E/gTV++o7G1r35l+p5aQcAbqwoP1wTDECeyQcx2M1DP/irLP7sQy/tNRyina2rdK6ATV/QY+Ib4tJ3sYpXaiPx4iGo+AgqUeTRDmD8anfUNtYzjYgos6x9DEDS+medyKx59813WgtCusxLIK0tx50H36tbMGmTUQxR5nHzrpG8nzQ8HKNKRNMgQNBoT4U3pcHMpwJY9bXUge4R", - Verification: "EwwhAnIujtkuXxpCUIyfti3TyTtoOhUd/wjLU4lwdHzBhsu6DCECkeyvwoMh29AA30IiQMankxndS3LESLsUGkLoTzfm/doMIQOyS9DtdzAVHs/Ne1yheExdO8NYTw1NkKyi1i4gd5tG1wwhA/sZ1ZOuaNWI9PnKa/3WYbE9xjnVVYWhVYYXFD38xLJWFEF7zmyl", + Version: 1, + Index: 100, + PreHash: "803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4", + StateRoot: "803ff4abe3ea6533bcc0be574efa02f83ae8fdc651c879056b0d9be336c01bf4", + Witness: struct { + InvocationScript string `json:"invocation"` + VerificationScript string `json:"verification"` + }{ + InvocationScript: "40424db765bc1e92e530292ec04ff8ddffb79bec13f04fd9f85c00163328aa9d64f0b40b74ca8c4b56445c9048c50e6a67df57ab221593612c6165251d9770f7e140465f1d1d3b532fcaa8a98633316e24a07358c857a3565f7cc9a1b87dd3e6dcbb191a7c78c1b57889924e813a0daacea5281884ce814d10469560f43c9d567cf440fd7252d9607389e9b61c577a8705b1d74165979dd9440c4a71d47443fc1014e46957b0a537e1244fd9b4363aefb2df5971749daf9073cfd014aecb7dba2b13ab40c141f6c63267ad12ebadb154a83a3444eccff046de534cda6f29059e531de58bfce6287ca68a62b45766df5522dfed449b3d1bdc0a319ab07d21cf8839f5b59240fee381887b2dc82447fbe9e6db6c1aa9adff8f7a7d2998cea4f901c002098115d7ba7e6218275c8690f86b92e8b641d59152243f2253ff86fa9c2b6413a52256", + VerificationScript: "552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae", }, }, } diff --git a/native/service/header_sync/neo/utils.go b/native/service/header_sync/neo/utils.go index 1a03e4d22..11507b64e 100644 --- a/native/service/header_sync/neo/utils.go +++ b/native/service/header_sync/neo/utils.go @@ -20,7 +20,7 @@ package neo import ( "encoding/hex" "fmt" - "github.com/joeqian10/neo3-gogogo/tx" + "github.com/joeqian10/neo-gogogo/tx" "github.com/polynetwork/poly/common" cstates "github.com/polynetwork/poly/core/states" "github.com/polynetwork/poly/native" @@ -44,7 +44,7 @@ func verifyHeader(native *native.NativeService, chainID uint64, header *NeoBlock return fmt.Errorf("verifyHeader, unable to get hash data of header") } if verified := tx.VerifyMultiSignatureWitness(msg, header.Witness); !verified { - return fmt.Errorf("verifyHeader, VerifyMultiSignatureWitness error: %s, height: %d", err, header.GetIndex()) + return fmt.Errorf("verifyHeader, VerifyMultiSignatureWitness error: %s, height: %d", err, header.Index) } return nil } @@ -65,8 +65,8 @@ func VerifyCrossChainMsgSig(native *native.NativeService, chainID uint64, crossC if err != nil { return fmt.Errorf("verifyCrossChainMsg, unable to get unsigned message of neo crossChainMsg") } - invScript, _ := hex.DecodeString(crossChainMsg.Witness.Invocation) - verScript, _ := hex.DecodeString(crossChainMsg.Witness.Verification) + invScript, _ := hex.DecodeString(crossChainMsg.Witness.InvocationScript) + verScript, _ := hex.DecodeString(crossChainMsg.Witness.VerificationScript) witness := &tx.Witness{ InvocationScript: invScript, VerificationScript: verScript, diff --git a/native/service/header_sync/neo3/header_sync.go b/native/service/header_sync/neo3/header_sync.go new file mode 100644 index 000000000..3914df179 --- /dev/null +++ b/native/service/header_sync/neo3/header_sync.go @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2020 The poly network Authors + * This file is part of The poly network library. + * + * The poly network is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The poly network is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The poly network . If not, see . + */ + +package neo3 + +import ( + "fmt" + "github.com/polynetwork/poly/native" + "github.com/polynetwork/poly/native/service/governance/node_manager" + hscommon "github.com/polynetwork/poly/native/service/header_sync/common" + + "github.com/polynetwork/poly/common" + "github.com/polynetwork/poly/native/service/utils" +) + +type NEOHandler struct { +} + +func NewNEOHandler() *NEOHandler { + return &NEOHandler{} +} + +func (this *NEOHandler) SyncGenesisHeader(native *native.NativeService) error { + params := new(hscommon.SyncGenesisHeaderParam) + if err := params.Deserialization(common.NewZeroCopySource(native.GetInput())); err != nil { + return fmt.Errorf("NeoHandler SyncGenesisHeader, contract params deserialize error: %v", err) + } + // Get current epoch operator + operatorAddress, err := node_manager.GetCurConOperator(native) + if err != nil { + return fmt.Errorf("NeoHandler SyncGenesisHeader, get current consensus operator address error: %v", err) + } + //check witness + err = utils.ValidateOwner(native, operatorAddress) + if err != nil { + return fmt.Errorf("NeoHandler SyncGenesisHeader, checkWitness error: %v", err) + } + // Deserialize neo block header + header := new(NeoBlockHeader) + if err := header.Deserialization(common.NewZeroCopySource(params.GenesisHeader)); err != nil { + return fmt.Errorf("NeoHandler SyncGenesisHeader, deserialize header err: %v", err) + } + if neoConsensus, _ := getConsensusValByChainId(native, params.ChainID); neoConsensus == nil { + // Put NeoConsensus.NextConsensus into storage + if err = putConsensusValByChainId(native, &NeoConsensus{ + ChainID: params.ChainID, + Height: header.GetIndex(), + NextConsensus: header.GetNextConsensus(), + }); err != nil { + return fmt.Errorf("NeoHandler SyncGenesisHeader, update ConsensusPeer error: %v", err) + } + } + return nil +} + +func (this *NEOHandler) SyncBlockHeader(native *native.NativeService) error { + params := new(hscommon.SyncBlockHeaderParam) + if err := params.Deserialization(common.NewZeroCopySource(native.GetInput())); err != nil { + return fmt.Errorf("SyncBlockHeader, contract params deserialize error: %v", err) + } + neoConsensus, err := getConsensusValByChainId(native, params.ChainID) + if err != nil { + return fmt.Errorf("SyncBlockHeader, the consensus validator has not been initialized, chainId: %d", params.ChainID) + } + var newNeoConsensus *NeoConsensus + for _, v := range params.Headers { + header := new(NeoBlockHeader) + if err := header.Deserialization(common.NewZeroCopySource(v)); err != nil { + return fmt.Errorf("SyncBlockHeader, NeoBlockHeaderFromBytes error: %v", err) + } + if !header.GetNextConsensus().Equals(neoConsensus.NextConsensus) && header.GetIndex() > neoConsensus.Height { + if err = verifyHeader(native, params.ChainID, header); err != nil { + return fmt.Errorf("SyncBlockHeader, verifyHeader error: %v", err) + } + newNeoConsensus = &NeoConsensus{ + ChainID: neoConsensus.ChainID, + Height: header.GetIndex(), + NextConsensus: header.GetNextConsensus(), + } + } + } + if newNeoConsensus != nil { + if err = putConsensusValByChainId(native, newNeoConsensus); err != nil { + return fmt.Errorf("SyncBlockHeader, update ConsensusPeer error: %v", err) + } + } + return nil +} + +func (this *NEOHandler) SyncCrossChainMsg(native *native.NativeService) error { + return nil +} diff --git a/native/service/header_sync/neo3/header_sync_test.go b/native/service/header_sync/neo3/header_sync_test.go new file mode 100644 index 000000000..085f1e150 --- /dev/null +++ b/native/service/header_sync/neo3/header_sync_test.go @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2020 The poly network Authors + * This file is part of The poly network library. + * + * The poly network is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The poly network is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The poly network . If not, see . + */ + +package neo3 + +import ( + "github.com/joeqian10/neo3-gogogo/block" + "github.com/joeqian10/neo3-gogogo/crypto" + "github.com/joeqian10/neo3-gogogo/helper" + tx2 "github.com/joeqian10/neo3-gogogo/tx" + "github.com/ontio/ontology-crypto/keypair" + "github.com/polynetwork/poly/account" + "github.com/polynetwork/poly/common" + "github.com/polynetwork/poly/core/genesis" + "github.com/polynetwork/poly/core/store/leveldbstore" + "github.com/polynetwork/poly/core/store/overlaydb" + "github.com/polynetwork/poly/core/types" + "github.com/polynetwork/poly/native" + scom "github.com/polynetwork/poly/native/service/header_sync/common" + "github.com/polynetwork/poly/native/storage" + "github.com/stretchr/testify/assert" + "testing" +) + +var ( + //neoAcct = func() *wallet.Account { + // acct, _ := wallet.NewAccount() + // return acct + //}() + acct *account.Account = account.NewAccount("") + getNativeFunc = func() *native.NativeService { + store, _ := leveldbstore.NewMemLevelDBStore() + cacheDB := storage.NewCacheDB(overlaydb.NewOverlayDB(store)) + service, _ := native.NewNativeService(cacheDB, new(types.Transaction), 0, 200, common.Uint256{}, 0, nil, false) + return service + } + getNeoHanderFunc = func() *NEOHandler { + return NewNEOHandler() + } + setBKers = func() { + genesis.GenesisBookkeepers = []keypair.PublicKey{acct.PublicKey} + } +) + +func init() { + setBKers() +} + +func NewNative(args []byte, tx *types.Transaction, db *storage.CacheDB) *native.NativeService { + if db == nil { + store, _ := leveldbstore.NewMemLevelDBStore() + db = storage.NewCacheDB(overlaydb.NewOverlayDB(store)) + } + ns, _ := native.NewNativeService(db, tx, 0, 0, common.Uint256{0}, 0, args, false) + return ns +} + +func TestSyncGenesisHeader(t *testing.T) { + prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) + vs, _ := crypto.Base64Decode("EQ==") + witness := tx2.Witness{ + InvocationScript: []byte{}, + VerificationScript: vs, + } + genesisHeader := &NeoBlockHeader{Header: new(block.Header)} + genesisHeader.SetVersion(0) + genesisHeader.SetPrevHash(prevHash) + genesisHeader.SetMerkleRoot(merkleRoot) + genesisHeader.SetTimeStamp(1468595301000) + genesisHeader.SetIndex(0) + genesisHeader.SetPrimaryIndex(0x00) + genesisHeader.SetNextConsensus(nextConsensus) + genesisHeader.SetWitnesses([]tx2.Witness{witness}) + + param := new(scom.SyncGenesisHeaderParam) + param.ChainID = 4 + sink := common.NewZeroCopySink(nil) + err := genesisHeader.Serialization(sink) + param.GenesisHeader = sink.Bytes() + assert.Nil(t, err) + + sink = common.NewZeroCopySink(nil) + param.Serialization(sink) + + tx := &types.Transaction{ + SignedAddr: []common.Address{acct.Address}, + } + //cdb := new(storage.CacheDB) + //cdb.Put() + native := NewNative(sink.Bytes(), tx, nil) + neoHandler := NewNEOHandler() + err = neoHandler.SyncGenesisHeader(native) + assert.NoError(t, err) +} + +func TestSyncBlockHeader(t *testing.T) { + prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) + is := []byte{} + vs, _ := crypto.Base64Decode("EQ==") + witness := tx2.Witness{ + InvocationScript: is, + VerificationScript: vs, + } + genesisHeader := &NeoBlockHeader{Header: new(block.Header)} + genesisHeader.SetVersion(0) + genesisHeader.SetPrevHash(prevHash) + genesisHeader.SetMerkleRoot(merkleRoot) + genesisHeader.SetTimeStamp(1468595301000) + genesisHeader.SetIndex(0) + genesisHeader.SetPrimaryIndex(0x00) + genesisHeader.SetNextConsensus(nextConsensus) + genesisHeader.SetWitnesses([]tx2.Witness{witness}) + sink := common.NewZeroCopySink(nil) + if err := genesisHeader.Serialization(sink); err != nil { + t.Errorf("NeoBlockHeaderToBytes error:%v", err) + } + neoGenesisHeaderbs := sink.Bytes() + // block 100 + prevHash, _ = helper.UInt256FromString("0xcee650e843a8f8cf78f7c62a2bc2108375df93bfa9a912de64bea2d8948fec31") + merkleRoot, _ = helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ = crypto.AddressToScriptHash("NYmMriQPYAiNxHC7tziV4ABJku5Yqe79N4", helper.DefaultAddressVersion) + is, _ = crypto.Base64Decode("DEAF2siXzBq5rCzpaNvAxTPuebSgsn3XX7bKMvuf1RzQx1QqJDLBn/XxMyCzAOnsolp67X8eLZ8xuc4bovqSMf4lDECxfs8iV5/5yLs2hVW0tB1d1n7R1J3HEoJ8vNCJr/xrqt3bJRoOFL+eObBmjyo+ZSk5M6GrGH+UqpglZqr0upu8DEAX9lh0LKdbFTOg5GfZ8gP9UdGURu/xbM288BKFUBXhTH1p/2Y4hqZzJoXes+DdlRCwWzhToCMa468OnmTHkxDoDEB4etR6RX+B69qB5cv7QjihqnTowYWzU3Zhec+yz+2wgETkD0aD4uUafiSGpCK7xNB7aknDbFgMJXWSK7cM+c3NDEDw4z4PxskKUfJ1cmXKXxhtdzo/05iEi6c/n2rfZHPLd/YA0aBPQuWf3QSWizQYsmsYyA2uriKR2PA7asqYYB60") + vs, _ = crypto.Base64Decode("FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhAj6bMuqJuU0GbmSbEk/VDjlu6RNp6OKmrhsRwXDQIiVtDCEDQI3NQWOW9keDrFh+oeFZPFfZ/qiAyKahkg6SollHeAYMIQKng0vpsy4pgdFXy1u9OstCz9EepcOxAiTXpE6YxZEPGwwhAroscPWZbzV6QxmHBYWfriz+oT4RcpYoAHcrPViKnUq9F0F7zmyl") + witness = tx2.Witness{ + InvocationScript: is, + VerificationScript: vs, + } + neoHeader100 := &NeoBlockHeader{Header: new(block.Header)} + neoHeader100.SetVersion(0) + neoHeader100.SetPrevHash(prevHash) + neoHeader100.SetMerkleRoot(merkleRoot) + neoHeader100.SetTimeStamp(1616577294488) + neoHeader100.SetIndex(100) + neoHeader100.SetPrimaryIndex(0x00) + neoHeader100.SetNextConsensus(nextConsensus) + neoHeader100.SetWitnesses([]tx2.Witness{witness}) + sink = common.NewZeroCopySink(nil) + if err := neoHeader100.Serialization(sink); err != nil { + t.Errorf("NeoBlockHeaderToBytes error:%v", err) + } + neoHeader100bs := sink.Bytes() + + // block 200 + prevHash, _ = helper.UInt256FromString("0xe22cd5bb35d832e59554dc2d4165a48bed56b2d7f9df379639078cca35ecc770") + merkleRoot, _ = helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ = crypto.AddressToScriptHash("NYmMriQPYAiNxHC7tziV4ABJku5Yqe79N4", helper.DefaultAddressVersion) + is, _ = crypto.Base64Decode("DEBGAk7oudrv67j+GFWetgK8W0Hu6m/15ceMxaq3sl6aKfjTQckmQfqzzGgzJ/rrdWMCyCsjYkgc14MdFvI/GnopDEBj9dRQtcKyu9K2qOyvqqkUoqK/9A32kdj0LbXpYPw+WDrz0DlvjNQF8dc2EuvmwTrYuQ5fUTrHvaPXKTmOPl3IDEAKtZf8AaZmY+onQejV8jqkEN5DGKKWthYGpVza5jueTvx4Hi1B5Uh7k6jW5Z6Y7mUVGuIUAGLbeULsp/MAQiyjDEBibp/Gy0rg5h1Hm3TokJi12KfYSMizn973+rkMDjKiWW1ySq6Sif3BEqlHi1prbuFPYSQf7xiJgs3+P0aFXfPzDEBdqKNocAkjWPBbxrHCHq0DRJoXBgmrXA9BSmytymp/pdU4xt2Y/Gxb/GBBXOAorOumjZ46DxWwnqfVpJ9adHMj") + vs, _ = crypto.Base64Decode("FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhAj6bMuqJuU0GbmSbEk/VDjlu6RNp6OKmrhsRwXDQIiVtDCEDQI3NQWOW9keDrFh+oeFZPFfZ/qiAyKahkg6SollHeAYMIQKng0vpsy4pgdFXy1u9OstCz9EepcOxAiTXpE6YxZEPGwwhAroscPWZbzV6QxmHBYWfriz+oT4RcpYoAHcrPViKnUq9F0F7zmyl") + witness = tx2.Witness{ + InvocationScript: is, + VerificationScript: vs, + } + neoHeader200 := &NeoBlockHeader{Header: new(block.Header)} + neoHeader200.SetVersion(0) + neoHeader200.SetPrevHash(prevHash) + neoHeader200.SetMerkleRoot(merkleRoot) + neoHeader200.SetTimeStamp(1616578903762) + neoHeader200.SetIndex(200) + neoHeader200.SetPrimaryIndex(0x00) + neoHeader200.SetNextConsensus(nextConsensus) + neoHeader200.SetWitnesses([]tx2.Witness{witness}) + sink = common.NewZeroCopySink(nil) + if err := neoHeader200.Serialization(sink); err != nil { + t.Errorf("NeoBlockHeaderToBytes error:%v", err) + } + neoHeader200bs := sink.Bytes() + + neoHandler := NewNEOHandler() + var native *native.NativeService + { + param := new(scom.SyncGenesisHeaderParam) + param.ChainID = 4 + param.GenesisHeader = neoGenesisHeaderbs + sink := common.NewZeroCopySink(nil) + param.Serialization(sink) + + tx := &types.Transaction{ + SignedAddr: []common.Address{acct.Address}, + } + + native = NewNative(sink.Bytes(), tx, nil) + err := neoHandler.SyncGenesisHeader(native) + assert.NoError(t, err) + } + + { + param := new(scom.SyncBlockHeaderParam) + param.ChainID = 4 + param.Address = acct.Address + param.Headers = append(param.Headers, neoHeader100bs) + param.Headers = append(param.Headers, neoHeader200bs) + sink := common.NewZeroCopySink(nil) + param.Serialization(sink) + + tx := &types.Transaction{ + SignedAddr: []common.Address{acct.Address}, + } + + native = NewNative(sink.Bytes(), tx, native.GetCacheDB()) + err := neoHandler.SyncBlockHeader(native) + assert.NoError(t, err) + } +} diff --git a/native/service/header_sync/neo3/states.go b/native/service/header_sync/neo3/states.go new file mode 100644 index 000000000..5cbd7dc1d --- /dev/null +++ b/native/service/header_sync/neo3/states.go @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2020 The poly network Authors + * This file is part of The poly network library. + * + * The poly network is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The poly network is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The poly network . If not, see . + */ + +package neo3 + +import ( + "fmt" + "github.com/joeqian10/neo3-gogogo/block" + "github.com/joeqian10/neo3-gogogo/crypto" + "github.com/joeqian10/neo3-gogogo/helper" + "github.com/joeqian10/neo3-gogogo/io" + "github.com/joeqian10/neo3-gogogo/mpt" + "github.com/polynetwork/poly/common" +) + +type NeoConsensus struct { + ChainID uint64 + Height uint32 + NextConsensus *helper.UInt160 +} + +func (this *NeoConsensus) Serialization(sink *common.ZeroCopySink) { + sink.WriteUint64(this.ChainID) + sink.WriteUint32(this.Height) + sink.WriteVarBytes(this.NextConsensus.ToByteArray()) +} + +func (this *NeoConsensus) Deserialization(source *common.ZeroCopySource) error { + var eof bool + if this.ChainID, eof = source.NextUint64(); eof { + return fmt.Errorf("NeoConsensus.Deserialization, ChainID NextUint64 error") + } + if this.Height, eof = source.NextUint32(); eof { + return fmt.Errorf("NeoConsensus.Deserialization, Height NextUint32 error") + } + + nextConsensusBs, eof := source.NextVarBytes() + if eof { + return fmt.Errorf("NeoConsensus.Deserialization, NextConsensus NextVarBytes error") + } + + this.NextConsensus = helper.UInt160FromBytes(nextConsensusBs); + return nil +} + +type NeoBlockHeader struct { + *block.Header +} + +func (this *NeoBlockHeader) Deserialization(source *common.ZeroCopySource) error { + this.Header = new(block.Header) + br := io.NewBinaryReaderFromBuf(source.Bytes()) + this.Header.Deserialize(br) + if br.Err != nil { + return fmt.Errorf("neo3-gogogo Header Deserialize error: %s", br.Err) + } + return nil +} + +func (this *NeoBlockHeader) Serialization(sink *common.ZeroCopySink) error { + bw := io.NewBufBinaryWriter() + this.Serialize(bw.BinaryWriter) + if bw.Err != nil { + return fmt.Errorf("neo3-gogogo Header Serialize error: %s", bw.Err) + } + sink.WriteBytes(bw.Bytes()) + return nil +} + +func (this *NeoBlockHeader) GetMessage() ([]byte, error) { + buf := io.NewBufBinaryWriter() + this.SerializeUnsigned(buf.BinaryWriter) + if buf.Err != nil { + return nil, fmt.Errorf("neo3-gogogo Header SerializeUnsigned error: %s", buf.Err) + } + return buf.Bytes(), nil +} + +type NeoCrossChainMsg struct { + *mpt.StateRoot +} + +func (this *NeoCrossChainMsg) Deserialization(source *common.ZeroCopySource) error { + this.StateRoot = new(mpt.StateRoot) + br := io.NewBinaryReaderFromBuf(source.Bytes()) + this.Deserialize(br) + if br.Err != nil { + return fmt.Errorf("neo3-gogogo mpt.StateRoot Deserialize error: %s", br.Err) + } + return nil +} + +func (this *NeoCrossChainMsg) Serialization(sink *common.ZeroCopySink) error { + bw := io.NewBufBinaryWriter() + this.Serialize(bw.BinaryWriter) + if bw.Err != nil { + return fmt.Errorf("neo3-gogogo mpt.StateRoot Serialize error: %s", bw.Err) + } + sink.WriteBytes(bw.Bytes()) + return nil +} + +func (this *NeoCrossChainMsg) GetScriptHash() (*helper.UInt160, error) { + verificationScriptBs, err := crypto.Base64Decode(this.Witness.Verification) // base64 + if err != nil { + return nil, fmt.Errorf("NeoCrossChainMsg.Witness.Verification decode error: %s", err) + } + if len(verificationScriptBs) == 0 { + return nil, fmt.Errorf("NeoCrossChainMsg.Witness.VerificationScript is empty") + } + scriptHash := helper.UInt160FromBytes(crypto.Hash160(verificationScriptBs)) + return scriptHash, nil +} + +func (this *NeoCrossChainMsg) GetMessage() ([]byte, error) { + buf := io.NewBufBinaryWriter() + this.SerializeUnsigned(buf.BinaryWriter) + if buf.Err != nil { + return nil, fmt.Errorf("neo3-gogogo mpt.StateRoot SerializeUnsigned error: %s", buf.Err) + } + return buf.Bytes(), nil +} diff --git a/native/service/header_sync/neo3/states_test.go b/native/service/header_sync/neo3/states_test.go new file mode 100644 index 000000000..93d352feb --- /dev/null +++ b/native/service/header_sync/neo3/states_test.go @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2020 The poly network Authors + * This file is part of The poly network library. + * + * The poly network is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The poly network is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The poly network . If not, see . + */ + +package neo3 + +import ( + "github.com/joeqian10/neo3-gogogo/crypto" + "github.com/joeqian10/neo3-gogogo/rpc/models" + "testing" + + "github.com/joeqian10/neo3-gogogo/helper" + "github.com/joeqian10/neo3-gogogo/mpt" + tx2 "github.com/joeqian10/neo3-gogogo/tx" + "github.com/polynetwork/poly/common" + "github.com/stretchr/testify/assert" +) + +func Test_NeoConsensus_Serialization(t *testing.T) { + nextConsensus, _ := crypto.AddressToScriptHash("NYmMriQPYAiNxHC7tziV4ABJku5Yqe79N4", helper.DefaultAddressVersion) + paramSerialize := &NeoConsensus{ + ChainID: 4, + Height: 100, + NextConsensus: nextConsensus, + } + sink := common.NewZeroCopySink(nil) + paramSerialize.Serialization(sink) + + paramDeserialize := new(NeoConsensus) + err := paramDeserialize.Deserialization(common.NewZeroCopySource(sink.Bytes())) + assert.Nil(t, err) + assert.Equal(t, paramDeserialize, paramSerialize) +} + +func Test_NeoBlockHeader_Serialization(t *testing.T) { + prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") + nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) + vs, _ := crypto.Base64Decode("EQ==") + witness := tx2.Witness{ + InvocationScript: []byte{}, + VerificationScript: vs, + } + genesisHeader := &NeoBlockHeader{} + genesisHeader.SetVersion(0) + genesisHeader.SetPrevHash(prevHash) + genesisHeader.SetMerkleRoot(merkleRoot) + genesisHeader.SetTimeStamp(1468595301000) + genesisHeader.SetIndex(0) + genesisHeader.SetPrimaryIndex(0x00) + genesisHeader.SetNextConsensus(nextConsensus) + genesisHeader.SetWitnesses([]tx2.Witness{witness}) + paramSerialize := new(NeoBlockHeader) + paramSerialize.Header = genesisHeader.Header + sink := common.NewZeroCopySink(nil) + err := paramSerialize.Serialization(sink) + assert.Nil(t, err) + + paramDeserialize := new(NeoBlockHeader) + err = paramDeserialize.Deserialization(common.NewZeroCopySource(sink.Bytes())) + assert.Nil(t, err) + assert.Equal(t, paramDeserialize, paramSerialize) +} + +func Test_NeoCrossChainMsg_Serialization(t *testing.T) { + paramSerialize := &NeoCrossChainMsg{ + StateRoot: &mpt.StateRoot{ + Version: 0, + Index: 1000, + RootHash: "0x53360e02b03f548c6fc2f74f760d82a6749df6a844fd117ad7b62504390c8f8c", + Witness: models.RpcWitness { + Invocation: "DEBnIRHFS8tG/6pw4cqZQbOQZri6rboaQPUJTCVS2ZD/HwOZG2m9IG3NJ8E/gTV++o7G1r35l+p5aQcAbqwoP1wTDECeyQcx2M1DP/irLP7sQy/tNRyina2rdK6ATV/QY+Ib4tJ3sYpXaiPx4iGo+AgqUeTRDmD8anfUNtYzjYgos6x9DEDS+medyKx59813WgtCusxLIK0tx50H36tbMGmTUQxR5nHzrpG8nzQ8HKNKRNMgQNBoT4U3pcHMpwJY9bXUge4R", + Verification: "EwwhAnIujtkuXxpCUIyfti3TyTtoOhUd/wjLU4lwdHzBhsu6DCECkeyvwoMh29AA30IiQMankxndS3LESLsUGkLoTzfm/doMIQOyS9DtdzAVHs/Ne1yheExdO8NYTw1NkKyi1i4gd5tG1wwhA/sZ1ZOuaNWI9PnKa/3WYbE9xjnVVYWhVYYXFD38xLJWFEF7zmyl", + }, + }, + } + + sink := common.NewZeroCopySink(nil) + err := paramSerialize.Serialization(sink) + assert.Nil(t, err) + + paramDeserialize := new(NeoCrossChainMsg) + err = paramDeserialize.Deserialization(common.NewZeroCopySource(sink.Bytes())) + assert.Nil(t, err) + assert.Equal(t, paramDeserialize, paramSerialize) +} diff --git a/native/service/header_sync/neo3/utils.go b/native/service/header_sync/neo3/utils.go new file mode 100644 index 000000000..5d710ad06 --- /dev/null +++ b/native/service/header_sync/neo3/utils.go @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2020 The poly network Authors + * This file is part of The poly network library. + * + * The poly network is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The poly network is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The poly network . If not, see . + */ + +package neo3 + +import ( + "encoding/hex" + "fmt" + "github.com/joeqian10/neo3-gogogo/tx" + "github.com/polynetwork/poly/common" + cstates "github.com/polynetwork/poly/core/states" + "github.com/polynetwork/poly/native" + hscommon "github.com/polynetwork/poly/native/service/header_sync/common" + "github.com/polynetwork/poly/native/service/utils" +) + +//verify header of any height +//find key height and get neoconsensus first, then check the witness +func verifyHeader(native *native.NativeService, chainID uint64, header *NeoBlockHeader) error { + neoConsensus, err := getConsensusValByChainId(native, chainID) + if err != nil { + return fmt.Errorf("verifyHeader, get Consensus error: %s", err) + } + if neoConsensus.NextConsensus != header.Witness.GetScriptHash() { + return fmt.Errorf("verifyHeader, invalid script hash in header error, expected: %s, got: %s", neoConsensus.NextConsensus.String(), header.Witness.GetScriptHash().String()) + } + + msg, err := header.GetMessage() + if err != nil { + return fmt.Errorf("verifyHeader, unable to get hash data of header") + } + if verified := tx.VerifyMultiSignatureWitness(msg, header.Witness); !verified { + return fmt.Errorf("verifyHeader, VerifyMultiSignatureWitness error: %s, height: %d", err, header.GetIndex()) + } + return nil +} + +func VerifyCrossChainMsgSig(native *native.NativeService, chainID uint64, crossChainMsg *NeoCrossChainMsg) error { + neoConsensus, err := getConsensusValByChainId(native, chainID) + if err != nil { + return fmt.Errorf("verifyCrossChainMsg, get ConsensusPeer error: %v", err) + } + crossChainMsgConsensus, err := crossChainMsg.GetScriptHash() + if err != nil { + return fmt.Errorf("verifyCrossChainMsg, getScripthash error: %v", err) + } + if neoConsensus.NextConsensus != crossChainMsgConsensus { + return fmt.Errorf("verifyCrossChainMsg, invalid script hash in NeoCrossChainMsg error, expected: %s, got: %s", neoConsensus.NextConsensus.String(), crossChainMsgConsensus.String()) + } + msg, err := crossChainMsg.GetMessage() + if err != nil { + return fmt.Errorf("verifyCrossChainMsg, unable to get unsigned message of neo crossChainMsg") + } + invScript, _ := hex.DecodeString(crossChainMsg.Witness.Invocation) + verScript, _ := hex.DecodeString(crossChainMsg.Witness.Verification) + witness := &tx.Witness{ + InvocationScript: invScript, + VerificationScript: verScript, + } + if verified := tx.VerifyMultiSignatureWitness(msg, witness); !verified { + return fmt.Errorf("verifyCrossChainMsg, VerifyMultiSignatureWitness error: %s, height: %d", "verification failed", crossChainMsg.Index) + } + return nil +} + +func getConsensusValByChainId(native *native.NativeService, chainID uint64) (*NeoConsensus, error) { + contract := utils.HeaderSyncContractAddress + chainIDBytes := utils.GetUint64Bytes(chainID) + neoConsensusStore, err := native.GetCacheDB().Get(utils.ConcatKey(contract, []byte(hscommon.CONSENSUS_PEER), chainIDBytes)) + if err != nil { + return nil, fmt.Errorf("getNextConsensusByHeight, get nextConsensusStore error: %v", err) + } + if neoConsensusStore == nil { + return nil, fmt.Errorf("getNextConsensusByHeight, can not find any record") + } + neoConsensusBytes, err := cstates.GetValueFromRawStorageItem(neoConsensusStore) + if err != nil { + return nil, fmt.Errorf("getConsensusPeerByHeight, deserialize from raw storage item err: %v", err) + } + neoConsensus := new(NeoConsensus) + if err := neoConsensus.Deserialization(common.NewZeroCopySource(neoConsensusBytes)); err != nil { + return nil, fmt.Errorf("getConsensusPeerByHeight, deserialize consensusPeer error: %v", err) + } + return neoConsensus, nil +} + +func putConsensusValByChainId(native *native.NativeService, neoConsensus *NeoConsensus) error { + contract := utils.HeaderSyncContractAddress + sink := common.NewZeroCopySink(nil) + neoConsensus.Serialization(sink) + chainIDBytes := utils.GetUint64Bytes(neoConsensus.ChainID) + native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(hscommon.CONSENSUS_PEER), chainIDBytes), cstates.GenRawStorageItem(sink.Bytes())) + return nil +} diff --git a/native/service/utils/params.go b/native/service/utils/params.go index 21deadbdb..85ef9370d 100644 --- a/native/service/utils/params.go +++ b/native/service/utils/params.go @@ -48,4 +48,5 @@ var ( QUORUM_ROUTER = uint64(8) ZILLIQA_ROUTER = uint64(9) MSC_ROUTER = uint64(10) + NEO3_ROUTER = uint64(11) ) From 067ba90f82b4fa2cdda63c2b46b57f3c76fcfa9c Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Wed, 21 Apr 2021 15:22:01 +0800 Subject: [PATCH 04/23] fix neo3 header deserialization, rename structs --- .../cross_chain_manager/neo3/neo_handler.go | 10 +++--- .../neo3/neo_handler_test.go | 8 ++--- .../service/header_sync/neo3/header_sync.go | 34 ++++++++++--------- .../header_sync/neo3/header_sync_test.go | 16 ++++----- native/service/header_sync/neo3/states.go | 2 +- .../service/header_sync/neo3/states_test.go | 12 ++++--- 6 files changed, 44 insertions(+), 38 deletions(-) diff --git a/native/service/cross_chain_manager/neo3/neo_handler.go b/native/service/cross_chain_manager/neo3/neo_handler.go index 878dbc935..f3bae9322 100644 --- a/native/service/cross_chain_manager/neo3/neo_handler.go +++ b/native/service/cross_chain_manager/neo3/neo_handler.go @@ -27,15 +27,15 @@ import ( "github.com/polynetwork/poly/native/service/header_sync/neo3" ) -type NEOHandler struct { +type Neo3Handler struct { ccmcId *int } -func NewNEOHandler() *NEOHandler { - return &NEOHandler{} +func NewNeo3Handler() *Neo3Handler { + return &Neo3Handler{} } -func (this *NEOHandler) MakeDepositProposal(service *native.NativeService) (*scom.MakeTxParam, error) { +func (this *Neo3Handler) MakeDepositProposal(service *native.NativeService) (*scom.MakeTxParam, error) { params := new(scom.EntranceParam) if err := params.Deserialization(common.NewZeroCopySource(service.GetInput())); err != nil { return nil, fmt.Errorf("neo3 MakeDepositProposal, contract params deserialize error: %v", err) @@ -74,7 +74,7 @@ func (this *NEOHandler) MakeDepositProposal(service *native.NativeService) (*sco return value, nil } -func (this *NEOHandler) SetCcmcId(idBytes []byte) { +func (this *Neo3Handler) SetCcmcId(idBytes []byte) { id := int(int32(helper.BytesToUInt32(idBytes))) this.ccmcId = &id } diff --git a/native/service/cross_chain_manager/neo3/neo_handler_test.go b/native/service/cross_chain_manager/neo3/neo_handler_test.go index 053f38c99..80a943d27 100644 --- a/native/service/cross_chain_manager/neo3/neo_handler_test.go +++ b/native/service/cross_chain_manager/neo3/neo_handler_test.go @@ -50,8 +50,8 @@ var ( service, _ := native.NewNativeService(cacheDB, new(types.Transaction), 0, 200, common.Uint256{}, 0, nil, false) return service } - getNeoHanderFunc = func() *NEOHandler { - return NewNEOHandler() + getNeoHanderFunc = func() *Neo3Handler { + return NewNeo3Handler() } setBKers = func() { genesis.GenesisBookkeepers = []keypair.PublicKey{acct.PublicKey} @@ -122,7 +122,7 @@ func Test_Neo_MakeDepositProposal(t *testing.T) { } native = NewNative(sink.Bytes(), tx, nil) - neoHandler := neo3.NewNEOHandler() + neoHandler := neo3.NewNeo3Handler() err = neoHandler.SyncGenesisHeader(native) assert.NoError(t, err) } @@ -151,7 +151,7 @@ func Test_Neo_MakeDepositProposal(t *testing.T) { } native = NewNative(sink.Bytes(), tx, native.GetCacheDB()) - neoHandler := NewNEOHandler() + neoHandler := NewNeo3Handler() SetContract(native, "b0d4f20da68a6007d4fb7eac374b5566a5b0e229") _, err = neoHandler.MakeDepositProposal(native) assert.Nil(t, err) diff --git a/native/service/header_sync/neo3/header_sync.go b/native/service/header_sync/neo3/header_sync.go index 3914df179..739a03d1b 100644 --- a/native/service/header_sync/neo3/header_sync.go +++ b/native/service/header_sync/neo3/header_sync.go @@ -27,33 +27,35 @@ import ( "github.com/polynetwork/poly/native/service/utils" ) -type NEOHandler struct { +type Neo3Handler struct { } -func NewNEOHandler() *NEOHandler { - return &NEOHandler{} +func NewNeo3Handler() *Neo3Handler { + return &Neo3Handler{} } -func (this *NEOHandler) SyncGenesisHeader(native *native.NativeService) error { +func (this *Neo3Handler) SyncGenesisHeader(native *native.NativeService) error { params := new(hscommon.SyncGenesisHeaderParam) if err := params.Deserialization(common.NewZeroCopySource(native.GetInput())); err != nil { - return fmt.Errorf("NeoHandler SyncGenesisHeader, contract params deserialize error: %v", err) + return fmt.Errorf("Neo3Handler SyncGenesisHeader, contract params deserialize error: %v", err) } // Get current epoch operator operatorAddress, err := node_manager.GetCurConOperator(native) if err != nil { - return fmt.Errorf("NeoHandler SyncGenesisHeader, get current consensus operator address error: %v", err) + return fmt.Errorf("Neo3Handler SyncGenesisHeader, get current consensus operator address error: %v", err) } //check witness err = utils.ValidateOwner(native, operatorAddress) if err != nil { - return fmt.Errorf("NeoHandler SyncGenesisHeader, checkWitness error: %v", err) + return fmt.Errorf("Neo3Handler SyncGenesisHeader, checkWitness error: %v", err) } // Deserialize neo block header + header := new(NeoBlockHeader) if err := header.Deserialization(common.NewZeroCopySource(params.GenesisHeader)); err != nil { - return fmt.Errorf("NeoHandler SyncGenesisHeader, deserialize header err: %v", err) + return fmt.Errorf("Neo3Handler SyncGenesisHeader, deserialize header err: %v", err) } + if neoConsensus, _ := getConsensusValByChainId(native, params.ChainID); neoConsensus == nil { // Put NeoConsensus.NextConsensus into storage if err = putConsensusValByChainId(native, &NeoConsensus{ @@ -61,30 +63,30 @@ func (this *NEOHandler) SyncGenesisHeader(native *native.NativeService) error { Height: header.GetIndex(), NextConsensus: header.GetNextConsensus(), }); err != nil { - return fmt.Errorf("NeoHandler SyncGenesisHeader, update ConsensusPeer error: %v", err) + return fmt.Errorf("Neo3Handler SyncGenesisHeader, update ConsensusPeer error: %v", err) } } return nil } -func (this *NEOHandler) SyncBlockHeader(native *native.NativeService) error { +func (this *Neo3Handler) SyncBlockHeader(native *native.NativeService) error { params := new(hscommon.SyncBlockHeaderParam) if err := params.Deserialization(common.NewZeroCopySource(native.GetInput())); err != nil { - return fmt.Errorf("SyncBlockHeader, contract params deserialize error: %v", err) + return fmt.Errorf("Neo3Handler SyncBlockHeader, contract params deserialize error: %v", err) } neoConsensus, err := getConsensusValByChainId(native, params.ChainID) if err != nil { - return fmt.Errorf("SyncBlockHeader, the consensus validator has not been initialized, chainId: %d", params.ChainID) + return fmt.Errorf("Neo3Handler SyncBlockHeader, the consensus validator has not been initialized, chainId: %d", params.ChainID) } var newNeoConsensus *NeoConsensus for _, v := range params.Headers { header := new(NeoBlockHeader) if err := header.Deserialization(common.NewZeroCopySource(v)); err != nil { - return fmt.Errorf("SyncBlockHeader, NeoBlockHeaderFromBytes error: %v", err) + return fmt.Errorf("Neo3Handler SyncBlockHeader, NeoBlockHeaderFromBytes error: %v", err) } if !header.GetNextConsensus().Equals(neoConsensus.NextConsensus) && header.GetIndex() > neoConsensus.Height { if err = verifyHeader(native, params.ChainID, header); err != nil { - return fmt.Errorf("SyncBlockHeader, verifyHeader error: %v", err) + return fmt.Errorf("Neo3Handler SyncBlockHeader, verifyHeader error: %v", err) } newNeoConsensus = &NeoConsensus{ ChainID: neoConsensus.ChainID, @@ -95,12 +97,12 @@ func (this *NEOHandler) SyncBlockHeader(native *native.NativeService) error { } if newNeoConsensus != nil { if err = putConsensusValByChainId(native, newNeoConsensus); err != nil { - return fmt.Errorf("SyncBlockHeader, update ConsensusPeer error: %v", err) + return fmt.Errorf("Neo3Handler SyncBlockHeader, update ConsensusPeer error: %v", err) } } return nil } -func (this *NEOHandler) SyncCrossChainMsg(native *native.NativeService) error { +func (this *Neo3Handler) SyncCrossChainMsg(native *native.NativeService) error { return nil } diff --git a/native/service/header_sync/neo3/header_sync_test.go b/native/service/header_sync/neo3/header_sync_test.go index 085f1e150..7f89611b8 100644 --- a/native/service/header_sync/neo3/header_sync_test.go +++ b/native/service/header_sync/neo3/header_sync_test.go @@ -48,8 +48,8 @@ var ( service, _ := native.NewNativeService(cacheDB, new(types.Transaction), 0, 200, common.Uint256{}, 0, nil, false) return service } - getNeoHanderFunc = func() *NEOHandler { - return NewNEOHandler() + getNeoHanderFunc = func() *Neo3Handler { + return NewNeo3Handler() } setBKers = func() { genesis.GenesisBookkeepers = []keypair.PublicKey{acct.PublicKey} @@ -78,7 +78,7 @@ func TestSyncGenesisHeader(t *testing.T) { InvocationScript: []byte{}, VerificationScript: vs, } - genesisHeader := &NeoBlockHeader{Header: new(block.Header)} + genesisHeader := &NeoBlockHeader{Header: block.NewBlockHeader()} genesisHeader.SetVersion(0) genesisHeader.SetPrevHash(prevHash) genesisHeader.SetMerkleRoot(merkleRoot) @@ -104,7 +104,7 @@ func TestSyncGenesisHeader(t *testing.T) { //cdb := new(storage.CacheDB) //cdb.Put() native := NewNative(sink.Bytes(), tx, nil) - neoHandler := NewNEOHandler() + neoHandler := NewNeo3Handler() err = neoHandler.SyncGenesisHeader(native) assert.NoError(t, err) } @@ -119,7 +119,7 @@ func TestSyncBlockHeader(t *testing.T) { InvocationScript: is, VerificationScript: vs, } - genesisHeader := &NeoBlockHeader{Header: new(block.Header)} + genesisHeader := &NeoBlockHeader{Header: block.NewBlockHeader()} genesisHeader.SetVersion(0) genesisHeader.SetPrevHash(prevHash) genesisHeader.SetMerkleRoot(merkleRoot) @@ -143,7 +143,7 @@ func TestSyncBlockHeader(t *testing.T) { InvocationScript: is, VerificationScript: vs, } - neoHeader100 := &NeoBlockHeader{Header: new(block.Header)} + neoHeader100 := &NeoBlockHeader{Header: block.NewBlockHeader()} neoHeader100.SetVersion(0) neoHeader100.SetPrevHash(prevHash) neoHeader100.SetMerkleRoot(merkleRoot) @@ -168,7 +168,7 @@ func TestSyncBlockHeader(t *testing.T) { InvocationScript: is, VerificationScript: vs, } - neoHeader200 := &NeoBlockHeader{Header: new(block.Header)} + neoHeader200 := &NeoBlockHeader{Header: block.NewBlockHeader()} neoHeader200.SetVersion(0) neoHeader200.SetPrevHash(prevHash) neoHeader200.SetMerkleRoot(merkleRoot) @@ -183,7 +183,7 @@ func TestSyncBlockHeader(t *testing.T) { } neoHeader200bs := sink.Bytes() - neoHandler := NewNEOHandler() + neoHandler := NewNeo3Handler() var native *native.NativeService { param := new(scom.SyncGenesisHeaderParam) diff --git a/native/service/header_sync/neo3/states.go b/native/service/header_sync/neo3/states.go index 5cbd7dc1d..961226a07 100644 --- a/native/service/header_sync/neo3/states.go +++ b/native/service/header_sync/neo3/states.go @@ -62,7 +62,7 @@ type NeoBlockHeader struct { } func (this *NeoBlockHeader) Deserialization(source *common.ZeroCopySource) error { - this.Header = new(block.Header) + this.Header = block.NewBlockHeader() br := io.NewBinaryReaderFromBuf(source.Bytes()) this.Header.Deserialize(br) if br.Err != nil { diff --git a/native/service/header_sync/neo3/states_test.go b/native/service/header_sync/neo3/states_test.go index 93d352feb..37953712e 100644 --- a/native/service/header_sync/neo3/states_test.go +++ b/native/service/header_sync/neo3/states_test.go @@ -18,8 +18,10 @@ package neo3 import ( + "github.com/joeqian10/neo3-gogogo/block" "github.com/joeqian10/neo3-gogogo/crypto" "github.com/joeqian10/neo3-gogogo/rpc/models" + "log" "testing" "github.com/joeqian10/neo3-gogogo/helper" @@ -49,12 +51,12 @@ func Test_NeoBlockHeader_Serialization(t *testing.T) { prevHash, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") merkleRoot, _ := helper.UInt256FromString("0x0000000000000000000000000000000000000000000000000000000000000000") nextConsensus, _ := crypto.AddressToScriptHash("NVg7LjGcUSrgxgjX3zEgqaksfMaiS8Z6e1", helper.DefaultAddressVersion) - vs, _ := crypto.Base64Decode("EQ==") + //vs, _ := crypto.Base64Decode("EQ==") witness := tx2.Witness{ InvocationScript: []byte{}, - VerificationScript: vs, + VerificationScript: []byte{}, } - genesisHeader := &NeoBlockHeader{} + genesisHeader := block.NewBlockHeader() genesisHeader.SetVersion(0) genesisHeader.SetPrevHash(prevHash) genesisHeader.SetMerkleRoot(merkleRoot) @@ -64,11 +66,13 @@ func Test_NeoBlockHeader_Serialization(t *testing.T) { genesisHeader.SetNextConsensus(nextConsensus) genesisHeader.SetWitnesses([]tx2.Witness{witness}) paramSerialize := new(NeoBlockHeader) - paramSerialize.Header = genesisHeader.Header + paramSerialize.Header = genesisHeader sink := common.NewZeroCopySink(nil) err := paramSerialize.Serialization(sink) assert.Nil(t, err) + log.Println(helper.BytesToHex(sink.Bytes())) + paramDeserialize := new(NeoBlockHeader) err = paramDeserialize.Deserialization(common.NewZeroCopySource(sink.Bytes())) assert.Nil(t, err) From 9a36e38796234ae102f1f71142d334d6dfb7719b Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Wed, 21 Apr 2021 15:35:18 +0800 Subject: [PATCH 05/23] fix --- native/service/cross_chain_manager/entrance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/service/cross_chain_manager/entrance.go b/native/service/cross_chain_manager/entrance.go index 74632490e..b0b040741 100644 --- a/native/service/cross_chain_manager/entrance.go +++ b/native/service/cross_chain_manager/entrance.go @@ -67,7 +67,7 @@ func GetChainHandler(router uint64) (scom.ChainHandler, error) { case utils.NEO_ROUTER: return neo.NewNEOHandler(), nil case utils.NEO3_ROUTER: - return neo3.NewNEOHandler(), nil + return neo3.NewNeo3Handler(), nil case utils.COSMOS_ROUTER: return cosmos.NewCosmosHandler(), nil case utils.QUORUM_ROUTER: From 4f959ccf23493a8c618ebaa12f9d0ffc0dbbc2f4 Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Wed, 21 Apr 2021 15:41:18 +0800 Subject: [PATCH 06/23] fix 2 --- native/service/header_sync/entrance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/service/header_sync/entrance.go b/native/service/header_sync/entrance.go index a4ee39868..a769ca42c 100644 --- a/native/service/header_sync/entrance.go +++ b/native/service/header_sync/entrance.go @@ -63,7 +63,7 @@ func GetChainHandler(router uint64) (hscommon.HeaderSyncHandler, error) { case utils.NEO_ROUTER: return neo.NewNEOHandler(), nil case utils.NEO3_ROUTER: - return neo3.NewNEOHandler(), nil + return neo3.NewNeo3Handler(), nil case utils.COSMOS_ROUTER: return cosmos.NewCosmosHandler(), nil case utils.QUORUM_ROUTER: From 437aa38883cdcc7f8d81a28e2f85f97a302d2c65 Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Thu, 29 Apr 2021 16:48:11 +0800 Subject: [PATCH 07/23] fix neoCrossChainMsg --- go.mod | 2 +- native/service/header_sync/neo3/states.go | 5 ++++- native/service/header_sync/neo3/utils.go | 13 +++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 3a0ef9f8d..9e714a4fb 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c github.com/itchyny/base58-go v0.1.0 github.com/joeqian10/neo-gogogo v1.1.0 - github.com/joeqian10/neo3-gogogo v0.2.4 + github.com/joeqian10/neo3-gogogo v0.3.2 github.com/ontio/ontology v1.11.0 github.com/ontio/ontology-crypto v1.0.9 github.com/ontio/ontology-eventbus v0.9.1 diff --git a/native/service/header_sync/neo3/states.go b/native/service/header_sync/neo3/states.go index 961226a07..c766998a6 100644 --- a/native/service/header_sync/neo3/states.go +++ b/native/service/header_sync/neo3/states.go @@ -115,7 +115,10 @@ func (this *NeoCrossChainMsg) Serialization(sink *common.ZeroCopySink) error { } func (this *NeoCrossChainMsg) GetScriptHash() (*helper.UInt160, error) { - verificationScriptBs, err := crypto.Base64Decode(this.Witness.Verification) // base64 + if len(this.Witnesses) == 0 { + return nil, fmt.Errorf("NeoCrossChainMsg.Witness incorrect length") + } + verificationScriptBs, err := crypto.Base64Decode(this.Witnesses[0].Verification) // base64 if err != nil { return nil, fmt.Errorf("NeoCrossChainMsg.Witness.Verification decode error: %s", err) } diff --git a/native/service/header_sync/neo3/utils.go b/native/service/header_sync/neo3/utils.go index 5d710ad06..a6976bb71 100644 --- a/native/service/header_sync/neo3/utils.go +++ b/native/service/header_sync/neo3/utils.go @@ -65,14 +65,19 @@ func VerifyCrossChainMsgSig(native *native.NativeService, chainID uint64, crossC if err != nil { return fmt.Errorf("verifyCrossChainMsg, unable to get unsigned message of neo crossChainMsg") } - invScript, _ := hex.DecodeString(crossChainMsg.Witness.Invocation) - verScript, _ := hex.DecodeString(crossChainMsg.Witness.Verification) + if len(crossChainMsg.Witnesses) == 0 { + return fmt.Errorf("verifyCrossChainMsg, incorrect witness length") + } + invScript, _ := hex.DecodeString(crossChainMsg.Witnesses[0].Invocation) + verScript, _ := hex.DecodeString(crossChainMsg.Witnesses[0].Verification) witness := &tx.Witness{ InvocationScript: invScript, VerificationScript: verScript, } - if verified := tx.VerifyMultiSignatureWitness(msg, witness); !verified { - return fmt.Errorf("verifyCrossChainMsg, VerifyMultiSignatureWitness error: %s, height: %d", "verification failed", crossChainMsg.Index) + v1 := tx.VerifyMultiSignatureWitness(msg, witness) + v2 := tx.VerifySignatureWitness(msg, witness) + if !v1 && !v2 { + return fmt.Errorf("verifyCrossChainMsg, verify witness failed, height: %d", crossChainMsg.Index) } return nil } From 474879d3ddcde85a1f525845a08374a8a2b1ec3a Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Thu, 13 May 2021 14:10:19 +0800 Subject: [PATCH 08/23] add neo3 state validator manager --- .../cross_chain_manager/neo3/neo_handler.go | 7 +- .../neo3/neo_handler_test.go | 6 +- .../neo3_state_manager/neo3_state_manager.go | 158 +++++++++ .../neo3_state_manager_test.go | 302 ++++++++++++++++++ .../governance/neo3_state_manager/param.go | 75 +++++ .../neo3_state_manager/param_test.go | 25 ++ .../governance/neo3_state_manager/utils.go | 277 ++++++++++++++++ native/service/header_sync/neo3/utils.go | 34 +- native/service/init.go | 2 + native/service/utils/params.go | 3 +- 10 files changed, 879 insertions(+), 10 deletions(-) create mode 100644 native/service/governance/neo3_state_manager/neo3_state_manager.go create mode 100644 native/service/governance/neo3_state_manager/neo3_state_manager_test.go create mode 100644 native/service/governance/neo3_state_manager/param.go create mode 100644 native/service/governance/neo3_state_manager/param_test.go create mode 100644 native/service/governance/neo3_state_manager/utils.go diff --git a/native/service/cross_chain_manager/neo3/neo_handler.go b/native/service/cross_chain_manager/neo3/neo_handler.go index f3bae9322..95c751e7d 100644 --- a/native/service/cross_chain_manager/neo3/neo_handler.go +++ b/native/service/cross_chain_manager/neo3/neo_handler.go @@ -45,6 +45,7 @@ func (this *Neo3Handler) MakeDepositProposal(service *native.NativeService) (*sc if err := crossChainMsg.Deserialization(common.NewZeroCopySource(params.HeaderOrCrossChainMsg)); err != nil { return nil, fmt.Errorf("neo3 MakeDepositProposal, deserialize crossChainMsg error: %v", err) } + if err := neo3.VerifyCrossChainMsgSig(service, params.SourceChainID, crossChainMsg); err != nil { return nil, fmt.Errorf("neo3 MakeDepositProposal, VerifyCrossChainMsg error: %v", err) } @@ -54,8 +55,10 @@ func (this *Neo3Handler) MakeDepositProposal(service *native.NativeService) (*sc return nil, fmt.Errorf("neo3 MakeDepositProposal, side_chain_manager.GetSideChain error: %v", err) } - // convert neo contract address bytes to id, it is different from other chains, it stores int in a []byte, contract id can be get from "getcontractstate" api - // todo, when register neo N3, convert ccmc id to []byte; native contracts have negative ids, while custom contracts have positive ones + // todo, review code, when register neo N3, convert ccmc id to []byte + // convert neo3 contract address bytes to id, it is different from other chains + // need to store int in a []byte, contract id can be get from "getcontractstate" api + // neo3 native contracts have negative ids, while custom contracts have positive ones if this.ccmcId == nil { this.SetCcmcId(sideChain.CCMCAddress) } diff --git a/native/service/cross_chain_manager/neo3/neo_handler_test.go b/native/service/cross_chain_manager/neo3/neo_handler_test.go index 80a943d27..4b3bae11e 100644 --- a/native/service/cross_chain_manager/neo3/neo_handler_test.go +++ b/native/service/cross_chain_manager/neo3/neo_handler_test.go @@ -160,9 +160,11 @@ func Test_Neo_MakeDepositProposal(t *testing.T) { func TestNEOHandler_SetCcmcId(t *testing.T) { // test positive int - idp := 5 + idp := 215 idpBytes := helper.IntToBytes(idp) - log.Println(helper.BytesToHex(idpBytes)) + ss := helper.BytesToHex(idpBytes) + log.Println(ss) + assert.Equal(t, "d7000000", ss) idp2 := int(helper.BytesToUInt32(idpBytes)) assert.Equal(t, idp, idp2) diff --git a/native/service/governance/neo3_state_manager/neo3_state_manager.go b/native/service/governance/neo3_state_manager/neo3_state_manager.go new file mode 100644 index 000000000..f6247d836 --- /dev/null +++ b/native/service/governance/neo3_state_manager/neo3_state_manager.go @@ -0,0 +1,158 @@ +package neo3_state_manager + +import ( + "fmt" + "github.com/polynetwork/poly/common" + "github.com/polynetwork/poly/native" + "github.com/polynetwork/poly/native/event" + "github.com/polynetwork/poly/native/service/governance/node_manager" + "github.com/polynetwork/poly/native/service/utils" +) + +const ( + //function name + GET_CURRENT_STATE_VALIDATOR = "getCurrentStateValidator" + REGISTER_STATE_VALIDATOR = "registerStateValidator" + APPROVE_REGISTER_STATE_VALIDATOR = "approveRegisterStateValidator" + REMOVE_STATE_VALIDATOR = "removeStateValidator" + APPROVE_REMOVE_STATE_VALIDATOR = "approveRemoveStateValidator" + + //key prefix + STATE_VALIDATOR = "stateValidator" + STATE_VALIDATOR_APPLY = "stateValidatorApply" + STATE_VALIDATOR_REMOVE = "stateValidatorRemove" + STATE_VALIDATOR_APPLY_ID = "stateValidatorApplyID" + STATE_VALIDATOR_REMOVE_ID = "stateValidatorRemoveID" +) + +// todo, review code + +func GetCurrentStateValidator(native *native.NativeService) ([]byte, error) { + svs, err := getStateValidators(native) + if err != nil { + return utils.BYTE_FALSE, fmt.Errorf("GetCurrentStateValidator, getStateValidators error: %v", err) + } + data := SerializeStringArray(svs) + return data, nil +} + +//Register methods of node_manager contract +func RegisterStateValidatorManagerContract(native *native.NativeService) { + native.Register(GET_CURRENT_STATE_VALIDATOR, GetCurrentStateValidator) + native.Register(REGISTER_STATE_VALIDATOR, RegisterStateValidator) + native.Register(APPROVE_REGISTER_STATE_VALIDATOR, ApproveRegisterStateValidator) + native.Register(REMOVE_STATE_VALIDATOR, RemoveStateValidator) + native.Register(APPROVE_REMOVE_STATE_VALIDATOR, ApproveRemoveStateValidator) +} + +func RegisterStateValidator(native *native.NativeService) ([]byte, error) { + params := new(StateValidatorListParam) + if err := params.Deserialization(common.NewZeroCopySource(native.GetInput())); err != nil { + return utils.BYTE_FALSE, fmt.Errorf("RegisterStateValidator, params.Deserialization error: %v", err) + } + //check witness + if err := utils.ValidateOwner(native, params.Address); err != nil { + return utils.BYTE_FALSE, fmt.Errorf("RegisterStateValidator, checkWitness: %s, error: %v", params.Address.ToBase58(), err) + } + if err := putStateValidatorApply(native, params); err != nil { + return utils.BYTE_FALSE, fmt.Errorf("RegisterStateValidator, putStateValidatorApply error: %v", err) + } + return utils.BYTE_TRUE, nil +} + +func ApproveRegisterStateValidator(native *native.NativeService) ([]byte, error) { + params := new(ApproveStateValidatorParam) + if err := params.Deserialization(common.NewZeroCopySource(native.GetInput())); err != nil { + return utils.BYTE_FALSE, fmt.Errorf("ApproveRegisterStateValidator, contract params deserialize error: %v", err) + } + + //check witness + err := utils.ValidateOwner(native, params.Address) + if err != nil { + return utils.BYTE_FALSE, fmt.Errorf("ApproveRegisterStateValidator, checkWitness error: %v", err) + } + + svListParam, err := getStateValidatorApply(native, params.ID) + if err != nil { + return utils.BYTE_FALSE, fmt.Errorf("ApproveRegisterStateValidator, getStateValidatorApply error: %v", err) + } + + //check consensus signs + ok, err := node_manager.CheckConsensusSigns(native, APPROVE_REGISTER_STATE_VALIDATOR, utils.GetUint64Bytes(params.ID), params.Address) + if err != nil { + return utils.BYTE_FALSE, fmt.Errorf("ApproveRegisterStateValidator, CheckConsensusSigns error: %v", err) + } + if !ok { + return utils.BYTE_FALSE, nil + } + + // put all the state validators in storage + err = putStateValidators(native, svListParam.StateValidators) + if err != nil { + return utils.BYTE_FALSE, fmt.Errorf("ApproveRegisterStateValidator, putStateValidators error: %v", err) + } + + native.GetCacheDB().Delete(utils.ConcatKey(utils.Neo3StateManagerContractAddress, []byte(STATE_VALIDATOR_APPLY), utils.GetUint64Bytes(params.ID))) + native.AddNotify( + &event.NotifyEventInfo{ + ContractAddress: utils.Neo3StateManagerContractAddress, + States: []interface{}{"ApproveRegisterStateValidator", params.ID}, + }) + return utils.BYTE_TRUE, nil +} + +func RemoveStateValidator(native *native.NativeService) ([]byte, error) { + params := new(StateValidatorListParam) + if err := params.Deserialization(common.NewZeroCopySource(native.GetInput())); err != nil { + return utils.BYTE_FALSE, fmt.Errorf("RemoveStateValidator, contract params deserialize error: %v", err) + } + //check witness + if err := utils.ValidateOwner(native, params.Address); err != nil { + return utils.BYTE_FALSE, fmt.Errorf("RemoveStateValidator, checkWitness: %s, error: %v", params.Address.ToBase58(), err) + } + err := putStateValidatorRemove(native, params) + if err != nil { + return utils.BYTE_FALSE, fmt.Errorf("RemoveStateValidator, putStateValidatorRemove error: %v", err) + } + return utils.BYTE_TRUE, nil +} + +func ApproveRemoveStateValidator(native *native.NativeService) ([]byte, error) { + params := new(ApproveStateValidatorParam) + if err := params.Deserialization(common.NewZeroCopySource(native.GetInput())); err != nil { + return utils.BYTE_FALSE, fmt.Errorf("ApproveRemoveStateValidator, contract params deserialize error: %v", err) + } + + //check witness + err := utils.ValidateOwner(native, params.Address) + if err != nil { + return utils.BYTE_FALSE, fmt.Errorf("ApproveRemoveStateValidator, checkWitness error: %v", err) + } + + svListParam, err := getStateValidatorRemove(native, params.ID) + if err != nil { + return utils.BYTE_FALSE, fmt.Errorf("ApproveRemoveStateValidator, getStateValidatorRemove error: %v", err) + } + + //check consensus signs + ok, err := node_manager.CheckConsensusSigns(native, APPROVE_REMOVE_STATE_VALIDATOR, utils.GetUint64Bytes(params.ID), params.Address) + if err != nil { + return utils.BYTE_FALSE, fmt.Errorf("ApproveRemoveStateValidator, CheckConsensusSigns error: %v", err) + } + if !ok { + return utils.BYTE_FALSE, nil + } + + // remove svs + err = removeStateValidators(native, svListParam.StateValidators) + if err != nil { + return utils.BYTE_FALSE, fmt.Errorf("ApproveRemoveStateValidator, removeStateValidators error: %v", err) + } + + native.AddNotify( + &event.NotifyEventInfo{ + ContractAddress: utils.Neo3StateManagerContractAddress, + States: []interface{}{"ApproveRemoveStateValidator", params.ID}, + }) + return utils.BYTE_TRUE, nil +} diff --git a/native/service/governance/neo3_state_manager/neo3_state_manager_test.go b/native/service/governance/neo3_state_manager/neo3_state_manager_test.go new file mode 100644 index 000000000..7a928184f --- /dev/null +++ b/native/service/governance/neo3_state_manager/neo3_state_manager_test.go @@ -0,0 +1,302 @@ +package neo3_state_manager + +import ( + "github.com/ontio/ontology-crypto/keypair" + "github.com/polynetwork/poly/account" + "github.com/polynetwork/poly/common" + vconfig "github.com/polynetwork/poly/consensus/vbft/config" + "github.com/polynetwork/poly/core/genesis" + cstates "github.com/polynetwork/poly/core/states" + "github.com/polynetwork/poly/core/store/leveldbstore" + "github.com/polynetwork/poly/core/store/overlaydb" + "github.com/polynetwork/poly/core/types" + "github.com/polynetwork/poly/native" + "github.com/polynetwork/poly/native/service/governance/node_manager" + "github.com/polynetwork/poly/native/service/utils" + "github.com/polynetwork/poly/native/storage" + "github.com/stretchr/testify/assert" + "log" + "strconv" + "testing" +) + +var ( + acct = account.NewAccount("") + conAccts = func() []*account.Account { + accts := make([]*account.Account, 0) + for i := 0; i < 7; i++ { + accts = append(accts, account.NewAccount(strconv.FormatUint(uint64(i), 10))) + } + return accts + } + getNativeFunc = func() *native.NativeService { + store, _ := + leveldbstore.NewMemLevelDBStore() + cacheDB := storage.NewCacheDB(overlaydb.NewOverlayDB(store)) + ns, _ := native.NewNativeService(cacheDB, new(types.Transaction), 0, 200, common.Uint256{}, 0, nil, false) + return ns + } + + setBKers = func() { + genesis.GenesisBookkeepers = []keypair.PublicKey{acct.PublicKey} + } + + nativeService *native.NativeService +) + +func init() { + setBKers() +} +func putPeerMapPoolAndView(db *storage.CacheDB, conAccts []*account.Account) { + peerPoolMap := new(node_manager.PeerPoolMap) + peerPoolMap.PeerPoolMap = make(map[string]*node_manager.PeerPoolItem) + for i, conAcct := range conAccts { + pkStr := vconfig.PubkeyID(conAcct.PublicKey) + peerPoolMap.PeerPoolMap[pkStr] = &node_manager.PeerPoolItem{ + Index: uint32(i), + PeerPubkey: pkStr, + Address: conAcct.Address, + Status: node_manager.ConsensusStatus, + } + } + viewBytes := utils.GetUint32Bytes(0) + sink := common.NewZeroCopySink(nil) + peerPoolMap.Serialization(sink) + db.Put(utils.ConcatKey(utils.NodeManagerContractAddress, []byte(node_manager.PEER_POOL), viewBytes), cstates.GenRawStorageItem(sink.Bytes())) + + govView := node_manager.GovernanceView{ + 0, 10, common.UINT256_EMPTY, + } + sink = common.NewZeroCopySink(nil) + govView.Serialization(sink) + db.Put(utils.ConcatKey(utils.NodeManagerContractAddress, []byte(node_manager.GOVERNANCE_VIEW)), cstates.GenRawStorageItem(sink.Bytes())) +} + +func NewNative(args []byte, tx *types.Transaction, db *storage.CacheDB) *native.NativeService { + if db == nil { + store, _ := leveldbstore.NewMemLevelDBStore() + db = storage.NewCacheDB(overlaydb.NewOverlayDB(store)) + } + ns, _ := native.NewNativeService(db, tx, 0, 0, common.Uint256{0}, 0, args, false) + return ns +} + +func TestRegisterStateValidator(t *testing.T) { + params := new(StateValidatorListParam) + // four state validators + params.StateValidators = []string{ + "023e9b32ea89b94d066e649b124fd50e396ee91369e8e2a6ae1b11c170d022256d", + "03009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a2", + "02ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd", + "03408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a259477806", + } + params.Address = acct.Address + sink := common.NewZeroCopySink(nil) + params.Serialization(sink) + + tx := &types.Transaction{ + SignedAddr: []common.Address{acct.Address}, + } + nativeService = NewNative(sink.Bytes(), tx, nil) + consensusAccounts := conAccts() + putPeerMapPoolAndView(nativeService.GetCacheDB(), consensusAccounts) + // register + res, err := RegisterStateValidator(nativeService) + assert.Equal(t, res, []byte{1}) + assert.Nil(t, err) + + svListParam, err := getStateValidatorApply(nativeService, 0) + assert.Nil(t, err) + assert.Equal(t, params, svListParam) + + // none consensus acct should not be able to approve register + notConAcct := account.NewAccount("x") + asvp := &ApproveStateValidatorParam{ + 0, + notConAcct.Address, + } + sink = common.NewZeroCopySink(nil) + asvp.Serialization(sink) + tx = &types.Transaction{ + SignedAddr: []common.Address{notConAcct.Address}, + } + nativeService = NewNative(sink.Bytes(), tx, nativeService.GetCacheDB()) + res, err = ApproveRegisterStateValidator(nativeService) + assert.Nil(t, err) + assert.Equal(t, utils.BYTE_FALSE, res) + + for i, conAcct := range consensusAccounts { + asvp := &ApproveStateValidatorParam{ + 0, + conAcct.Address, + } + sink := common.NewZeroCopySink(nil) + asvp.Serialization(sink) + tx := &types.Transaction{ + SignedAddr: []common.Address{conAcct.Address}, + } + nativeService = NewNative(sink.Bytes(), tx, nativeService.GetCacheDB()) + res, err := ApproveRegisterStateValidator(nativeService) + assert.Nil(t, err) + + if i < (2*len(consensusAccounts)+2)/3-1 { // not enough sig + assert.Equal(t, utils.BYTE_FALSE, res) + } else { + assert.Equal(t, utils.BYTE_TRUE, res) + break + } + } +} + +func TestGetCurrentStateValidator(t *testing.T) { + params := new(StateValidatorListParam) + // four state validators + params.StateValidators = []string{ + "023e9b32ea89b94d066e649b124fd50e396ee91369e8e2a6ae1b11c170d022256d", + "03009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a2", + "02ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd", + "03408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a259477806", + } + params.Address = acct.Address + sink := common.NewZeroCopySink(nil) + params.Serialization(sink) + + tx := &types.Transaction{ + SignedAddr: []common.Address{acct.Address}, + } + nativeService = NewNative(sink.Bytes(), tx, nil) + consensusAccounts := conAccts() + putPeerMapPoolAndView(nativeService.GetCacheDB(), consensusAccounts) + + contract := utils.Neo3StateManagerContractAddress + // clear storage + nativeService.GetCacheDB().Delete(utils.ConcatKey(contract, []byte(STATE_VALIDATOR))) + + // register + res, err := RegisterStateValidator(nativeService) + assert.Equal(t, res, []byte{1}) + assert.Nil(t, err) + + // approve + for i, conAcct := range consensusAccounts { + log.Println(i) + asvp := &ApproveStateValidatorParam{ + 0, + conAcct.Address, + } + sink := common.NewZeroCopySink(nil) + asvp.Serialization(sink) + tx := &types.Transaction{ + SignedAddr: []common.Address{conAcct.Address}, + } + nativeService = NewNative(sink.Bytes(), tx, nativeService.GetCacheDB()) + res, err := ApproveRegisterStateValidator(nativeService) + assert.Nil(t, err) + if i < (2*len(consensusAccounts)+2)/3-1 { // not enough sig + assert.Equal(t, utils.BYTE_FALSE, res) + } else { + assert.Equal(t, utils.BYTE_TRUE, res) + break + } + //if i < (2*len(consensusAccounts)+2)/3 - 1 { // not enough sig + // ok, err := node_manager.CheckConsensusSigns(nativeService, APPROVE_REGISTER_STATE_VALIDATOR, utils.GetUint64Bytes(0), conAcct.Address) + // assert.Nil(t, err) + // assert.Equal(t, false, ok) + //} + } + // get + svs, err := getStateValidators(nativeService) + assert.Nil(t, err) + assert.Equal(t, 4, len(svs)) + + svBytes, err := GetCurrentStateValidator(nativeService) + assert.Nil(t, err) + assert.Equal(t, 269, len(svBytes)) +} + +func TestRemoveStateValidator(t *testing.T) { + params := new(StateValidatorListParam) + // four state validators + params.StateValidators = []string{ + "023e9b32ea89b94d066e649b124fd50e396ee91369e8e2a6ae1b11c170d022256d", + "03009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a2", + "02ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd", + "03408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a259477806", + } + params.Address = acct.Address + sink := common.NewZeroCopySink(nil) + params.Serialization(sink) + + tx := &types.Transaction{ + SignedAddr: []common.Address{acct.Address}, + } + nativeService = NewNative(sink.Bytes(), tx, nil) // for register + consensusAccounts := conAccts() + putPeerMapPoolAndView(nativeService.GetCacheDB(), consensusAccounts) + + // first register + res, err := RegisterStateValidator(nativeService) + assert.Equal(t, res, []byte{1}) + assert.Nil(t, err) + + // approve register + for i, conAcct := range consensusAccounts { + asvp := &ApproveStateValidatorParam{ + 0, + conAcct.Address, + } + sink := common.NewZeroCopySink(nil) + asvp.Serialization(sink) + tx := &types.Transaction{ + SignedAddr: []common.Address{conAcct.Address}, + } + nativeService = NewNative(sink.Bytes(), tx, nativeService.GetCacheDB()) + res, err := ApproveRegisterStateValidator(nativeService) + assert.Nil(t, err) + + if i < (2*len(consensusAccounts)+2)/3-1 { // not enough sig + assert.Equal(t, utils.BYTE_FALSE, res) + } else { + assert.Equal(t, utils.BYTE_TRUE, res) + break + } + } + + // confirm state validators in storage + svs, err := getStateValidators(nativeService) + assert.Nil(t, err) + assert.Equal(t, 4, len(svs)) + + // remove + nativeService = NewNative(sink.Bytes(), tx, nativeService.GetCacheDB()) // for remove + res, err = RemoveStateValidator(nativeService) + assert.Equal(t, res, []byte{1}) + assert.Nil(t, err) + + svRaw1, err := getStateValidatorRemove(nativeService, 0) + assert.Nil(t, err) + assert.Equal(t, params, svRaw1) + + // approve remove + for i, conAcct := range consensusAccounts { + asvp := &ApproveStateValidatorParam{ + 0, + conAcct.Address, + } + sink := common.NewZeroCopySink(nil) + asvp.Serialization(sink) + tx := &types.Transaction{ + SignedAddr: []common.Address{conAcct.Address}, + } + nativeService = NewNative(sink.Bytes(), tx, nativeService.GetCacheDB()) + res, err := ApproveRemoveStateValidator(nativeService) + assert.Nil(t, err) + + if i < (2*len(consensusAccounts)+2)/3-1 { // not enough sig + assert.Equal(t, utils.BYTE_FALSE, res) + } else { + assert.Equal(t, utils.BYTE_TRUE, res) + break + } + } +} diff --git a/native/service/governance/neo3_state_manager/param.go b/native/service/governance/neo3_state_manager/param.go new file mode 100644 index 000000000..197778334 --- /dev/null +++ b/native/service/governance/neo3_state_manager/param.go @@ -0,0 +1,75 @@ +package neo3_state_manager + +import ( + "fmt" + "github.com/polynetwork/poly/common" +) + +type StateValidatorListParam struct { + StateValidators []string // public key strings in encoded format, each is 33 bytes in []byte + Address common.Address // for check witness? +} + +func (this *StateValidatorListParam) Serialization(sink *common.ZeroCopySink) { + sink.WriteVarUint(uint64(len(this.StateValidators))) + for _, v := range this.StateValidators { + sink.WriteString(v) + } + sink.WriteVarBytes(this.Address[:]) +} + +func (this *StateValidatorListParam) Deserialization(source *common.ZeroCopySource) error { + n, eof := source.NextVarUint() + if eof { + return fmt.Errorf("source.NextVarUint, deserialize StateValidators length error") + } + stateValidators := make([]string, 0) + for i := 0; uint64(i) < n; i++ { + ss, eof := source.NextString() + if eof { + return fmt.Errorf("source.NextString, deserialize stateValidator error") + } + stateValidators = append(stateValidators, ss) + } + + address, eof := source.NextVarBytes() + if eof { + return fmt.Errorf("source.NextVarBytes, deserialize address error") + } + addr, err := common.AddressParseFromBytes(address) + if err != nil { + return fmt.Errorf("common.AddressParseFromBytes, deserialize address error: %s", err) + } + this.StateValidators = stateValidators + this.Address = addr + return nil +} + +type ApproveStateValidatorParam struct { + ID uint64 // StateValidatorApproveID + Address common.Address // for check witness? +} + +func (this *ApproveStateValidatorParam) Serialization(sink *common.ZeroCopySink) { + sink.WriteVarUint(this.ID) + sink.WriteVarBytes(this.Address[:]) +} + +func (this *ApproveStateValidatorParam) Deserialization(source *common.ZeroCopySource) error { + ID, eof := source.NextVarUint() + if eof { + return fmt.Errorf("source.NextVarUint, deserialize ID error") + } + + address, eof := source.NextVarBytes() + if eof { + return fmt.Errorf("source.NextVarBytes, deserialize address error") + } + addr, err := common.AddressParseFromBytes(address) + if err != nil { + return fmt.Errorf("common.AddressParseFromBytes, deserialize address error: %s", err) + } + this.ID = ID + this.Address = addr + return nil +} diff --git a/native/service/governance/neo3_state_manager/param_test.go b/native/service/governance/neo3_state_manager/param_test.go new file mode 100644 index 000000000..cd3b504a3 --- /dev/null +++ b/native/service/governance/neo3_state_manager/param_test.go @@ -0,0 +1,25 @@ +package neo3_state_manager + +import ( + "github.com/polynetwork/poly/common" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestStateValidatorListParam_Serialization(t *testing.T) { + params := new(StateValidatorListParam) + params.StateValidators = []string{ + "023e9b32ea89b94d066e649b124fd50e396ee91369e8e2a6ae1b11c170d022256d", + "03009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a2", + "02ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd", + "03408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a259477806", + } + sink := common.NewZeroCopySink(nil) + params.Serialization(sink) + + source := common.NewZeroCopySource(sink.Bytes()) + var p StateValidatorListParam + err := p.Deserialization(source) + assert.Nil(t, err) + assert.Equal(t, 4, len(p.StateValidators)) +} diff --git a/native/service/governance/neo3_state_manager/utils.go b/native/service/governance/neo3_state_manager/utils.go new file mode 100644 index 000000000..aec64922a --- /dev/null +++ b/native/service/governance/neo3_state_manager/utils.go @@ -0,0 +1,277 @@ +package neo3_state_manager + +import ( + "fmt" + "github.com/polynetwork/poly/common" + cstates "github.com/polynetwork/poly/core/states" + "github.com/polynetwork/poly/native" + "github.com/polynetwork/poly/native/event" + "github.com/polynetwork/poly/native/service/utils" +) + +//// putStateValidator put state validator in the contract storage using the STATE_VALIDATOR key +//func putStateValidator(native *native.NativeService, stateValidator helper.UInt160) error { +// contract := utils.Neo3StateManagerContractAddress +// native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(STATE_VALIDATOR), stateValidator.ToByteArray()), cstates.GenRawStorageItem(stateValidator.ToByteArray())) +// return nil +//} + +//func getStateValidator(native *native.NativeService, stateValidator helper.UInt160) error { +// contract := utils.Neo3StateManagerContractAddress +// native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(STATE_VALIDATOR), stateValidator.ToByteArray()), cstates.GenRawStorageItem(stateValidator.ToByteArray())) +// return nil +//} + +// +func SerializeStringArray(data []string) []byte { + sink := common.NewZeroCopySink(nil) + // serialize + sink.WriteVarUint(uint64(len(data))) + for _, v := range data { + sink.WriteString(v) + } + return sink.Bytes() +} + +func DeserializeStringArray(data []byte) ([]string, error) { + source := common.NewZeroCopySource(data) + n, eof := source.NextVarUint() + if eof { + return nil, fmt.Errorf("source.NextVarUint error") + } + result := make([]string, 0) + for i := 0; uint64(i) < n; i++ { + ss, eof := source.NextString() + if eof { + return nil, fmt.Errorf("source.NextString error") + } + result = append(result, ss) + } + return result, nil +} + +func getStateValidators(native *native.NativeService) ([]string, error) { + contract := utils.Neo3StateManagerContractAddress + svStore, err := native.GetCacheDB().Get(utils.ConcatKey(contract, []byte(STATE_VALIDATOR))) + if err != nil { + return nil, fmt.Errorf("getStateValidator, get stateValidatorListParamStore error: %v", err) + } + if svStore == nil { + return []string{}, nil + } + svBytes, err := cstates.GetValueFromRawStorageItem(svStore) + if err != nil { + return nil, fmt.Errorf("getStateValidator, deserialize from raw storage item error: %v", err) + } + svs, err := DeserializeStringArray(svBytes) + if err != nil { + return nil, fmt.Errorf("getStateValidator, convert to UInt160 array error: %v", err) + } + return svs, nil +} + +func putStateValidators(native *native.NativeService, stateValidators []string) error { + contract := utils.Neo3StateManagerContractAddress + // get current stored value + oldSVs, err := getStateValidators(native) + if err != nil { + return fmt.Errorf("putStateValidator, get old state validators error: %v", err) + } + // use a map to filter old svs + mm := make(map[string]string) + for _, v := range oldSVs { + if _, ok := mm[v]; ok { + continue + } + mm[v] = v + } + // use the map to add new svs + for _, v := range stateValidators { + if _, ok := mm[v]; ok { + continue + } + mm[v] = v + } + // convert map back to UInt160 array + newSVs := make([]string, 0) + for _, v := range mm { + newSVs = append(newSVs, v) + } + // convert back to []byte + data := SerializeStringArray(newSVs) + native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(STATE_VALIDATOR)), cstates.GenRawStorageItem(data)) + return nil +} + +func removeStateValidators(native *native.NativeService, stateValidators []string) error { + contract := utils.Neo3StateManagerContractAddress + // get current stored value + oldSVs, err := getStateValidators(native) + if err != nil { + return fmt.Errorf("removeStateValidator, get old state validators error: %v", err) + } + // use a map to filter old svs + mm := make(map[string]string) + for _, v := range oldSVs { + if _, ok := mm[v]; ok { + continue + } + mm[v] = v + } + // use the map to delete svs + for _, v := range stateValidators { + // if the sv is in map, delete it, else continue + if _, ok := mm[v]; ok { + delete(mm, v) + } + } + // convert map back to UInt160 array + newSVs := make([]string, 0) + for _, v := range mm { + newSVs = append(newSVs, v) + } + // if no sv left, delete the storage, else put remaining back + if len(newSVs) == 0 { + native.GetCacheDB().Delete(utils.ConcatKey(contract, []byte(STATE_VALIDATOR))) + return nil + } + + // convert back to []byte + data := SerializeStringArray(newSVs) + native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(STATE_VALIDATOR)), cstates.GenRawStorageItem(data)) + return nil +} + +func getStateValidatorApply(native *native.NativeService, applyID uint64) (*StateValidatorListParam, error) { + contract := utils.Neo3StateManagerContractAddress + svListParamStore, err := native.GetCacheDB().Get(utils.ConcatKey(contract, []byte(STATE_VALIDATOR_APPLY), utils.GetUint64Bytes(applyID))) + if err != nil { + return nil, fmt.Errorf("getStateValidatorApply, get stateValidatorListParamStore error: %v", err) + } + if svListParamStore == nil { + return nil, fmt.Errorf("getStateValidatorApply, can't find any record") + } + svListParam := new(StateValidatorListParam) + svListParamBytes, err := cstates.GetValueFromRawStorageItem(svListParamStore) + if err != nil { + return nil, fmt.Errorf("getStateValidatorApply, deserialize from raw storage item error: %v", err) + } + err = svListParam.Deserialization(common.NewZeroCopySource(svListParamBytes)) + if err != nil { + + } + return svListParam, nil +} + +func putStateValidatorApply(native *native.NativeService, stateValidatorListParam *StateValidatorListParam) error { + contract := utils.Neo3StateManagerContractAddress + applyID, err := getStateValidatorApplyID(native) + if err != nil { + return fmt.Errorf("putStateValidatorApply, getStateValidatorApplyID error: %v", err) + } + newApplyID := applyID + 1 + err = putStateValidatorApplyID(native, newApplyID) + if err != nil { + return fmt.Errorf("putStateValidatorApply, putStateValidatorApplyID error: %v", err) + } + sink := common.NewZeroCopySink(nil) + stateValidatorListParam.Serialization(sink) + native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(STATE_VALIDATOR_APPLY), utils.GetUint64Bytes(applyID)), cstates.GenRawStorageItem(sink.Bytes())) + native.AddNotify( + &event.NotifyEventInfo{ + ContractAddress: contract, + States: []interface{}{"putStateValidatorApply", applyID}, + }) + return nil +} + +func getStateValidatorApplyID(native *native.NativeService) (uint64, error) { + contract := utils.Neo3StateManagerContractAddress + applyIDStore, err := native.GetCacheDB().Get(utils.ConcatKey(contract, []byte(STATE_VALIDATOR_APPLY_ID))) + if err != nil { + return 0, fmt.Errorf("getStateValidatorApplyID, get applyIDStore error: %v", err) + } + var applyID uint64 = 0 + if applyIDStore != nil { + applyIDBytes, err := cstates.GetValueFromRawStorageItem(applyIDStore) + if err != nil { + return 0, fmt.Errorf("getStateValidatorApplyID, deserialize from raw storage item error: %v", err) + } + applyID = utils.GetBytesUint64(applyIDBytes) + } + return applyID, nil +} + +func putStateValidatorApplyID(native *native.NativeService, applyID uint64) error { + contract := utils.Neo3StateManagerContractAddress + applyIDByte := utils.GetUint64Bytes(applyID) + native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(STATE_VALIDATOR_APPLY_ID)), cstates.GenRawStorageItem(applyIDByte)) + return nil +} + +func getStateValidatorRemove(native *native.NativeService, removeID uint64) (*StateValidatorListParam, error) { + contract := utils.Neo3StateManagerContractAddress + svListParamStore, err := native.GetCacheDB().Get(utils.ConcatKey(contract, []byte(STATE_VALIDATOR_REMOVE), utils.GetUint64Bytes(removeID))) + if err != nil { + return nil, fmt.Errorf("getStateValidatorRemove, get stateValidatorListParamStore error: %v", err) + } + if svListParamStore == nil { + return nil, fmt.Errorf("getStateValidatorRemove, can't find any record") + } + svListParam := new(StateValidatorListParam) + svListParamBytes, err := cstates.GetValueFromRawStorageItem(svListParamStore) + if err != nil { + return nil, fmt.Errorf("getStateValidatorRemove, deserialize from raw storage item error: %v", err) + } + err = svListParam.Deserialization(common.NewZeroCopySource(svListParamBytes)) + if err != nil { + return nil, fmt.Errorf("getStateValidatorRemove, svListParam.Deserialization error: %v", err) + } + return svListParam, nil +} + +func putStateValidatorRemove(native *native.NativeService, svListParam *StateValidatorListParam) error { + contract := utils.Neo3StateManagerContractAddress + removeID, err := getStateValidatorRemoveID(native) + if err != nil { + return fmt.Errorf("putStateValidatorRemove, getStateValidatorRemoveID error: %v", err) + } + newRemoveID := removeID + 1 + err = putStateValidatorRemoveID(native, newRemoveID) + if err != nil { + return fmt.Errorf("putStateValidatorRemove, putStateValidatorRemoveID error: %v", err) + } + sink := common.NewZeroCopySink(nil) + svListParam.Serialization(sink) + native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(STATE_VALIDATOR_REMOVE), utils.GetUint64Bytes(removeID)), cstates.GenRawStorageItem(sink.Bytes())) + native.AddNotify( + &event.NotifyEventInfo{ + ContractAddress: contract, + States: []interface{}{"putStateValidatorRemove", removeID}, + }) + return nil +} + +func getStateValidatorRemoveID(native *native.NativeService) (uint64, error) { + contract := utils.Neo3StateManagerContractAddress + removeIDStore, err := native.GetCacheDB().Get(utils.ConcatKey(contract, []byte(STATE_VALIDATOR_REMOVE_ID))) + if err != nil { + return 0, fmt.Errorf("getStateValidatorRemoveID, get removeIDStore error: %v", err) + } + var removeID uint64 = 0 + if removeIDStore != nil { + removeIDBytes, err := cstates.GetValueFromRawStorageItem(removeIDStore) + if err != nil { + return 0, fmt.Errorf("getStateValidatorRemoveID, deserialize from raw storage item error: %v", err) + } + removeID = utils.GetBytesUint64(removeIDBytes) + } + return removeID, nil +} + +func putStateValidatorRemoveID(native *native.NativeService, removeID uint64) error { + contract := utils.Neo3StateManagerContractAddress + removeIDBytes := utils.GetUint64Bytes(removeID) + native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(STATE_VALIDATOR_REMOVE_ID)), cstates.GenRawStorageItem(removeIDBytes)) + return nil +} diff --git a/native/service/header_sync/neo3/utils.go b/native/service/header_sync/neo3/utils.go index a6976bb71..0b271d091 100644 --- a/native/service/header_sync/neo3/utils.go +++ b/native/service/header_sync/neo3/utils.go @@ -20,10 +20,13 @@ package neo3 import ( "encoding/hex" "fmt" + "github.com/joeqian10/neo3-gogogo/crypto" + "github.com/joeqian10/neo3-gogogo/sc" "github.com/joeqian10/neo3-gogogo/tx" "github.com/polynetwork/poly/common" cstates "github.com/polynetwork/poly/core/states" "github.com/polynetwork/poly/native" + "github.com/polynetwork/poly/native/service/governance/neo3_state_manager" hscommon "github.com/polynetwork/poly/native/service/header_sync/common" "github.com/polynetwork/poly/native/service/utils" ) @@ -50,16 +53,37 @@ func verifyHeader(native *native.NativeService, chainID uint64, header *NeoBlock } func VerifyCrossChainMsgSig(native *native.NativeService, chainID uint64, crossChainMsg *NeoCrossChainMsg) error { - neoConsensus, err := getConsensusValByChainId(native, chainID) + // todo, review code, get neo3 state validator from native contract + svListBytes, err := neo3_state_manager.GetCurrentStateValidator(native) + if err != nil { + return fmt.Errorf("verifyCrossChainMsg, neo3_state_manager.GetCurrentStateValidator error: %v", err) + } + svStrings, err := neo3_state_manager.DeserializeStringArray(svListBytes) + if err != nil { + return fmt.Errorf("verifyCrossChainMsg, neo3_state_manager.DeserializeStringArray error: %v", err) + } + pubKeys := make([]crypto.ECPoint, len(svStrings)) + for i, v := range svStrings { + pubKey, err := crypto.NewECPointFromString(v) + if err != nil { + return fmt.Errorf("verifyCrossChainMsg, crypto.NewECPointFromString error: %v", err) + } + pubKeys[i] = *pubKey + } + n := len(pubKeys) + m := n - (n-1)/3 + msc, err := sc.CreateMultiSigContract(m, pubKeys) if err != nil { - return fmt.Errorf("verifyCrossChainMsg, get ConsensusPeer error: %v", err) + return fmt.Errorf("verifyCrossChainMsg, sc.CreateMultiSigContract error: %v", err) } - crossChainMsgConsensus, err := crossChainMsg.GetScriptHash() + expected := msc.GetScriptHash() + got, err := crossChainMsg.GetScriptHash() if err != nil { return fmt.Errorf("verifyCrossChainMsg, getScripthash error: %v", err) } - if neoConsensus.NextConsensus != crossChainMsgConsensus { - return fmt.Errorf("verifyCrossChainMsg, invalid script hash in NeoCrossChainMsg error, expected: %s, got: %s", neoConsensus.NextConsensus.String(), crossChainMsgConsensus.String()) + // compare state validator + if !expected.Equals(got) { + return fmt.Errorf("verifyCrossChainMsg, invalid script hash in NeoCrossChainMsg error, expected: %s, got: %s", expected.String(), got.String()) } msg, err := crossChainMsg.GetMessage() if err != nil { diff --git a/native/service/init.go b/native/service/init.go index 486414a18..5a55238ef 100644 --- a/native/service/init.go +++ b/native/service/init.go @@ -21,6 +21,7 @@ import ( "github.com/polynetwork/poly/common/config" "github.com/polynetwork/poly/native" "github.com/polynetwork/poly/native/service/cross_chain_manager" + "github.com/polynetwork/poly/native/service/governance/neo3_state_manager" "github.com/polynetwork/poly/native/service/governance/node_manager" "github.com/polynetwork/poly/native/service/governance/relayer_manager" "github.com/polynetwork/poly/native/service/governance/side_chain_manager" @@ -34,6 +35,7 @@ func init() { native.Contracts[utils.CrossChainManagerContractAddress] = cross_chain_manager.RegisterCrossChainManagerContract native.Contracts[utils.NodeManagerContractAddress] = node_manager.RegisterNodeManagerContract native.Contracts[utils.RelayerManagerContractAddress] = relayer_manager.RegisterRelayerManagerContract + native.Contracts[utils.Neo3StateManagerContractAddress] = neo3_state_manager.RegisterStateValidatorManagerContract config.EXTRA_INFO_HEIGHT_FORK_CHECK = true } diff --git a/native/service/utils/params.go b/native/service/utils/params.go index 85ef9370d..bf3a2e136 100644 --- a/native/service/utils/params.go +++ b/native/service/utils/params.go @@ -37,6 +37,7 @@ var ( SideChainManagerContractAddress, _ = common.AddressParseFromBytes([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04}) NodeManagerContractAddress, _ = common.AddressParseFromBytes([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05}) RelayerManagerContractAddress, _ = common.AddressParseFromBytes([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06}) + Neo3StateManagerContractAddress, _ = common.AddressParseFromBytes([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07}) BTC_ROUTER = uint64(1) ETH_ROUTER = uint64(2) @@ -48,5 +49,5 @@ var ( QUORUM_ROUTER = uint64(8) ZILLIQA_ROUTER = uint64(9) MSC_ROUTER = uint64(10) - NEO3_ROUTER = uint64(11) + NEO3_ROUTER = uint64(11) ) From 7c006f569577341982315d5557351ccca7e9a0f5 Mon Sep 17 00:00:00 2001 From: dogecoindev Date: Mon, 17 May 2021 17:38:55 +0700 Subject: [PATCH 09/23] add support native kai --- core/store/ledgerstore/test/block/CURRENT | 1 + core/store/ledgerstore/test/block/LOCK | 0 core/store/ledgerstore/test/block/LOG | 6 + .../ledgerstore/test/block/MANIFEST-000000 | Bin 0 -> 54 bytes .../ledgerstore/test/ledger/block/CURRENT | 1 + core/store/ledgerstore/test/ledger/block/LOCK | 0 core/store/ledgerstore/test/ledger/block/LOG | 6 + .../test/ledger/block/MANIFEST-000000 | Bin 0 -> 54 bytes .../test/ledger/ledgerevent/CURRENT | 1 + .../ledgerstore/test/ledger/ledgerevent/LOCK | 0 .../ledgerstore/test/ledger/ledgerevent/LOG | 6 + .../test/ledger/ledgerevent/MANIFEST-000000 | Bin 0 -> 54 bytes .../ledgerstore/test/ledger/merkle_tree.db | 1 + .../ledgerstore/test/ledger/states/CURRENT | 1 + .../store/ledgerstore/test/ledger/states/LOCK | 0 core/store/ledgerstore/test/ledger/states/LOG | 6 + .../test/ledger/states/MANIFEST-000000 | Bin 0 -> 54 bytes core/store/ledgerstore/test/merkle_tree.db | 0 core/store/ledgerstore/test/state/CURRENT | 1 + core/store/ledgerstore/test/state/LOCK | 0 core/store/ledgerstore/test/state/LOG | 6 + .../ledgerstore/test/state/MANIFEST-000000 | Bin 0 -> 54 bytes go.mod | 14 +- go.sum | 83 ++++++ merkle/merkletree.db | Bin 0 -> 8864 bytes .../cross_chain_manager/kai/handler.go | 260 ++++++++++++++++++ .../cross_chain_manager/kai/handler_test.go | 1 + native/service/header_sync/kai/header_sync.go | 75 +++++ .../header_sync/kai/header_sync_test.go | 1 + native/service/header_sync/kai/state.go | 60 ++++ native/service/header_sync/kai/utils.go | 69 +++++ validator/db/temp.db/000002.ldb | Bin 0 -> 181 bytes validator/db/temp.db/CURRENT | 1 + validator/db/temp.db/CURRENT.bak | 1 + validator/db/temp.db/LOCK | 0 validator/db/temp.db/LOG | 25 ++ validator/db/temp.db/MANIFEST-000006 | Bin 0 -> 66 bytes 37 files changed, 620 insertions(+), 6 deletions(-) create mode 100644 core/store/ledgerstore/test/block/CURRENT create mode 100644 core/store/ledgerstore/test/block/LOCK create mode 100644 core/store/ledgerstore/test/block/LOG create mode 100644 core/store/ledgerstore/test/block/MANIFEST-000000 create mode 100644 core/store/ledgerstore/test/ledger/block/CURRENT create mode 100644 core/store/ledgerstore/test/ledger/block/LOCK create mode 100644 core/store/ledgerstore/test/ledger/block/LOG create mode 100644 core/store/ledgerstore/test/ledger/block/MANIFEST-000000 create mode 100644 core/store/ledgerstore/test/ledger/ledgerevent/CURRENT create mode 100644 core/store/ledgerstore/test/ledger/ledgerevent/LOCK create mode 100644 core/store/ledgerstore/test/ledger/ledgerevent/LOG create mode 100644 core/store/ledgerstore/test/ledger/ledgerevent/MANIFEST-000000 create mode 100755 core/store/ledgerstore/test/ledger/merkle_tree.db create mode 100644 core/store/ledgerstore/test/ledger/states/CURRENT create mode 100644 core/store/ledgerstore/test/ledger/states/LOCK create mode 100644 core/store/ledgerstore/test/ledger/states/LOG create mode 100644 core/store/ledgerstore/test/ledger/states/MANIFEST-000000 create mode 100755 core/store/ledgerstore/test/merkle_tree.db create mode 100644 core/store/ledgerstore/test/state/CURRENT create mode 100644 core/store/ledgerstore/test/state/LOCK create mode 100644 core/store/ledgerstore/test/state/LOG create mode 100644 core/store/ledgerstore/test/state/MANIFEST-000000 create mode 100755 merkle/merkletree.db create mode 100644 native/service/cross_chain_manager/kai/handler.go create mode 100644 native/service/cross_chain_manager/kai/handler_test.go create mode 100644 native/service/header_sync/kai/header_sync.go create mode 100644 native/service/header_sync/kai/header_sync_test.go create mode 100644 native/service/header_sync/kai/state.go create mode 100644 native/service/header_sync/kai/utils.go create mode 100644 validator/db/temp.db/000002.ldb create mode 100644 validator/db/temp.db/CURRENT create mode 100644 validator/db/temp.db/CURRENT.bak create mode 100644 validator/db/temp.db/LOCK create mode 100644 validator/db/temp.db/LOG create mode 100644 validator/db/temp.db/MANIFEST-000006 diff --git a/core/store/ledgerstore/test/block/CURRENT b/core/store/ledgerstore/test/block/CURRENT new file mode 100644 index 000000000..feda7d6b2 --- /dev/null +++ b/core/store/ledgerstore/test/block/CURRENT @@ -0,0 +1 @@ +MANIFEST-000000 diff --git a/core/store/ledgerstore/test/block/LOCK b/core/store/ledgerstore/test/block/LOCK new file mode 100644 index 000000000..e69de29bb diff --git a/core/store/ledgerstore/test/block/LOG b/core/store/ledgerstore/test/block/LOG new file mode 100644 index 000000000..0fde3b290 --- /dev/null +++ b/core/store/ledgerstore/test/block/LOG @@ -0,0 +1,6 @@ +=============== May 17, 2021 (+07) =============== +11:10:17.023901 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +11:10:17.032333 db@open opening +11:10:17.032765 version@stat F·[] S·0B[] Sc·[] +11:10:17.037842 db@janitor F·2 G·0 +11:10:17.037869 db@open done T·5.5158ms diff --git a/core/store/ledgerstore/test/block/MANIFEST-000000 b/core/store/ledgerstore/test/block/MANIFEST-000000 new file mode 100644 index 0000000000000000000000000000000000000000..9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d GIT binary patch literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD literal 0 HcmV?d00001 diff --git a/core/store/ledgerstore/test/ledger/block/CURRENT b/core/store/ledgerstore/test/ledger/block/CURRENT new file mode 100644 index 000000000..feda7d6b2 --- /dev/null +++ b/core/store/ledgerstore/test/ledger/block/CURRENT @@ -0,0 +1 @@ +MANIFEST-000000 diff --git a/core/store/ledgerstore/test/ledger/block/LOCK b/core/store/ledgerstore/test/ledger/block/LOCK new file mode 100644 index 000000000..e69de29bb diff --git a/core/store/ledgerstore/test/ledger/block/LOG b/core/store/ledgerstore/test/ledger/block/LOG new file mode 100644 index 000000000..5b5238ab4 --- /dev/null +++ b/core/store/ledgerstore/test/ledger/block/LOG @@ -0,0 +1,6 @@ +=============== May 17, 2021 (+07) =============== +11:10:16.986154 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +11:10:16.993916 db@open opening +11:10:16.995678 version@stat F·[] S·0B[] Sc·[] +11:10:17.000560 db@janitor F·2 G·0 +11:10:17.000607 db@open done T·6.660819ms diff --git a/core/store/ledgerstore/test/ledger/block/MANIFEST-000000 b/core/store/ledgerstore/test/ledger/block/MANIFEST-000000 new file mode 100644 index 0000000000000000000000000000000000000000..9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d GIT binary patch literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD literal 0 HcmV?d00001 diff --git a/core/store/ledgerstore/test/ledger/ledgerevent/CURRENT b/core/store/ledgerstore/test/ledger/ledgerevent/CURRENT new file mode 100644 index 000000000..feda7d6b2 --- /dev/null +++ b/core/store/ledgerstore/test/ledger/ledgerevent/CURRENT @@ -0,0 +1 @@ +MANIFEST-000000 diff --git a/core/store/ledgerstore/test/ledger/ledgerevent/LOCK b/core/store/ledgerstore/test/ledger/ledgerevent/LOCK new file mode 100644 index 000000000..e69de29bb diff --git a/core/store/ledgerstore/test/ledger/ledgerevent/LOG b/core/store/ledgerstore/test/ledger/ledgerevent/LOG new file mode 100644 index 000000000..1707ba97b --- /dev/null +++ b/core/store/ledgerstore/test/ledger/ledgerevent/LOG @@ -0,0 +1,6 @@ +=============== May 17, 2021 (+07) =============== +11:10:17.012451 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +11:10:17.018845 db@open opening +11:10:17.019081 version@stat F·[] S·0B[] Sc·[] +11:10:17.023639 db@janitor F·2 G·0 +11:10:17.023689 db@open done T·4.824619ms diff --git a/core/store/ledgerstore/test/ledger/ledgerevent/MANIFEST-000000 b/core/store/ledgerstore/test/ledger/ledgerevent/MANIFEST-000000 new file mode 100644 index 0000000000000000000000000000000000000000..9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d GIT binary patch literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD literal 0 HcmV?d00001 diff --git a/core/store/ledgerstore/test/ledger/merkle_tree.db b/core/store/ledgerstore/test/ledger/merkle_tree.db new file mode 100755 index 000000000..cfc241656 --- /dev/null +++ b/core/store/ledgerstore/test/ledger/merkle_tree.db @@ -0,0 +1 @@ +œž1¬‚VÊ/%…ƒß&-¼}ohò 0CÕÉšJå§9lé \ No newline at end of file diff --git a/core/store/ledgerstore/test/ledger/states/CURRENT b/core/store/ledgerstore/test/ledger/states/CURRENT new file mode 100644 index 000000000..feda7d6b2 --- /dev/null +++ b/core/store/ledgerstore/test/ledger/states/CURRENT @@ -0,0 +1 @@ +MANIFEST-000000 diff --git a/core/store/ledgerstore/test/ledger/states/LOCK b/core/store/ledgerstore/test/ledger/states/LOCK new file mode 100644 index 000000000..e69de29bb diff --git a/core/store/ledgerstore/test/ledger/states/LOG b/core/store/ledgerstore/test/ledger/states/LOG new file mode 100644 index 000000000..eb83d2cf3 --- /dev/null +++ b/core/store/ledgerstore/test/ledger/states/LOG @@ -0,0 +1,6 @@ +=============== May 17, 2021 (+07) =============== +11:10:17.000802 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +11:10:17.007586 db@open opening +11:10:17.007952 version@stat F·[] S·0B[] Sc·[] +11:10:17.012274 db@janitor F·2 G·0 +11:10:17.012298 db@open done T·4.689132ms diff --git a/core/store/ledgerstore/test/ledger/states/MANIFEST-000000 b/core/store/ledgerstore/test/ledger/states/MANIFEST-000000 new file mode 100644 index 0000000000000000000000000000000000000000..9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d GIT binary patch literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD literal 0 HcmV?d00001 diff --git a/core/store/ledgerstore/test/merkle_tree.db b/core/store/ledgerstore/test/merkle_tree.db new file mode 100755 index 000000000..e69de29bb diff --git a/core/store/ledgerstore/test/state/CURRENT b/core/store/ledgerstore/test/state/CURRENT new file mode 100644 index 000000000..feda7d6b2 --- /dev/null +++ b/core/store/ledgerstore/test/state/CURRENT @@ -0,0 +1 @@ +MANIFEST-000000 diff --git a/core/store/ledgerstore/test/state/LOCK b/core/store/ledgerstore/test/state/LOCK new file mode 100644 index 000000000..e69de29bb diff --git a/core/store/ledgerstore/test/state/LOG b/core/store/ledgerstore/test/state/LOG new file mode 100644 index 000000000..a0f86ce62 --- /dev/null +++ b/core/store/ledgerstore/test/state/LOG @@ -0,0 +1,6 @@ +=============== May 17, 2021 (+07) =============== +11:10:17.038075 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +11:10:17.044648 db@open opening +11:10:17.044847 version@stat F·[] S·0B[] Sc·[] +11:10:17.050382 db@janitor F·2 G·0 +11:10:17.050408 db@open done T·5.740115ms diff --git a/core/store/ledgerstore/test/state/MANIFEST-000000 b/core/store/ledgerstore/test/state/MANIFEST-000000 new file mode 100644 index 0000000000000000000000000000000000000000..9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d GIT binary patch literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD literal 0 HcmV?d00001 diff --git a/go.mod b/go.mod index 7b090dab4..b9b1ef17c 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,10 @@ go 1.14 require ( github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210329093354-1b8e0a7a2e25 - github.com/btcsuite/btcd v0.20.1-beta + github.com/btcsuite/btcd v0.21.0-beta github.com/btcsuite/btcutil v1.0.2 github.com/cosmos/cosmos-sdk v0.39.1 - github.com/ethereum/go-ethereum v1.9.15 + github.com/ethereum/go-ethereum v1.9.18 github.com/gcash/bchd v0.16.5 github.com/gcash/bchutil v0.0.0-20200506001747-c2894cd54b33 github.com/gorilla/websocket v1.4.2 @@ -16,17 +16,19 @@ require ( github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c github.com/itchyny/base58-go v0.1.0 github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43 + github.com/kardiachain/go-kardia v1.1.1-0.20210514114009-042c640f55d4 // indirect github.com/ontio/ontology v1.11.1-0.20200812075204-26cf1fa5dd47 github.com/ontio/ontology-crypto v1.0.9 github.com/ontio/ontology-eventbus v0.9.1 github.com/pborman/uuid v1.2.0 github.com/polynetwork/poly-io-test v0.0.0-20200819093740-8cf514b07750 - github.com/stretchr/testify v1.6.1 - github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d + github.com/stretchr/testify v1.7.0 + github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca github.com/tendermint/tendermint v0.33.7 github.com/urfave/cli v1.22.4 github.com/valyala/bytebufferpool v1.0.0 - golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de - golang.org/x/net v0.0.0-20200822124328-c89045814202 + golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 + golang.org/x/net v0.0.0-20201021035429-f5854403a974 + google.golang.org/grpc v1.30.0 // indirect gotest.tools v2.2.0+incompatible ) diff --git a/go.sum b/go.sum index 936b56289..7d5a8a35a 100644 --- a/go.sum +++ b/go.sum @@ -77,12 +77,17 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= +github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= +github.com/antlr/antlr4 v0.0.0-20190819145818-b43a4c3a8015/go.mod h1:T7PbCXFs94rrTttyxjbyT5+/1V8T2TYDejxUfHJjw1Y= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847 h1:rtI0fD4oG/8eVokGVPYJEW1F88p1ZNgXiEIs9thEE4A= github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= +github.com/aristanetworks/goarista v0.0.0-20190712234253-ed1100a1c015 h1:7ABPr1+uJdqESAdlVevnc/2FJGiC/K3uMg1JiELeF+0= +github.com/aristanetworks/goarista v0.0.0-20190712234253-ed1100a1c015/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= @@ -104,6 +109,8 @@ github.com/btcsuite/btcd v0.0.0-20190115013929-ed77733ec07d/go.mod h1:d3C0AkH6BR github.com/btcsuite/btcd v0.0.0-20190315201642-aa6e0f35703c/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= +github.com/btcsuite/btcd v0.21.0-beta h1:At9hIZdJW0s9E/fAz28nrz6AmcNlSVucCH796ZteX1M= +github.com/btcsuite/btcd v0.21.0-beta/go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= @@ -125,6 +132,7 @@ github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= +github.com/cespare/cp v1.1.1/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.0.1-0.20190104013014-3767db7a7e18/go.mod h1:HD5P3vAIAh+Y2GAxg0PrPN1P8WkepXGpjbUPDHJqqKM= @@ -169,11 +177,15 @@ github.com/dchest/siphash v1.2.1 h1:4cLinnzVJDKxTCl9B01807Yiy+W7ZzVHj/KIroQRvT4= github.com/dchest/siphash v1.2.1/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4= github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea h1:j4317fAZh7X6GqbFowYdYdI0L9bwxL07jyPZIdepyZ0= github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= +github.com/deckarep/golang-set v1.7.1 h1:SCQV0S6gTtp6itiFrTqI+pfmJ4LN85S1YzhDf9rTHJQ= +github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= +github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v17.12.0-ce-rc1.0.20200531234253-77e06fda0c94+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/dop251/goja v0.0.0-20200219165308-d1232e640a87/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA= github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -182,6 +194,7 @@ github.com/dvyukov/go-fuzz v0.0.0-20200318091601-be3528f3a813/go.mod h1:11Gm+ccJ github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/ebuchman/fail-test v0.0.0-20170303061230-95f809107225/go.mod h1:OFTBW14UVJS8P0shpX7OdPY0qpkTdA7AWGYFacMC2D8= github.com/edsrzf/mmap-go v0.0.0-20160512033002-935e0e8a636c/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= @@ -200,6 +213,8 @@ github.com/ethereum/go-ethereum v1.9.13 h1:rOPqjSngvs1VSYH2H+PMPiWt4VEulvNRbFgqi github.com/ethereum/go-ethereum v1.9.13/go.mod h1:qwN9d1GLyDh0N7Ab8bMGd0H9knaji2jOBm2RrMGjXls= github.com/ethereum/go-ethereum v1.9.15 h1:wrWl+QrtutRUJ9LZXdUqBoGoo2b1tOCYRDrAOQhCY3A= github.com/ethereum/go-ethereum v1.9.15/go.mod h1:slT8bPPRhXsyNTwHQxrOnjuTZ1sDXRajW11EkJ84QJ0= +github.com/ethereum/go-ethereum v1.9.18 h1:+vzvufVD7+OfQa07IJP20Z7AGZsJaw0M6JIA/WQcqy8= +github.com/ethereum/go-ethereum v1.9.18/go.mod h1:JSSTypSMTkGZtAdAChH2wP5dZEvPGh3nUTuDpH+hNrg= github.com/ethereum/go-ethereum v1.9.24 h1:6AK+ORt3EMDO+FTjzXy/AQwHMbu52J2nYHIjyQX9azQ= github.com/ethereum/go-ethereum v1.9.24/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ= @@ -212,6 +227,7 @@ github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= +github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= @@ -262,6 +278,8 @@ github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -285,6 +303,8 @@ github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0 github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -293,11 +313,14 @@ github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26/go.mod h1:/XxbfmMg github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/cel-go v0.3.2/go.mod h1:DoRSdzaJzNiP1lVuWhp/RjSnHLDQr/aNPlyqSBasBqA= +github.com/google/cel-spec v0.3.0/go.mod h1:MjQm800JAGhOZXI7vatnVpmIaFTR6L8FHcKk+piiKpI= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -397,25 +420,32 @@ github.com/joeqian10/neo-gogogo v0.0.0-20200611102831-c17de5e1f0f8/go.mod h1:1fV github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43 h1:KkErIktuwCqqZYWV8iBbD7NEsgIbyGw6xxtuylqdyu0= github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43/go.mod h1:1fVDp4U1ROZQBRIooecbGNHHJpfs3bG9528sqlZ096g= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356 h1:I/yrLt2WilKxlQKCM52clh5rGzTKpVctGT1lH4Dc8Jw= github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= +github.com/kardiachain/go-kardia v1.1.1-0.20210514114009-042c640f55d4 h1:vYkCSECIwErZ8YhymhOYySiieROmbKk+3/rIsU1MUgE= +github.com/kardiachain/go-kardia v1.1.1-0.20210514114009-042c640f55d4/go.mod h1:XV2KPJf+Ib3es9iAFH5Io5fISzHpu7pk06um9bgAVKU= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/kkdai/bstream v0.0.0-20181106074824-b3251f7901ec/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -434,11 +464,13 @@ github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzR github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= @@ -452,6 +484,7 @@ github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3N github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 h1:hLDRPB66XQT/8+wG9WsDpiCvZf1yKO7sz7scAjSlBa0= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= github.com/minio/highwayhash v1.0.0/go.mod h1:xQboMTeM9nY9v/LlAOxFctujiv5+Aq2hR5dxBpaMbdc= +github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -476,6 +509,7 @@ github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzE github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= @@ -494,6 +528,7 @@ github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5 github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/ontio/go-bip32 v0.0.0-20190520025953-d3cea6894a2b/go.mod h1:J0eVc7BEMmVVXbGv9PHoxjRSEwOwLr0qfzPk8Rdl5iw= github.com/ontio/ontology v1.10.0/go.mod h1:iok/imHJVQXi5/Yr88dcbrKBRHGdiota1ZC6qh6l6Rc= @@ -523,12 +558,14 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI github.com/pborman/uuid v0.0.0-20170112150404-1b00554d8222/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34= github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= +github.com/pebbe/zmq4 v1.0.0/go.mod h1:7N4y5R18zBiu3l0vajMUWQgZyjv464prE8RCyBcmnZM= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.6.0 h1:aetoXYr0Tv7xRU/V4B4IZJ2QcbtMUFoNb3ORp7TzIK4= github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -556,6 +593,8 @@ github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeD github.com/prometheus/client_golang v1.5.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.5.1 h1:bdHYieyGlH+6OLEk2YQha8THib30KP0/yD0YH9m6xcA= github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= +github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= +github.com/prometheus/client_golang v1.8.0/go.mod h1:O9VU6huf47PktckDQfMTX0Y8tY0/7TSWwj+ITvv0TnM= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -570,20 +609,28 @@ github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8 github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= +github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= +github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= +github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/tsdb v0.6.2-0.20190402121629-4f204dcbc150/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/prometheus/tsdb v0.10.0 h1:If5rVCMTp6W2SiRAQFlbpJNgVlgMEd+U2GZckwK38ic= +github.com/prometheus/tsdb v0.10.0/go.mod h1:oi49uRhEe9dPUTlS3JRZOwJuVi6tmh10QSgwXEyGCt4= github.com/rakyll/statik v0.1.6/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rjeczalik/notify v0.9.1 h1:CLCKso/QK1snAlnhNR/CNvNiFU2saUtjV0bx3EwNeCE= github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho= +github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8= +github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= @@ -594,6 +641,7 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= +github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/scylladb/go-set v1.0.2/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= @@ -605,6 +653,7 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5I github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= @@ -636,6 +685,7 @@ github.com/spf13/viper v1.6.3 h1:pDDu1OyEDTKzpJwdq4TiuLyMsUgRa/BT5cn5O62NoHs= github.com/spf13/viper v1.6.3/go.mod h1:jUMtyi0/lB5yZH/FjyGAoH7IMNrIhlBf6pXZmbMDvzw= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 h1:Gb2Tyox57NRNuZ2d3rmvB3pcmbu7O1RS3m8WRx7ilrg= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= +github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 h1:gIlAHnH1vJb5vwEjIp5kBj/eu99p/bl0Ay2goiPe5xE= github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw= github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 h1:njlZPzLwU639dk2kqnCPPv+wNjq7Xb6EfUxe/oX0/NM= @@ -654,6 +704,8 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= @@ -711,6 +763,8 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/ybbus/jsonrpc v2.1.2+incompatible h1:V4mkE9qhbDQ92/MLMIhlhMSbz8jNXdagC3xBR5NDwaQ= github.com/ybbus/jsonrpc v2.1.2+incompatible/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= github.com/zquestz/grab v0.0.0-20190224022517-abcee96e61b1 h1:1qKTeMTSIEvRIjvVYzgcRp0xVp0eoiRTTiHSncb5gD8= github.com/zquestz/grab v0.0.0-20190224022517-abcee96e61b1/go.mod h1:bslhAiUxakrA6z6CHmVyvkfpnxx18RJBwVyx2TluJWw= @@ -745,10 +799,13 @@ golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200406173513-056763e48d71/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 h1:phUcVbl53swtrUN8kQEXFhUxPlIlWyBfKmidCu7P95o= +golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= @@ -764,6 +821,8 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -791,11 +850,14 @@ golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -804,16 +866,19 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -824,8 +889,10 @@ golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -834,10 +901,17 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 h1:5B6i6EAiSYyejWfvc5Rc9BbI3rzIsrrXfAQBWnYfn+w= golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed h1:J22ig1FUekjjkmZUM7pTKixYm8DvrYsvrBZdunYeIuQ= golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 h1:AvbQYmiaaaza3cW3QXRyPo5kYgpFIzOAfeAAN7m3qQ4= golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88= +golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -864,6 +938,8 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= @@ -883,6 +959,9 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84 h1:pSLkPbrjnPyLDYUO2VM9mDLqo2V6CFBY84lFSZAfoi4= google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6 h1:iRN4+t0lvZX/l9gH14ARF9i58tsVa5a97k6aH95rC3Y= +google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= @@ -911,11 +990,15 @@ google.golang.org/protobuf v1.22.0 h1:cJv5/xdbk1NnMPR1VP9+HU6gupuG9MLBoH1r6RHZ2M google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= diff --git a/merkle/merkletree.db b/merkle/merkletree.db new file mode 100755 index 0000000000000000000000000000000000000000..9c87f62aa36ffec02d13420cf1de50f2c2cd4195 GIT binary patch literal 8864 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 literal 0 HcmV?d00001 diff --git a/native/service/cross_chain_manager/kai/handler.go b/native/service/cross_chain_manager/kai/handler.go new file mode 100644 index 000000000..49adf7185 --- /dev/null +++ b/native/service/cross_chain_manager/kai/handler.go @@ -0,0 +1,260 @@ +/* + * Copyright (C) 2020 The poly network Authors + * This file is part of The poly network library. + * + * The poly network is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The poly network is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The poly network . If not, see . + */ + +package kai + +import ( + "bytes" + "encoding/hex" + "encoding/json" + "fmt" + "math/big" + + ecommon "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/light" + "github.com/ethereum/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/trie" + "github.com/kardiachain/go-kardia/types" + "github.com/polynetwork/poly/common" + "github.com/polynetwork/poly/common/log" + "github.com/polynetwork/poly/native" + scom "github.com/polynetwork/poly/native/service/cross_chain_manager/common" + "github.com/polynetwork/poly/native/service/governance/side_chain_manager" + "github.com/polynetwork/poly/native/service/header_sync/kai" +) + +// Handler ... +type HecoHandler struct { +} + +// NewHandler ... +func NewHecoHandler() *HecoHandler { + return &HecoHandler{} +} + +// MakeDepositProposal ... +func (h *HecoHandler) MakeDepositProposal(service *native.NativeService) (*scom.MakeTxParam, error) { + params := new(scom.EntranceParam) + if err := params.Deserialization(common.NewZeroCopySource(service.GetInput())); err != nil { + return nil, fmt.Errorf("KAI MakeDepositProposal, contract params deserialize error: %s", err) + } + info, err := kai.GetEpochSwitchInfo(service, params.SourceChainID) + if err != nil { + return nil, fmt.Errorf("KAI MakeDepositProposal, failed to get epoch switching height: %v", err) + } + if info.Height > int64(params.Height) { + return nil, fmt.Errorf("KAI MakeDepositProposal, the height %d of header is lower than epoch "+ + "switching height %d", params.Height, info.Height) + } + + if len(params.HeaderOrCrossChainMsg) == 0 { + return nil, fmt.Errorf("you must commit the header used to verify transaction's proof and get none") + } + + var myHeader kai.Header + if err := json.Unmarshal(params.HeaderOrCrossChainMsg, &myHeader); err != nil { + return nil, fmt.Errorf("KAI MakeDepositProposal, unmarshal cosmos header failed: %v", err) + } + if myHeader.Header.Height != uint64(params.Height) { + return nil, fmt.Errorf("KAI MakeDepositProposal, "+ + "height of your header is %d not equal to %d in parameter", myHeader.Header.Height, params.Height) + } + + if err = kai.VerifyHeader(&myHeader, info); err != nil { + return nil, fmt.Errorf("KAI MakeDepositProposal, failed to verify KAI header: %v", err) + } + + sideChain, err := side_chain_manager.GetSideChain(service, params.SourceChainID) + if err != nil { + return nil, fmt.Errorf("KAI MakeDepositProposal, side_chain_manager.GetSideChain error: %v", err) + } + + if !myHeader.Header.ValidatorsHash.Equal(myHeader.Header.NextValidatorsHash) && + int64(myHeader.Header.Height) > info.Height { + kai.PutEpochSwitchInfo(service, params.SourceChainID, &kai.EpochSwitchInfo{ + Height: int64(myHeader.Header.Height), + BlockHash: myHeader.Header.Hash().Bytes(), + NextValidatorsHash: myHeader.Header.NextValidatorsHash.Bytes(), + ChainID: "", + }) + } + + value, err := verifyTx(myHeader.Header, service, params.Proof, params.Extra, params.SourceChainID, params.Height, sideChain) + if err != nil { + return nil, fmt.Errorf("KAI MakeDepositProposal, verifyFromEthTx error: %s", err) + } + + if err := scom.CheckDoneTx(service, value.CrossChainID, params.SourceChainID); err != nil { + return nil, fmt.Errorf("KAI MakeDepositProposal, check done transaction error:%s", err) + } + if err := scom.PutDoneTx(service, value.CrossChainID, params.SourceChainID); err != nil { + return nil, fmt.Errorf("KAI MakeDepositProposal, PutDoneTx error:%s", err) + } + + return nil, nil +} + +func verifyTx(header *types.Header, native *native.NativeService, proof, extra []byte, fromChainID uint64, height uint32, sideChain *side_chain_manager.SideChain) (param *scom.MakeTxParam, err error) { + kaiProof := new(Proof) + err = json.Unmarshal(proof, kaiProof) + if err != nil { + return nil, fmt.Errorf("verifyTx, unmarshal proof error:%s", err) + } + + if len(kaiProof.StorageProofs) != 1 { + return nil, fmt.Errorf("verifyTx, incorrect proof format") + } + + proofResult, err := verifyMerkleProof(kaiProof, header, sideChain.CCMCAddress) + if err != nil { + return nil, fmt.Errorf("verifyTx, verifyMerkleProof error:%v", err) + } + + if proofResult == nil { + return nil, fmt.Errorf("verifyTx, verifyMerkleProof failed") + } + + if !checkProofResult(proofResult, extra) { + return nil, fmt.Errorf("verifyTx, verify proof value hash failed, proof result:%x, extra:%x", proofResult, extra) + } + + data := common.NewZeroCopySource(extra) + txParam := new(scom.MakeTxParam) + if err := txParam.Deserialization(data); err != nil { + return nil, fmt.Errorf("verifyTx, deserialize merkleValue error:%s", err) + } + return txParam, nil +} + +// Proof ... +type Proof struct { + Address string `json:"address"` + Balance string `json:"balance"` + CodeHash string `json:"codeHash"` + Nonce string `json:"nonce"` + StorageHash string `json:"storageHash"` + AccountProof []string `json:"accountProof"` + StorageProofs []StorageProof `json:"storageProof"` +} + +// StorageProof ... +type StorageProof struct { + Key string `json:"key"` + Value string `json:"value"` + Proof []string `json:"proof"` +} + +// ProofAccount ... +type ProofAccount struct { + Nounce *big.Int + Balance *big.Int + Storage ecommon.Hash + Codehash ecommon.Hash +} + +func verifyMerkleProof(kaiProof *Proof, blockData *types.Header, contractAddr []byte) ([]byte, error) { + //1. prepare verify account + nodeList := new(light.NodeList) + + for _, s := range kaiProof.AccountProof { + p := scom.Replace0x(s) + nodeList.Put(nil, ecommon.Hex2Bytes(p)) + } + ns := nodeList.NodeSet() + + addr := ecommon.Hex2Bytes(scom.Replace0x(kaiProof.Address)) + if !bytes.Equal(addr, contractAddr) { + return nil, fmt.Errorf("verifyMerkleProof, contract address is error, proof address: %s, side chain address: %s", kaiProof.Address, hex.EncodeToString(contractAddr)) + } + acctKey := crypto.Keccak256(addr) + + //2. verify account proof + acctVal, err := trie.VerifyProof(ecommon.Hash(blockData.AppHash), acctKey, ns) + if err != nil { + return nil, fmt.Errorf("verifyMerkleProof, verify account proof error:%s", err) + } + + nounce := new(big.Int) + _, ok := nounce.SetString(scom.Replace0x(kaiProof.Nonce), 16) + if !ok { + return nil, fmt.Errorf("verifyMerkleProof, invalid format of nounce:%s", kaiProof.Nonce) + } + + balance := new(big.Int) + _, ok = balance.SetString(scom.Replace0x(kaiProof.Balance), 16) + if !ok { + return nil, fmt.Errorf("verifyMerkleProof, invalid format of balance:%s", kaiProof.Balance) + } + + storageHash := ecommon.HexToHash(scom.Replace0x(kaiProof.StorageHash)) + codeHash := ecommon.HexToHash(scom.Replace0x(kaiProof.CodeHash)) + + acct := &ProofAccount{ + Nounce: nounce, + Balance: balance, + Storage: storageHash, + Codehash: codeHash, + } + + acctrlp, err := rlp.EncodeToBytes(acct) + if err != nil { + return nil, err + } + + if !bytes.Equal(acctrlp, acctVal) { + return nil, fmt.Errorf("verifyMerkleProof, verify account proof failed, wanted:%v, get:%v", acctrlp, acctVal) + } + + //3.verify storage proof + nodeList = new(light.NodeList) + if len(kaiProof.StorageProofs) != 1 { + return nil, fmt.Errorf("verifyMerkleProof, invalid storage proof format") + } + + sp := kaiProof.StorageProofs[0] + storageKey := crypto.Keccak256(ecommon.HexToHash(scom.Replace0x(sp.Key)).Bytes()) + + for _, prf := range sp.Proof { + nodeList.Put(nil, ecommon.Hex2Bytes(scom.Replace0x(prf))) + } + + ns = nodeList.NodeSet() + val, err := trie.VerifyProof(storageHash, storageKey, ns) + if err != nil { + return nil, fmt.Errorf("verifyMerkleProof, verify storage proof error:%s", err) + } + + return val, nil +} + +func checkProofResult(result, value []byte) bool { + var tempBytes []byte + err := rlp.DecodeBytes(result, &tempBytes) + if err != nil { + log.Errorf("checkProofResult, rlp.DecodeBytes error:%s\n", err) + return false + } + // + var s []byte + for i := len(tempBytes); i < 32; i++ { + s = append(s, 0) + } + s = append(s, tempBytes...) + hash := crypto.Keccak256(value) + return bytes.Equal(s, hash) +} diff --git a/native/service/cross_chain_manager/kai/handler_test.go b/native/service/cross_chain_manager/kai/handler_test.go new file mode 100644 index 000000000..0fc6c7afe --- /dev/null +++ b/native/service/cross_chain_manager/kai/handler_test.go @@ -0,0 +1 @@ +package kai diff --git a/native/service/header_sync/kai/header_sync.go b/native/service/header_sync/kai/header_sync.go new file mode 100644 index 000000000..7789eb929 --- /dev/null +++ b/native/service/header_sync/kai/header_sync.go @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2020 The poly network Authors + * This file is part of The poly network library. + * + * The poly network is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The poly network is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The poly network . If not, see . + */ +package kai + +import ( + "encoding/json" + "fmt" + + "github.com/polynetwork/poly/common" + "github.com/polynetwork/poly/common/log" + "github.com/polynetwork/poly/native" + hscommon "github.com/polynetwork/poly/native/service/header_sync/common" +) + +// Handler ... +type Handler struct { +} + +// SyncBlockHeader ... +func (h *Handler) SyncBlockHeader(native *native.NativeService) error { + params := new(hscommon.SyncBlockHeaderParam) + if err := params.Deserialization(common.NewZeroCopySource(native.GetInput())); err != nil { + return fmt.Errorf("SyncBlockHeader, contract params deserialize error: %v", err) + } + cnt := 0 + info, err := GetEpochSwitchInfo(native, params.ChainID) + if err != nil { + return fmt.Errorf("SyncBlockHeader, get epoch switching height failed: %v", err) + } + for _, v := range params.Headers { + var myHeader Header + if err := json.Unmarshal(v, &myHeader); err != nil { + return fmt.Errorf("SyncBlockHeader failed to unmarshal header: %v", err) + } + + if myHeader.Header.NextValidatorsHash.Equal(myHeader.Header.ValidatorsHash) { + continue + } + if info.Height >= int64(myHeader.Header.Height) { + log.Debugf("SyncBlockHeader, height %d is lower or equal than epoch switching height %d", + myHeader.Header.Height, info.Height) + continue + } + if err = VerifyHeader(&myHeader, info); err != nil { + return fmt.Errorf("SyncBlockHeader, failed to verify header: %v", err) + } + info.NextValidatorsHash = myHeader.Header.NextValidatorsHash.Bytes() + info.Height = int64(myHeader.Header.Height) + info.BlockHash = myHeader.Header.Hash().Bytes() + cnt++ + } + if cnt == 0 { + return fmt.Errorf("no header you commited is useful") + } + PutEpochSwitchInfo(native, params.ChainID, info) + return nil +} + +func (this *Handler) SyncCrossChainMsg(native *native.NativeService) error { + return nil +} diff --git a/native/service/header_sync/kai/header_sync_test.go b/native/service/header_sync/kai/header_sync_test.go new file mode 100644 index 000000000..0fc6c7afe --- /dev/null +++ b/native/service/header_sync/kai/header_sync_test.go @@ -0,0 +1 @@ +package kai diff --git a/native/service/header_sync/kai/state.go b/native/service/header_sync/kai/state.go new file mode 100644 index 000000000..1125c17bb --- /dev/null +++ b/native/service/header_sync/kai/state.go @@ -0,0 +1,60 @@ +package kai + +import ( + "fmt" + + "github.com/kardiachain/go-kardia/lib/bytes" + "github.com/kardiachain/go-kardia/types" + "github.com/polynetwork/poly/common" +) + +type EpochSwitchInfo struct { + // The height where validators set changed last time. Poly only accept + // header and proof signed by new validators. That means the header + // can not be lower than this height. + Height int64 + + // Hash of the block at `Height`. Poly don't save the whole header. + // So we can identify the content of this block by `BlockHash`. + BlockHash bytes.HexBytes + + // The hash of new validators set which used to verify validators set + // committed with proof. + NextValidatorsHash bytes.HexBytes + + ChainID string +} + +func (info *EpochSwitchInfo) Serialization(sink *common.ZeroCopySink) { + sink.WriteInt64(info.Height) + sink.WriteVarBytes(info.BlockHash) + sink.WriteVarBytes(info.NextValidatorsHash) + sink.WriteString(info.ChainID) +} + +func (info *EpochSwitchInfo) Deserialization(source *common.ZeroCopySource) error { + var eof bool + info.Height, eof = source.NextInt64() + if eof { + return fmt.Errorf("deserialize height of EpochSwitchInfo failed") + } + info.BlockHash, eof = source.NextVarBytes() + if eof { + return fmt.Errorf("deserialize BlockHash of EpochSwitchInfo failed") + } + info.NextValidatorsHash, eof = source.NextVarBytes() + if eof { + return fmt.Errorf("deserialize NextValidatorsHash of EpochSwitchInfo failed") + } + info.ChainID, eof = source.NextString() + if eof { + return fmt.Errorf("deserialize ChainID of EpochSwitchInfo failed") + } + return nil +} + +type Header struct { + Header *types.Header + Commit *types.Commit + Vset *types.ValidatorSet +} diff --git a/native/service/header_sync/kai/utils.go b/native/service/header_sync/kai/utils.go new file mode 100644 index 000000000..c583b03b5 --- /dev/null +++ b/native/service/header_sync/kai/utils.go @@ -0,0 +1,69 @@ +package kai + +import ( + "bytes" + "fmt" + + "github.com/polynetwork/poly/common" + "github.com/polynetwork/poly/common/config" + cstates "github.com/polynetwork/poly/core/states" + "github.com/polynetwork/poly/native" + "github.com/polynetwork/poly/native/event" + hscommon "github.com/polynetwork/poly/native/service/header_sync/common" + "github.com/polynetwork/poly/native/service/utils" +) + +func VerifyHeader(myHeader *Header, info *EpochSwitchInfo) error { + valset := myHeader.Vset + // now verify this header + if !bytes.Equal(info.NextValidatorsHash, valset.Hash().Bytes()) { + return fmt.Errorf("VerifyHeader, block validator is not right, next validator hash: %s, "+ + "validator set hash: %s", info.NextValidatorsHash.String(), valset.Hash().Hex()) + } + if !myHeader.Header.ValidatorsHash.Equal(valset.Hash()) { + return fmt.Errorf("VerifyHeader, block validator is not right!, header validator hash: %s, "+ + "validator set hash: %s", myHeader.Header.ValidatorsHash.String(), valset.Hash().Hex()) + } + if err := valset.VerifyCommit(info.ChainID, myHeader.Header.LastBlockID, myHeader.Header.Height, myHeader.Commit); err != nil { + return err + } + return nil +} + +func GetEpochSwitchInfo(service *native.NativeService, chainId uint64) (*EpochSwitchInfo, error) { + val, err := service.GetCacheDB().Get( + utils.ConcatKey(utils.HeaderSyncContractAddress, []byte(hscommon.EPOCH_SWITCH), utils.GetUint64Bytes(chainId))) + if err != nil { + return nil, fmt.Errorf("failed to get epoch switching height: %v", err) + } + raw, err := cstates.GetValueFromRawStorageItem(val) + if err != nil { + return nil, fmt.Errorf("deserialize bytes from raw storage item err: %v", err) + } + info := &EpochSwitchInfo{} + if err = info.Deserialization(common.NewZeroCopySource(raw)); err != nil { + return nil, fmt.Errorf("failed to deserialize EpochSwitchInfo: %v", err) + } + return info, nil +} + +func PutEpochSwitchInfo(service *native.NativeService, chainId uint64, info *EpochSwitchInfo) { + sink := common.NewZeroCopySink(nil) + info.Serialization(sink) + service.GetCacheDB().Put( + utils.ConcatKey(utils.HeaderSyncContractAddress, []byte(hscommon.EPOCH_SWITCH), utils.GetUint64Bytes(chainId)), + cstates.GenRawStorageItem(sink.Bytes())) + notifyEpochSwitchInfo(service, chainId, info) +} + +func notifyEpochSwitchInfo(native *native.NativeService, chainID uint64, info *EpochSwitchInfo) { + if !config.DefConfig.Common.EnableEventLog { + return + } + native.AddNotify( + &event.NotifyEventInfo{ + ContractAddress: utils.HeaderSyncContractAddress, + States: []interface{}{chainID, info.BlockHash.String(), info.Height, + info.NextValidatorsHash.String(), info.ChainID, native.GetHeight()}, + }) +} diff --git a/validator/db/temp.db/000002.ldb b/validator/db/temp.db/000002.ldb new file mode 100644 index 0000000000000000000000000000000000000000..e0893f78097423771acadd3f594813d7d889024b GIT binary patch literal 181 zcmWd)VBlnAU}R(f126?57%%>-33cL7WC01Yfe20@=4RNwW9kXLEewiGX_+}CsYQA@ zsb#4-DM@-xr9ggWo>NYKey$r>N=68z3v8Bu)x-s2Aq<>MaC;cU;gW96TP2MRG9*9( Ogh2T3hHjNo_uBv%f*r8{ literal 0 HcmV?d00001 diff --git a/validator/db/temp.db/CURRENT b/validator/db/temp.db/CURRENT new file mode 100644 index 000000000..f7753e22a --- /dev/null +++ b/validator/db/temp.db/CURRENT @@ -0,0 +1 @@ +MANIFEST-000006 diff --git a/validator/db/temp.db/CURRENT.bak b/validator/db/temp.db/CURRENT.bak new file mode 100644 index 000000000..cacca7574 --- /dev/null +++ b/validator/db/temp.db/CURRENT.bak @@ -0,0 +1 @@ +MANIFEST-000004 diff --git a/validator/db/temp.db/LOCK b/validator/db/temp.db/LOCK new file mode 100644 index 000000000..e69de29bb diff --git a/validator/db/temp.db/LOG b/validator/db/temp.db/LOG new file mode 100644 index 000000000..40f9c018a --- /dev/null +++ b/validator/db/temp.db/LOG @@ -0,0 +1,25 @@ +=============== May 17, 2021 (+07) =============== +10:08:07.829273 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +10:08:07.836037 db@open opening +10:08:07.836757 version@stat F·[] S·0B[] Sc·[] +10:08:07.838543 db@janitor F·2 G·0 +10:08:07.838558 db@open done T·2.505998ms +=============== May 17, 2021 (+07) =============== +11:07:41.018899 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +11:07:41.019013 version@stat F·[] S·0B[] Sc·[] +11:07:41.019025 db@open opening +11:07:41.019048 journal@recovery F·1 +11:07:41.019476 journal@recovery recovering @1 +11:07:41.024746 memdb@flush created L0@2 N·1 S·181B "\x00,v1":"\x00,v1" +11:07:41.025036 version@stat F·[1] S·181B[181B] Sc·[0.25] +11:07:41.030363 db@janitor F·3 G·0 +11:07:41.030382 db@open done T·11.351415ms +=============== May 17, 2021 (+07) =============== +11:10:17.897615 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +11:10:17.897764 version@stat F·[1] S·181B[181B] Sc·[0.25] +11:10:17.897777 db@open opening +11:10:17.897812 journal@recovery F·1 +11:10:17.898145 journal@recovery recovering @3 +11:10:17.898591 version@stat F·[1] S·181B[181B] Sc·[0.25] +11:10:17.906994 db@janitor F·3 G·0 +11:10:17.907011 db@open done T·9.225448ms diff --git a/validator/db/temp.db/MANIFEST-000006 b/validator/db/temp.db/MANIFEST-000006 new file mode 100644 index 0000000000000000000000000000000000000000..87a8461577e7fcba6b28ab88651debee14ce1615 GIT binary patch literal 66 zcmYeE|8S=@10$nUPHI_dPD+xVQ)NkNd1i5{bAE0?Vo_pAei0KZGdl|tI|I{JMoyqg I1~5Rd0G}-mPyhe` literal 0 HcmV?d00001 From a187e362af9718e6fbd645675a11ed2599a9f89d Mon Sep 17 00:00:00 2001 From: dogecoindev Date: Mon, 17 May 2021 17:41:57 +0700 Subject: [PATCH 10/23] remove db --- core/store/ledgerstore/test/block/CURRENT | 1 - core/store/ledgerstore/test/block/LOCK | 0 core/store/ledgerstore/test/block/LOG | 6 ----- .../ledgerstore/test/block/MANIFEST-000000 | Bin 54 -> 0 bytes .../ledgerstore/test/ledger/block/CURRENT | 1 - core/store/ledgerstore/test/ledger/block/LOCK | 0 core/store/ledgerstore/test/ledger/block/LOG | 6 ----- .../test/ledger/block/MANIFEST-000000 | Bin 54 -> 0 bytes .../test/ledger/ledgerevent/CURRENT | 1 - .../ledgerstore/test/ledger/ledgerevent/LOCK | 0 .../ledgerstore/test/ledger/ledgerevent/LOG | 6 ----- .../test/ledger/ledgerevent/MANIFEST-000000 | Bin 54 -> 0 bytes .../ledgerstore/test/ledger/merkle_tree.db | 1 - .../ledgerstore/test/ledger/states/CURRENT | 1 - .../store/ledgerstore/test/ledger/states/LOCK | 0 core/store/ledgerstore/test/ledger/states/LOG | 6 ----- .../test/ledger/states/MANIFEST-000000 | Bin 54 -> 0 bytes core/store/ledgerstore/test/merkle_tree.db | 0 core/store/ledgerstore/test/state/CURRENT | 1 - core/store/ledgerstore/test/state/LOCK | 0 core/store/ledgerstore/test/state/LOG | 6 ----- .../ledgerstore/test/state/MANIFEST-000000 | Bin 54 -> 0 bytes validator/db/temp.db/000002.ldb | Bin 181 -> 0 bytes validator/db/temp.db/CURRENT | 1 - validator/db/temp.db/CURRENT.bak | 1 - validator/db/temp.db/LOCK | 0 validator/db/temp.db/LOG | 25 ------------------ validator/db/temp.db/MANIFEST-000006 | Bin 66 -> 0 bytes 28 files changed, 63 deletions(-) delete mode 100644 core/store/ledgerstore/test/block/CURRENT delete mode 100644 core/store/ledgerstore/test/block/LOCK delete mode 100644 core/store/ledgerstore/test/block/LOG delete mode 100644 core/store/ledgerstore/test/block/MANIFEST-000000 delete mode 100644 core/store/ledgerstore/test/ledger/block/CURRENT delete mode 100644 core/store/ledgerstore/test/ledger/block/LOCK delete mode 100644 core/store/ledgerstore/test/ledger/block/LOG delete mode 100644 core/store/ledgerstore/test/ledger/block/MANIFEST-000000 delete mode 100644 core/store/ledgerstore/test/ledger/ledgerevent/CURRENT delete mode 100644 core/store/ledgerstore/test/ledger/ledgerevent/LOCK delete mode 100644 core/store/ledgerstore/test/ledger/ledgerevent/LOG delete mode 100644 core/store/ledgerstore/test/ledger/ledgerevent/MANIFEST-000000 delete mode 100755 core/store/ledgerstore/test/ledger/merkle_tree.db delete mode 100644 core/store/ledgerstore/test/ledger/states/CURRENT delete mode 100644 core/store/ledgerstore/test/ledger/states/LOCK delete mode 100644 core/store/ledgerstore/test/ledger/states/LOG delete mode 100644 core/store/ledgerstore/test/ledger/states/MANIFEST-000000 delete mode 100755 core/store/ledgerstore/test/merkle_tree.db delete mode 100644 core/store/ledgerstore/test/state/CURRENT delete mode 100644 core/store/ledgerstore/test/state/LOCK delete mode 100644 core/store/ledgerstore/test/state/LOG delete mode 100644 core/store/ledgerstore/test/state/MANIFEST-000000 delete mode 100644 validator/db/temp.db/000002.ldb delete mode 100644 validator/db/temp.db/CURRENT delete mode 100644 validator/db/temp.db/CURRENT.bak delete mode 100644 validator/db/temp.db/LOCK delete mode 100644 validator/db/temp.db/LOG delete mode 100644 validator/db/temp.db/MANIFEST-000006 diff --git a/core/store/ledgerstore/test/block/CURRENT b/core/store/ledgerstore/test/block/CURRENT deleted file mode 100644 index feda7d6b2..000000000 --- a/core/store/ledgerstore/test/block/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000000 diff --git a/core/store/ledgerstore/test/block/LOCK b/core/store/ledgerstore/test/block/LOCK deleted file mode 100644 index e69de29bb..000000000 diff --git a/core/store/ledgerstore/test/block/LOG b/core/store/ledgerstore/test/block/LOG deleted file mode 100644 index 0fde3b290..000000000 --- a/core/store/ledgerstore/test/block/LOG +++ /dev/null @@ -1,6 +0,0 @@ -=============== May 17, 2021 (+07) =============== -11:10:17.023901 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -11:10:17.032333 db@open opening -11:10:17.032765 version@stat F·[] S·0B[] Sc·[] -11:10:17.037842 db@janitor F·2 G·0 -11:10:17.037869 db@open done T·5.5158ms diff --git a/core/store/ledgerstore/test/block/MANIFEST-000000 b/core/store/ledgerstore/test/block/MANIFEST-000000 deleted file mode 100644 index 9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD diff --git a/core/store/ledgerstore/test/ledger/block/CURRENT b/core/store/ledgerstore/test/ledger/block/CURRENT deleted file mode 100644 index feda7d6b2..000000000 --- a/core/store/ledgerstore/test/ledger/block/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000000 diff --git a/core/store/ledgerstore/test/ledger/block/LOCK b/core/store/ledgerstore/test/ledger/block/LOCK deleted file mode 100644 index e69de29bb..000000000 diff --git a/core/store/ledgerstore/test/ledger/block/LOG b/core/store/ledgerstore/test/ledger/block/LOG deleted file mode 100644 index 5b5238ab4..000000000 --- a/core/store/ledgerstore/test/ledger/block/LOG +++ /dev/null @@ -1,6 +0,0 @@ -=============== May 17, 2021 (+07) =============== -11:10:16.986154 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -11:10:16.993916 db@open opening -11:10:16.995678 version@stat F·[] S·0B[] Sc·[] -11:10:17.000560 db@janitor F·2 G·0 -11:10:17.000607 db@open done T·6.660819ms diff --git a/core/store/ledgerstore/test/ledger/block/MANIFEST-000000 b/core/store/ledgerstore/test/ledger/block/MANIFEST-000000 deleted file mode 100644 index 9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD diff --git a/core/store/ledgerstore/test/ledger/ledgerevent/CURRENT b/core/store/ledgerstore/test/ledger/ledgerevent/CURRENT deleted file mode 100644 index feda7d6b2..000000000 --- a/core/store/ledgerstore/test/ledger/ledgerevent/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000000 diff --git a/core/store/ledgerstore/test/ledger/ledgerevent/LOCK b/core/store/ledgerstore/test/ledger/ledgerevent/LOCK deleted file mode 100644 index e69de29bb..000000000 diff --git a/core/store/ledgerstore/test/ledger/ledgerevent/LOG b/core/store/ledgerstore/test/ledger/ledgerevent/LOG deleted file mode 100644 index 1707ba97b..000000000 --- a/core/store/ledgerstore/test/ledger/ledgerevent/LOG +++ /dev/null @@ -1,6 +0,0 @@ -=============== May 17, 2021 (+07) =============== -11:10:17.012451 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -11:10:17.018845 db@open opening -11:10:17.019081 version@stat F·[] S·0B[] Sc·[] -11:10:17.023639 db@janitor F·2 G·0 -11:10:17.023689 db@open done T·4.824619ms diff --git a/core/store/ledgerstore/test/ledger/ledgerevent/MANIFEST-000000 b/core/store/ledgerstore/test/ledger/ledgerevent/MANIFEST-000000 deleted file mode 100644 index 9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD diff --git a/core/store/ledgerstore/test/ledger/merkle_tree.db b/core/store/ledgerstore/test/ledger/merkle_tree.db deleted file mode 100755 index cfc241656..000000000 --- a/core/store/ledgerstore/test/ledger/merkle_tree.db +++ /dev/null @@ -1 +0,0 @@ -œž1¬‚VÊ/%…ƒß&-¼}ohò 0CÕÉšJå§9lé \ No newline at end of file diff --git a/core/store/ledgerstore/test/ledger/states/CURRENT b/core/store/ledgerstore/test/ledger/states/CURRENT deleted file mode 100644 index feda7d6b2..000000000 --- a/core/store/ledgerstore/test/ledger/states/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000000 diff --git a/core/store/ledgerstore/test/ledger/states/LOCK b/core/store/ledgerstore/test/ledger/states/LOCK deleted file mode 100644 index e69de29bb..000000000 diff --git a/core/store/ledgerstore/test/ledger/states/LOG b/core/store/ledgerstore/test/ledger/states/LOG deleted file mode 100644 index eb83d2cf3..000000000 --- a/core/store/ledgerstore/test/ledger/states/LOG +++ /dev/null @@ -1,6 +0,0 @@ -=============== May 17, 2021 (+07) =============== -11:10:17.000802 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -11:10:17.007586 db@open opening -11:10:17.007952 version@stat F·[] S·0B[] Sc·[] -11:10:17.012274 db@janitor F·2 G·0 -11:10:17.012298 db@open done T·4.689132ms diff --git a/core/store/ledgerstore/test/ledger/states/MANIFEST-000000 b/core/store/ledgerstore/test/ledger/states/MANIFEST-000000 deleted file mode 100644 index 9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD diff --git a/core/store/ledgerstore/test/merkle_tree.db b/core/store/ledgerstore/test/merkle_tree.db deleted file mode 100755 index e69de29bb..000000000 diff --git a/core/store/ledgerstore/test/state/CURRENT b/core/store/ledgerstore/test/state/CURRENT deleted file mode 100644 index feda7d6b2..000000000 --- a/core/store/ledgerstore/test/state/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000000 diff --git a/core/store/ledgerstore/test/state/LOCK b/core/store/ledgerstore/test/state/LOCK deleted file mode 100644 index e69de29bb..000000000 diff --git a/core/store/ledgerstore/test/state/LOG b/core/store/ledgerstore/test/state/LOG deleted file mode 100644 index a0f86ce62..000000000 --- a/core/store/ledgerstore/test/state/LOG +++ /dev/null @@ -1,6 +0,0 @@ -=============== May 17, 2021 (+07) =============== -11:10:17.038075 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -11:10:17.044648 db@open opening -11:10:17.044847 version@stat F·[] S·0B[] Sc·[] -11:10:17.050382 db@janitor F·2 G·0 -11:10:17.050408 db@open done T·5.740115ms diff --git a/core/store/ledgerstore/test/state/MANIFEST-000000 b/core/store/ledgerstore/test/state/MANIFEST-000000 deleted file mode 100644 index 9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD diff --git a/validator/db/temp.db/000002.ldb b/validator/db/temp.db/000002.ldb deleted file mode 100644 index e0893f78097423771acadd3f594813d7d889024b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 181 zcmWd)VBlnAU}R(f126?57%%>-33cL7WC01Yfe20@=4RNwW9kXLEewiGX_+}CsYQA@ zsb#4-DM@-xr9ggWo>NYKey$r>N=68z3v8Bu)x-s2Aq<>MaC;cU;gW96TP2MRG9*9( Ogh2T3hHjNo_uBv%f*r8{ diff --git a/validator/db/temp.db/CURRENT b/validator/db/temp.db/CURRENT deleted file mode 100644 index f7753e22a..000000000 --- a/validator/db/temp.db/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000006 diff --git a/validator/db/temp.db/CURRENT.bak b/validator/db/temp.db/CURRENT.bak deleted file mode 100644 index cacca7574..000000000 --- a/validator/db/temp.db/CURRENT.bak +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000004 diff --git a/validator/db/temp.db/LOCK b/validator/db/temp.db/LOCK deleted file mode 100644 index e69de29bb..000000000 diff --git a/validator/db/temp.db/LOG b/validator/db/temp.db/LOG deleted file mode 100644 index 40f9c018a..000000000 --- a/validator/db/temp.db/LOG +++ /dev/null @@ -1,25 +0,0 @@ -=============== May 17, 2021 (+07) =============== -10:08:07.829273 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -10:08:07.836037 db@open opening -10:08:07.836757 version@stat F·[] S·0B[] Sc·[] -10:08:07.838543 db@janitor F·2 G·0 -10:08:07.838558 db@open done T·2.505998ms -=============== May 17, 2021 (+07) =============== -11:07:41.018899 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -11:07:41.019013 version@stat F·[] S·0B[] Sc·[] -11:07:41.019025 db@open opening -11:07:41.019048 journal@recovery F·1 -11:07:41.019476 journal@recovery recovering @1 -11:07:41.024746 memdb@flush created L0@2 N·1 S·181B "\x00,v1":"\x00,v1" -11:07:41.025036 version@stat F·[1] S·181B[181B] Sc·[0.25] -11:07:41.030363 db@janitor F·3 G·0 -11:07:41.030382 db@open done T·11.351415ms -=============== May 17, 2021 (+07) =============== -11:10:17.897615 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -11:10:17.897764 version@stat F·[1] S·181B[181B] Sc·[0.25] -11:10:17.897777 db@open opening -11:10:17.897812 journal@recovery F·1 -11:10:17.898145 journal@recovery recovering @3 -11:10:17.898591 version@stat F·[1] S·181B[181B] Sc·[0.25] -11:10:17.906994 db@janitor F·3 G·0 -11:10:17.907011 db@open done T·9.225448ms diff --git a/validator/db/temp.db/MANIFEST-000006 b/validator/db/temp.db/MANIFEST-000006 deleted file mode 100644 index 87a8461577e7fcba6b28ab88651debee14ce1615..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 66 zcmYeE|8S=@10$nUPHI_dPD+xVQ)NkNd1i5{bAE0?Vo_pAei0KZGdl|tI|I{JMoyqg I1~5Rd0G}-mPyhe` From 6be817730090350043295a1b1a4b7c68780815d2 Mon Sep 17 00:00:00 2001 From: dogecoindev Date: Mon, 17 May 2021 18:05:32 +0700 Subject: [PATCH 11/23] add kai router --- native/service/cross_chain_manager/entrance.go | 3 +++ native/service/cross_chain_manager/kai/handler.go | 8 ++++---- native/service/utils/params.go | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/native/service/cross_chain_manager/entrance.go b/native/service/cross_chain_manager/entrance.go index 329118c8b..23612fabd 100644 --- a/native/service/cross_chain_manager/entrance.go +++ b/native/service/cross_chain_manager/entrance.go @@ -28,6 +28,7 @@ import ( "github.com/polynetwork/poly/native/service/cross_chain_manager/cosmos" "github.com/polynetwork/poly/native/service/cross_chain_manager/eth" "github.com/polynetwork/poly/native/service/cross_chain_manager/heco" + "github.com/polynetwork/poly/native/service/cross_chain_manager/kai" "github.com/polynetwork/poly/native/service/cross_chain_manager/msc" "github.com/polynetwork/poly/native/service/cross_chain_manager/neo" "github.com/polynetwork/poly/native/service/cross_chain_manager/okex" @@ -80,6 +81,8 @@ func GetChainHandler(router uint64) (scom.ChainHandler, error) { return msc.NewHandler(), nil case utils.OKEX_ROUTER: return okex.NewHandler(), nil + case utils.KAI_ROUTER: + return kai.NewHandler(), nil default: return nil, fmt.Errorf("not a supported router:%d", router) } diff --git a/native/service/cross_chain_manager/kai/handler.go b/native/service/cross_chain_manager/kai/handler.go index 49adf7185..2dab3a85c 100644 --- a/native/service/cross_chain_manager/kai/handler.go +++ b/native/service/cross_chain_manager/kai/handler.go @@ -39,16 +39,16 @@ import ( ) // Handler ... -type HecoHandler struct { +type Handler struct { } // NewHandler ... -func NewHecoHandler() *HecoHandler { - return &HecoHandler{} +func NewHandler() *Handler { + return &Handler{} } // MakeDepositProposal ... -func (h *HecoHandler) MakeDepositProposal(service *native.NativeService) (*scom.MakeTxParam, error) { +func (h *Handler) MakeDepositProposal(service *native.NativeService) (*scom.MakeTxParam, error) { params := new(scom.EntranceParam) if err := params.Deserialization(common.NewZeroCopySource(service.GetInput())); err != nil { return nil, fmt.Errorf("KAI MakeDepositProposal, contract params deserialize error: %s", err) diff --git a/native/service/utils/params.go b/native/service/utils/params.go index 605234a8b..5ce42bf29 100644 --- a/native/service/utils/params.go +++ b/native/service/utils/params.go @@ -49,4 +49,5 @@ var ( ZILLIQA_ROUTER = uint64(9) MSC_ROUTER = uint64(10) OKEX_ROUTER = uint64(12) + KAI_ROUTER = uint64(13) ) From d2d6694335549178570e766cb915244b0669d0af Mon Sep 17 00:00:00 2001 From: dogecoindev Date: Tue, 18 May 2021 14:41:10 +0700 Subject: [PATCH 12/23] update import go-eth version --- go.mod | 4 ++-- go.sum | 3 +++ native/service/cross_chain_manager/kai/handler.go | 10 +++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index b9b1ef17c..3a3479fd6 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/btcsuite/btcd v0.21.0-beta github.com/btcsuite/btcutil v1.0.2 github.com/cosmos/cosmos-sdk v0.39.1 - github.com/ethereum/go-ethereum v1.9.18 + github.com/ethereum/go-ethereum v1.9.15 github.com/gcash/bchd v0.16.5 github.com/gcash/bchutil v0.0.0-20200506001747-c2894cd54b33 github.com/gorilla/websocket v1.4.2 @@ -16,7 +16,7 @@ require ( github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c github.com/itchyny/base58-go v0.1.0 github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43 - github.com/kardiachain/go-kardia v1.1.1-0.20210514114009-042c640f55d4 // indirect + github.com/kardiachain/go-kardia v1.1.1-0.20210518073513-843096e91762 // indirect github.com/ontio/ontology v1.11.1-0.20200812075204-26cf1fa5dd47 github.com/ontio/ontology-crypto v1.0.9 github.com/ontio/ontology-eventbus v0.9.1 diff --git a/go.sum b/go.sum index 7d5a8a35a..2b3b22779 100644 --- a/go.sum +++ b/go.sum @@ -436,6 +436,8 @@ github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356 h1:I/yrLt2WilKxlQKCM5 github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= github.com/kardiachain/go-kardia v1.1.1-0.20210514114009-042c640f55d4 h1:vYkCSECIwErZ8YhymhOYySiieROmbKk+3/rIsU1MUgE= github.com/kardiachain/go-kardia v1.1.1-0.20210514114009-042c640f55d4/go.mod h1:XV2KPJf+Ib3es9iAFH5Io5fISzHpu7pk06um9bgAVKU= +github.com/kardiachain/go-kardia v1.1.1-0.20210518073513-843096e91762 h1:Jkua+KxKgB3unn8wcCfkylIn8PVcrzVGThxHcrijkbA= +github.com/kardiachain/go-kardia v1.1.1-0.20210518073513-843096e91762/go.mod h1:dIcZ5VO21q0HAjL9LiHqJ8bKMDkoE3T/4H0vy8urggs= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= @@ -685,6 +687,7 @@ github.com/spf13/viper v1.6.3 h1:pDDu1OyEDTKzpJwdq4TiuLyMsUgRa/BT5cn5O62NoHs= github.com/spf13/viper v1.6.3/go.mod h1:jUMtyi0/lB5yZH/FjyGAoH7IMNrIhlBf6pXZmbMDvzw= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 h1:Gb2Tyox57NRNuZ2d3rmvB3pcmbu7O1RS3m8WRx7ilrg= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= +github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48 h1:ju5UTwk5Odtm4trrY+4Ca4RMj5OyXbmVeDAVad2T0Jw= github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 h1:gIlAHnH1vJb5vwEjIp5kBj/eu99p/bl0Ay2goiPe5xE= github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw= diff --git a/native/service/cross_chain_manager/kai/handler.go b/native/service/cross_chain_manager/kai/handler.go index 2dab3a85c..dcc71a7d3 100644 --- a/native/service/cross_chain_manager/kai/handler.go +++ b/native/service/cross_chain_manager/kai/handler.go @@ -35,7 +35,7 @@ import ( "github.com/polynetwork/poly/native" scom "github.com/polynetwork/poly/native/service/cross_chain_manager/common" "github.com/polynetwork/poly/native/service/governance/side_chain_manager" - "github.com/polynetwork/poly/native/service/header_sync/kai" + hskai "github.com/polynetwork/poly/native/service/header_sync/kai" ) // Handler ... @@ -53,7 +53,7 @@ func (h *Handler) MakeDepositProposal(service *native.NativeService) (*scom.Make if err := params.Deserialization(common.NewZeroCopySource(service.GetInput())); err != nil { return nil, fmt.Errorf("KAI MakeDepositProposal, contract params deserialize error: %s", err) } - info, err := kai.GetEpochSwitchInfo(service, params.SourceChainID) + info, err := hskai.GetEpochSwitchInfo(service, params.SourceChainID) if err != nil { return nil, fmt.Errorf("KAI MakeDepositProposal, failed to get epoch switching height: %v", err) } @@ -66,7 +66,7 @@ func (h *Handler) MakeDepositProposal(service *native.NativeService) (*scom.Make return nil, fmt.Errorf("you must commit the header used to verify transaction's proof and get none") } - var myHeader kai.Header + var myHeader hskai.Header if err := json.Unmarshal(params.HeaderOrCrossChainMsg, &myHeader); err != nil { return nil, fmt.Errorf("KAI MakeDepositProposal, unmarshal cosmos header failed: %v", err) } @@ -75,7 +75,7 @@ func (h *Handler) MakeDepositProposal(service *native.NativeService) (*scom.Make "height of your header is %d not equal to %d in parameter", myHeader.Header.Height, params.Height) } - if err = kai.VerifyHeader(&myHeader, info); err != nil { + if err = hskai.VerifyHeader(&myHeader, info); err != nil { return nil, fmt.Errorf("KAI MakeDepositProposal, failed to verify KAI header: %v", err) } @@ -86,7 +86,7 @@ func (h *Handler) MakeDepositProposal(service *native.NativeService) (*scom.Make if !myHeader.Header.ValidatorsHash.Equal(myHeader.Header.NextValidatorsHash) && int64(myHeader.Header.Height) > info.Height { - kai.PutEpochSwitchInfo(service, params.SourceChainID, &kai.EpochSwitchInfo{ + hskai.PutEpochSwitchInfo(service, params.SourceChainID, &hskai.EpochSwitchInfo{ Height: int64(myHeader.Header.Height), BlockHash: myHeader.Header.Hash().Bytes(), NextValidatorsHash: myHeader.Header.NextValidatorsHash.Bytes(), From 4034bfb3ef8784048ccc6b5acd90e467a9f15228 Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Tue, 18 May 2021 16:38:34 +0800 Subject: [PATCH 13/23] update neo3 state root GetMessage() --- .../cross_chain_manager/neo3/neo_handler_test.go | 4 ++-- .../service/governance/neo3_state_manager/utils.go | 2 +- native/service/header_sync/neo3/states.go | 14 +++++++++++--- native/service/header_sync/neo3/utils.go | 11 ++++++++--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/native/service/cross_chain_manager/neo3/neo_handler_test.go b/native/service/cross_chain_manager/neo3/neo_handler_test.go index 4b3bae11e..9923791b1 100644 --- a/native/service/cross_chain_manager/neo3/neo_handler_test.go +++ b/native/service/cross_chain_manager/neo3/neo_handler_test.go @@ -160,11 +160,11 @@ func Test_Neo_MakeDepositProposal(t *testing.T) { func TestNEOHandler_SetCcmcId(t *testing.T) { // test positive int - idp := 215 + idp := 12 idpBytes := helper.IntToBytes(idp) ss := helper.BytesToHex(idpBytes) log.Println(ss) - assert.Equal(t, "d7000000", ss) + assert.Equal(t, "0c000000", ss) idp2 := int(helper.BytesToUInt32(idpBytes)) assert.Equal(t, idp, idp2) diff --git a/native/service/governance/neo3_state_manager/utils.go b/native/service/governance/neo3_state_manager/utils.go index aec64922a..f9ad50f19 100644 --- a/native/service/governance/neo3_state_manager/utils.go +++ b/native/service/governance/neo3_state_manager/utils.go @@ -92,7 +92,7 @@ func putStateValidators(native *native.NativeService, stateValidators []string) } mm[v] = v } - // convert map back to UInt160 array + // convert map back to string array newSVs := make([]string, 0) for _, v := range mm { newSVs = append(newSVs, v) diff --git a/native/service/header_sync/neo3/states.go b/native/service/header_sync/neo3/states.go index c766998a6..280067ad9 100644 --- a/native/service/header_sync/neo3/states.go +++ b/native/service/header_sync/neo3/states.go @@ -118,7 +118,7 @@ func (this *NeoCrossChainMsg) GetScriptHash() (*helper.UInt160, error) { if len(this.Witnesses) == 0 { return nil, fmt.Errorf("NeoCrossChainMsg.Witness incorrect length") } - verificationScriptBs, err := crypto.Base64Decode(this.Witnesses[0].Verification) // base64 + verificationScriptBs, err := crypto.Base64Decode(this.Witnesses[0].Verification) // base64 if err != nil { return nil, fmt.Errorf("NeoCrossChainMsg.Witness.Verification decode error: %s", err) } @@ -130,10 +130,18 @@ func (this *NeoCrossChainMsg) GetScriptHash() (*helper.UInt160, error) { } func (this *NeoCrossChainMsg) GetMessage() ([]byte, error) { + buff2 := io.NewBufBinaryWriter() + this.SerializeUnsigned(buff2.BinaryWriter) + if buff2.Err != nil { + return nil, fmt.Errorf("neo3-gogogo mpt.StateRoot SerializeUnsigned error: %s", buff2.Err) + } + hash := helper.UInt256FromBytes(crypto.Sha256(buff2.Bytes())) + buf := io.NewBufBinaryWriter() - this.SerializeUnsigned(buf.BinaryWriter) + buf.BinaryWriter.WriteLE(uint32(5195066)) + buf.BinaryWriter.WriteLE(hash) if buf.Err != nil { - return nil, fmt.Errorf("neo3-gogogo mpt.StateRoot SerializeUnsigned error: %s", buf.Err) + return nil, fmt.Errorf("write hash error: %s", buf.Err) } return buf.Bytes(), nil } diff --git a/native/service/header_sync/neo3/utils.go b/native/service/header_sync/neo3/utils.go index 0b271d091..2cb2badd1 100644 --- a/native/service/header_sync/neo3/utils.go +++ b/native/service/header_sync/neo3/utils.go @@ -18,7 +18,6 @@ package neo3 import ( - "encoding/hex" "fmt" "github.com/joeqian10/neo3-gogogo/crypto" "github.com/joeqian10/neo3-gogogo/sc" @@ -92,8 +91,14 @@ func VerifyCrossChainMsgSig(native *native.NativeService, chainID uint64, crossC if len(crossChainMsg.Witnesses) == 0 { return fmt.Errorf("verifyCrossChainMsg, incorrect witness length") } - invScript, _ := hex.DecodeString(crossChainMsg.Witnesses[0].Invocation) - verScript, _ := hex.DecodeString(crossChainMsg.Witnesses[0].Verification) + invScript, err := crypto.Base64Decode(crossChainMsg.Witnesses[0].Invocation) + if err != nil { + return fmt.Errorf("crypto.Base64Decode, decode invocation script error: %v", err) + } + verScript, err := crypto.Base64Decode(crossChainMsg.Witnesses[0].Verification) + if err != nil { + return fmt.Errorf("crypto.Base64Decode, decode verification script error: %v", err) + } witness := &tx.Witness{ InvocationScript: invScript, VerificationScript: verScript, From 24b1d3d68214d8908eb935a82911e77b214bfafe Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Tue, 18 May 2021 17:17:55 +0800 Subject: [PATCH 14/23] get neo3 magic from side chain extra info --- native/service/cross_chain_manager/neo3/neo_handler.go | 7 +++---- native/service/header_sync/neo3/states.go | 4 ++-- native/service/header_sync/neo3/utils.go | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/native/service/cross_chain_manager/neo3/neo_handler.go b/native/service/cross_chain_manager/neo3/neo_handler.go index 95c751e7d..138d90be8 100644 --- a/native/service/cross_chain_manager/neo3/neo_handler.go +++ b/native/service/cross_chain_manager/neo3/neo_handler.go @@ -45,15 +45,14 @@ func (this *Neo3Handler) MakeDepositProposal(service *native.NativeService) (*sc if err := crossChainMsg.Deserialization(common.NewZeroCopySource(params.HeaderOrCrossChainMsg)); err != nil { return nil, fmt.Errorf("neo3 MakeDepositProposal, deserialize crossChainMsg error: %v", err) } - - if err := neo3.VerifyCrossChainMsgSig(service, params.SourceChainID, crossChainMsg); err != nil { - return nil, fmt.Errorf("neo3 MakeDepositProposal, VerifyCrossChainMsg error: %v", err) - } // Verify the validity of proof with the help of state root in verified neo cross chain msg sideChain, err := side_chain_manager.GetSideChain(service, params.SourceChainID) if err != nil { return nil, fmt.Errorf("neo3 MakeDepositProposal, side_chain_manager.GetSideChain error: %v", err) } + if err := neo3.VerifyCrossChainMsgSig(service, helper.BytesToUInt32(sideChain.ExtraInfo), crossChainMsg); err != nil { + return nil, fmt.Errorf("neo3 MakeDepositProposal, VerifyCrossChainMsg error: %v", err) + } // todo, review code, when register neo N3, convert ccmc id to []byte // convert neo3 contract address bytes to id, it is different from other chains diff --git a/native/service/header_sync/neo3/states.go b/native/service/header_sync/neo3/states.go index 280067ad9..d606f4a9e 100644 --- a/native/service/header_sync/neo3/states.go +++ b/native/service/header_sync/neo3/states.go @@ -129,7 +129,7 @@ func (this *NeoCrossChainMsg) GetScriptHash() (*helper.UInt160, error) { return scriptHash, nil } -func (this *NeoCrossChainMsg) GetMessage() ([]byte, error) { +func (this *NeoCrossChainMsg) GetMessage(magic uint32) ([]byte, error) { buff2 := io.NewBufBinaryWriter() this.SerializeUnsigned(buff2.BinaryWriter) if buff2.Err != nil { @@ -138,7 +138,7 @@ func (this *NeoCrossChainMsg) GetMessage() ([]byte, error) { hash := helper.UInt256FromBytes(crypto.Sha256(buff2.Bytes())) buf := io.NewBufBinaryWriter() - buf.BinaryWriter.WriteLE(uint32(5195066)) + buf.BinaryWriter.WriteLE(magic) buf.BinaryWriter.WriteLE(hash) if buf.Err != nil { return nil, fmt.Errorf("write hash error: %s", buf.Err) diff --git a/native/service/header_sync/neo3/utils.go b/native/service/header_sync/neo3/utils.go index 2cb2badd1..36300b5af 100644 --- a/native/service/header_sync/neo3/utils.go +++ b/native/service/header_sync/neo3/utils.go @@ -51,7 +51,7 @@ func verifyHeader(native *native.NativeService, chainID uint64, header *NeoBlock return nil } -func VerifyCrossChainMsgSig(native *native.NativeService, chainID uint64, crossChainMsg *NeoCrossChainMsg) error { +func VerifyCrossChainMsgSig(native *native.NativeService, magic uint32, crossChainMsg *NeoCrossChainMsg) error { // todo, review code, get neo3 state validator from native contract svListBytes, err := neo3_state_manager.GetCurrentStateValidator(native) if err != nil { @@ -84,7 +84,7 @@ func VerifyCrossChainMsgSig(native *native.NativeService, chainID uint64, crossC if !expected.Equals(got) { return fmt.Errorf("verifyCrossChainMsg, invalid script hash in NeoCrossChainMsg error, expected: %s, got: %s", expected.String(), got.String()) } - msg, err := crossChainMsg.GetMessage() + msg, err := crossChainMsg.GetMessage(magic) if err != nil { return fmt.Errorf("verifyCrossChainMsg, unable to get unsigned message of neo crossChainMsg") } From c36d24c26422f8ef89efc567aa0c90f6eea432c5 Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Wed, 19 May 2021 10:09:54 +0800 Subject: [PATCH 15/23] update dependency --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9e714a4fb..1d2add22d 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c github.com/itchyny/base58-go v0.1.0 github.com/joeqian10/neo-gogogo v1.1.0 - github.com/joeqian10/neo3-gogogo v0.3.2 + github.com/joeqian10/neo3-gogogo v0.3.3 github.com/ontio/ontology v1.11.0 github.com/ontio/ontology-crypto v1.0.9 github.com/ontio/ontology-eventbus v0.9.1 From 24ddfe91cbc78a8d99a6678d5672387ab54e93fe Mon Sep 17 00:00:00 2001 From: dogecoindev Date: Thu, 20 May 2021 10:45:56 +0700 Subject: [PATCH 16/23] remove merkletree.db --- go.sum | 1 + merkle/merkletree.db | Bin 8864 -> 0 bytes 2 files changed, 1 insertion(+) delete mode 100755 merkle/merkletree.db diff --git a/go.sum b/go.sum index 2b3b22779..a88334157 100644 --- a/go.sum +++ b/go.sum @@ -320,6 +320,7 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= diff --git a/merkle/merkletree.db b/merkle/merkletree.db deleted file mode 100755 index 9c87f62aa36ffec02d13420cf1de50f2c2cd4195..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8864 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 From 733e4e016b0e297ae7806de711e288f255c33763 Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Thu, 20 May 2021 17:59:13 +0800 Subject: [PATCH 17/23] remove unused code --- native/service/cross_chain_manager/entrance.go | 2 +- .../cross_chain_manager/neo3/neo_handler.go | 14 ++++++-------- .../governance/neo3_state_manager/utils.go | 16 +--------------- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/native/service/cross_chain_manager/entrance.go b/native/service/cross_chain_manager/entrance.go index 4c63b0df0..a01d9e9e0 100644 --- a/native/service/cross_chain_manager/entrance.go +++ b/native/service/cross_chain_manager/entrance.go @@ -30,7 +30,7 @@ import ( "github.com/polynetwork/poly/native/service/cross_chain_manager/heco" "github.com/polynetwork/poly/native/service/cross_chain_manager/msc" "github.com/polynetwork/poly/native/service/cross_chain_manager/neo" - "github.com/polynetwork/poly/native/service/cross_chain_manager/neo3" + "github.com/polynetwork/poly/native/service/cross_chain_manager/neo3" "github.com/polynetwork/poly/native/service/cross_chain_manager/okex" "github.com/polynetwork/poly/native/service/cross_chain_manager/ont" "github.com/polynetwork/poly/native/service/cross_chain_manager/quorum" diff --git a/native/service/cross_chain_manager/neo3/neo_handler.go b/native/service/cross_chain_manager/neo3/neo_handler.go index 138d90be8..1bd66d1e0 100644 --- a/native/service/cross_chain_manager/neo3/neo_handler.go +++ b/native/service/cross_chain_manager/neo3/neo_handler.go @@ -28,7 +28,6 @@ import ( ) type Neo3Handler struct { - ccmcId *int } func NewNeo3Handler() *Neo3Handler { @@ -54,15 +53,14 @@ func (this *Neo3Handler) MakeDepositProposal(service *native.NativeService) (*sc return nil, fmt.Errorf("neo3 MakeDepositProposal, VerifyCrossChainMsg error: %v", err) } - // todo, review code, when register neo N3, convert ccmc id to []byte + // when register neo N3, convert ccmc id to []byte // convert neo3 contract address bytes to id, it is different from other chains // need to store int in a []byte, contract id can be get from "getcontractstate" api // neo3 native contracts have negative ids, while custom contracts have positive ones - if this.ccmcId == nil { - this.SetCcmcId(sideChain.CCMCAddress) - } - value, err := verifyFromNeoTx(params.Proof, crossChainMsg, *this.ccmcId) + id := this.ConvertCcmcAddressToId(sideChain.CCMCAddress) + + value, err := verifyFromNeoTx(params.Proof, crossChainMsg, id) if err != nil { return nil, fmt.Errorf("neo3 MakeDepositProposal, VerifyFromNeoTx error: %v", err) } @@ -76,7 +74,7 @@ func (this *Neo3Handler) MakeDepositProposal(service *native.NativeService) (*sc return value, nil } -func (this *Neo3Handler) SetCcmcId(idBytes []byte) { +func (this *Neo3Handler) ConvertCcmcAddressToId(idBytes []byte) int { id := int(int32(helper.BytesToUInt32(idBytes))) - this.ccmcId = &id + return id } diff --git a/native/service/governance/neo3_state_manager/utils.go b/native/service/governance/neo3_state_manager/utils.go index f9ad50f19..b23040c03 100644 --- a/native/service/governance/neo3_state_manager/utils.go +++ b/native/service/governance/neo3_state_manager/utils.go @@ -9,20 +9,6 @@ import ( "github.com/polynetwork/poly/native/service/utils" ) -//// putStateValidator put state validator in the contract storage using the STATE_VALIDATOR key -//func putStateValidator(native *native.NativeService, stateValidator helper.UInt160) error { -// contract := utils.Neo3StateManagerContractAddress -// native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(STATE_VALIDATOR), stateValidator.ToByteArray()), cstates.GenRawStorageItem(stateValidator.ToByteArray())) -// return nil -//} - -//func getStateValidator(native *native.NativeService, stateValidator helper.UInt160) error { -// contract := utils.Neo3StateManagerContractAddress -// native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(STATE_VALIDATOR), stateValidator.ToByteArray()), cstates.GenRawStorageItem(stateValidator.ToByteArray())) -// return nil -//} - -// func SerializeStringArray(data []string) []byte { sink := common.NewZeroCopySink(nil) // serialize @@ -39,7 +25,7 @@ func DeserializeStringArray(data []byte) ([]string, error) { if eof { return nil, fmt.Errorf("source.NextVarUint error") } - result := make([]string, 0) + result := make([]string, 0, n) for i := 0; uint64(i) < n; i++ { ss, eof := source.NextString() if eof { From ebead48548004ad6ee7b7e7b1ec8b43097e57ab6 Mon Sep 17 00:00:00 2001 From: zhuoqian Date: Fri, 21 May 2021 14:58:25 +0800 Subject: [PATCH 18/23] discard map for filtering --- .../cross_chain_manager/neo3/neo_handler.go | 8 +-- .../neo3_state_manager_test.go | 2 +- .../governance/neo3_state_manager/param.go | 2 +- .../governance/neo3_state_manager/utils.go | 64 +++++++------------ native/service/header_sync/neo3/utils.go | 6 +- 5 files changed, 30 insertions(+), 52 deletions(-) diff --git a/native/service/cross_chain_manager/neo3/neo_handler.go b/native/service/cross_chain_manager/neo3/neo_handler.go index 1bd66d1e0..cb2e071aa 100644 --- a/native/service/cross_chain_manager/neo3/neo_handler.go +++ b/native/service/cross_chain_manager/neo3/neo_handler.go @@ -57,8 +57,7 @@ func (this *Neo3Handler) MakeDepositProposal(service *native.NativeService) (*sc // convert neo3 contract address bytes to id, it is different from other chains // need to store int in a []byte, contract id can be get from "getcontractstate" api // neo3 native contracts have negative ids, while custom contracts have positive ones - - id := this.ConvertCcmcAddressToId(sideChain.CCMCAddress) + id := int(int32(helper.BytesToUInt32(sideChain.CCMCAddress))) value, err := verifyFromNeoTx(params.Proof, crossChainMsg, id) if err != nil { @@ -73,8 +72,3 @@ func (this *Neo3Handler) MakeDepositProposal(service *native.NativeService) (*sc } return value, nil } - -func (this *Neo3Handler) ConvertCcmcAddressToId(idBytes []byte) int { - id := int(int32(helper.BytesToUInt32(idBytes))) - return id -} diff --git a/native/service/governance/neo3_state_manager/neo3_state_manager_test.go b/native/service/governance/neo3_state_manager/neo3_state_manager_test.go index 7a928184f..61fea70fb 100644 --- a/native/service/governance/neo3_state_manager/neo3_state_manager_test.go +++ b/native/service/governance/neo3_state_manager/neo3_state_manager_test.go @@ -23,7 +23,7 @@ import ( var ( acct = account.NewAccount("") conAccts = func() []*account.Account { - accts := make([]*account.Account, 0) + accts := make([]*account.Account, 0, 7) for i := 0; i < 7; i++ { accts = append(accts, account.NewAccount(strconv.FormatUint(uint64(i), 10))) } diff --git a/native/service/governance/neo3_state_manager/param.go b/native/service/governance/neo3_state_manager/param.go index 197778334..177606e73 100644 --- a/native/service/governance/neo3_state_manager/param.go +++ b/native/service/governance/neo3_state_manager/param.go @@ -23,7 +23,7 @@ func (this *StateValidatorListParam) Deserialization(source *common.ZeroCopySour if eof { return fmt.Errorf("source.NextVarUint, deserialize StateValidators length error") } - stateValidators := make([]string, 0) + stateValidators := make([]string, 0, n) for i := 0; uint64(i) < n; i++ { ss, eof := source.NextString() if eof { diff --git a/native/service/governance/neo3_state_manager/utils.go b/native/service/governance/neo3_state_manager/utils.go index b23040c03..c1e130435 100644 --- a/native/service/governance/neo3_state_manager/utils.go +++ b/native/service/governance/neo3_state_manager/utils.go @@ -63,25 +63,21 @@ func putStateValidators(native *native.NativeService, stateValidators []string) if err != nil { return fmt.Errorf("putStateValidator, get old state validators error: %v", err) } - // use a map to filter old svs - mm := make(map[string]string) - for _, v := range oldSVs { - if _, ok := mm[v]; ok { - continue + // max capacity = len(oldSVs)+len(stateValidators) + newSVs := make([]string, 0, len(oldSVs)+len(stateValidators)) + newSVs = append(newSVs, oldSVs...) + // filter duplicate svs + for _, sv := range stateValidators { + isInOld := false + for _, oldSv := range oldSVs{ + if sv == oldSv { + isInOld = true + break + } } - mm[v] = v - } - // use the map to add new svs - for _, v := range stateValidators { - if _, ok := mm[v]; ok { - continue + if !isInOld { + newSVs = append(newSVs, sv) } - mm[v] = v - } - // convert map back to string array - newSVs := make([]string, 0) - for _, v := range mm { - newSVs = append(newSVs, v) } // convert back to []byte data := SerializeStringArray(newSVs) @@ -96,34 +92,22 @@ func removeStateValidators(native *native.NativeService, stateValidators []strin if err != nil { return fmt.Errorf("removeStateValidator, get old state validators error: %v", err) } - // use a map to filter old svs - mm := make(map[string]string) - for _, v := range oldSVs { - if _, ok := mm[v]; ok { - continue - } - mm[v] = v - } - // use the map to delete svs - for _, v := range stateValidators { - // if the sv is in map, delete it, else continue - if _, ok := mm[v]; ok { - delete(mm, v) + // remove in the slice + for _, sv := range stateValidators { + for i, oldSv := range oldSVs{ + if sv == oldSv { + oldSVs = append(oldSVs[:i], oldSVs[i+1:]...) + break + } } } - // convert map back to UInt160 array - newSVs := make([]string, 0) - for _, v := range mm { - newSVs = append(newSVs, v) - } // if no sv left, delete the storage, else put remaining back - if len(newSVs) == 0 { + if len(oldSVs) == 0 { native.GetCacheDB().Delete(utils.ConcatKey(contract, []byte(STATE_VALIDATOR))) return nil } - // convert back to []byte - data := SerializeStringArray(newSVs) + data := SerializeStringArray(oldSVs) native.GetCacheDB().Put(utils.ConcatKey(contract, []byte(STATE_VALIDATOR)), cstates.GenRawStorageItem(data)) return nil } @@ -135,7 +119,7 @@ func getStateValidatorApply(native *native.NativeService, applyID uint64) (*Stat return nil, fmt.Errorf("getStateValidatorApply, get stateValidatorListParamStore error: %v", err) } if svListParamStore == nil { - return nil, fmt.Errorf("getStateValidatorApply, can't find any record") + return nil, nil } svListParam := new(StateValidatorListParam) svListParamBytes, err := cstates.GetValueFromRawStorageItem(svListParamStore) @@ -202,7 +186,7 @@ func getStateValidatorRemove(native *native.NativeService, removeID uint64) (*St return nil, fmt.Errorf("getStateValidatorRemove, get stateValidatorListParamStore error: %v", err) } if svListParamStore == nil { - return nil, fmt.Errorf("getStateValidatorRemove, can't find any record") + return nil, nil } svListParam := new(StateValidatorListParam) svListParamBytes, err := cstates.GetValueFromRawStorageItem(svListParamStore) diff --git a/native/service/header_sync/neo3/utils.go b/native/service/header_sync/neo3/utils.go index 36300b5af..c9c3231b7 100644 --- a/native/service/header_sync/neo3/utils.go +++ b/native/service/header_sync/neo3/utils.go @@ -52,7 +52,7 @@ func verifyHeader(native *native.NativeService, chainID uint64, header *NeoBlock } func VerifyCrossChainMsgSig(native *native.NativeService, magic uint32, crossChainMsg *NeoCrossChainMsg) error { - // todo, review code, get neo3 state validator from native contract + // get neo3 state validator from native contract svListBytes, err := neo3_state_manager.GetCurrentStateValidator(native) if err != nil { return fmt.Errorf("verifyCrossChainMsg, neo3_state_manager.GetCurrentStateValidator error: %v", err) @@ -61,7 +61,7 @@ func VerifyCrossChainMsgSig(native *native.NativeService, magic uint32, crossCha if err != nil { return fmt.Errorf("verifyCrossChainMsg, neo3_state_manager.DeserializeStringArray error: %v", err) } - pubKeys := make([]crypto.ECPoint, len(svStrings)) + pubKeys := make([]crypto.ECPoint, len(svStrings), len(svStrings)) for i, v := range svStrings { pubKey, err := crypto.NewECPointFromString(v) if err != nil { @@ -71,7 +71,7 @@ func VerifyCrossChainMsgSig(native *native.NativeService, magic uint32, crossCha } n := len(pubKeys) m := n - (n-1)/3 - msc, err := sc.CreateMultiSigContract(m, pubKeys) + msc, err := sc.CreateMultiSigContract(m, pubKeys) // sort public keys inside if err != nil { return fmt.Errorf("verifyCrossChainMsg, sc.CreateMultiSigContract error: %v", err) } From efaaf7f68ad1548015f1478752086336a6c667d4 Mon Sep 17 00:00:00 2001 From: dogecoindev Date: Fri, 21 May 2021 14:49:33 +0700 Subject: [PATCH 19/23] Revert "remove merkletree.db" This reverts commit 24ddfe91cbc78a8d99a6678d5672387ab54e93fe. --- go.sum | 1 - merkle/merkletree.db | Bin 0 -> 8864 bytes 2 files changed, 1 deletion(-) create mode 100755 merkle/merkletree.db diff --git a/go.sum b/go.sum index a88334157..2b3b22779 100644 --- a/go.sum +++ b/go.sum @@ -320,7 +320,6 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= diff --git a/merkle/merkletree.db b/merkle/merkletree.db new file mode 100755 index 0000000000000000000000000000000000000000..9c87f62aa36ffec02d13420cf1de50f2c2cd4195 GIT binary patch literal 8864 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 literal 0 HcmV?d00001 From b1937a314c720d3c3e1592ab8bd3a9cbb74ed80d Mon Sep 17 00:00:00 2001 From: dogecoindev Date: Fri, 21 May 2021 17:05:46 +0700 Subject: [PATCH 20/23] fix register kai handler --- native/service/header_sync/entrance.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/native/service/header_sync/entrance.go b/native/service/header_sync/entrance.go index 7c627d8d7..7e23e65e5 100644 --- a/native/service/header_sync/entrance.go +++ b/native/service/header_sync/entrance.go @@ -22,6 +22,7 @@ import ( "github.com/polynetwork/poly/native/service/header_sync/neo" "github.com/polynetwork/poly/native/service/header_sync/neo3" + "github.com/polynetwork/poly/native/service/cross_chain_manager/kai" "github.com/polynetwork/poly/native/service/header_sync/heco" "github.com/polynetwork/poly/native/service/header_sync/msc" "github.com/polynetwork/poly/native/service/header_sync/okex" @@ -79,6 +80,8 @@ func GetChainHandler(router uint64) (hscommon.HeaderSyncHandler, error) { return msc.NewHandler(), nil case utils.OKEX_ROUTER: return okex.NewHandler(), nil + case utils.KAI_ROUTER: + return kai.NewHandler(), nil default: return nil, fmt.Errorf("not a supported router:%d", router) } From 39aec30bae672680394b9596d055c3b7537327c7 Mon Sep 17 00:00:00 2001 From: dogecoindev Date: Tue, 25 May 2021 14:01:40 +0700 Subject: [PATCH 21/23] add unitest kai header sync --- .gitignore | 1 + go.mod | 9 +- go.sum | 20 + native/service/header_sync/entrance.go | 2 +- native/service/header_sync/kai/header_sync.go | 42 ++ .../header_sync/kai/header_sync_test.go | 230 +++++++++ .../header_sync/kai/kaiclient/client.go | 483 ++++++++++++++++++ 7 files changed, 781 insertions(+), 6 deletions(-) create mode 100644 native/service/header_sync/kai/kaiclient/client.go diff --git a/.gitignore b/.gitignore index 327b7042f..ea29cef88 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ docker/payload config.json peers.recent .vscode +poly \ No newline at end of file diff --git a/go.mod b/go.mod index 2200cbb47..e53b706c3 100644 --- a/go.mod +++ b/go.mod @@ -15,18 +15,17 @@ require ( github.com/hashicorp/golang-lru v0.5.4 github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c github.com/itchyny/base58-go v0.1.0 - github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43 - github.com/kardiachain/go-kardia v1.1.1-0.20210518073513-843096e91762 // indirect - github.com/ontio/ontology v1.11.1-0.20200812075204-26cf1fa5dd47 github.com/joeqian10/neo-gogogo v1.1.0 github.com/joeqian10/neo3-gogogo v0.3.3 - github.com/ontio/ontology v1.11.0 + github.com/kardiachain/go-kardia v1.1.1-0.20210524050836-7b1961837a7a // indirect + github.com/ontio/ontology v1.11.1-0.20200812075204-26cf1fa5dd47 github.com/ontio/ontology-crypto v1.0.9 github.com/ontio/ontology-eventbus v0.9.1 github.com/pborman/uuid v1.2.0 github.com/polynetwork/poly-io-test v0.0.0-20200819093740-8cf514b07750 + github.com/prometheus/tsdb v0.10.0 // indirect github.com/stretchr/testify v1.7.0 - github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d + github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca github.com/tendermint/tendermint v0.33.7 github.com/urfave/cli v1.22.4 github.com/valyala/bytebufferpool v1.0.0 diff --git a/go.sum b/go.sum index 2b3b22779..f0ec9ada9 100644 --- a/go.sum +++ b/go.sum @@ -194,6 +194,7 @@ github.com/dvyukov/go-fuzz v0.0.0-20200318091601-be3528f3a813/go.mod h1:11Gm+ccJ github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/ebuchman/fail-test v0.0.0-20170303061230-95f809107225 h1:7TXT8REobzZUI9GzsRtAD29efTY/HgKRU2xYnV1zlaM= github.com/ebuchman/fail-test v0.0.0-20170303061230-95f809107225/go.mod h1:OFTBW14UVJS8P0shpX7OdPY0qpkTdA7AWGYFacMC2D8= github.com/edsrzf/mmap-go v0.0.0-20160512033002-935e0e8a636c/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= @@ -320,6 +321,7 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= @@ -419,6 +421,10 @@ github.com/joeqian10/neo-gogogo v0.0.0-20200611102831-c17de5e1f0f8 h1:C+PIS6p7oQ github.com/joeqian10/neo-gogogo v0.0.0-20200611102831-c17de5e1f0f8/go.mod h1:1fVDp4U1ROZQBRIooecbGNHHJpfs3bG9528sqlZ096g= github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43 h1:KkErIktuwCqqZYWV8iBbD7NEsgIbyGw6xxtuylqdyu0= github.com/joeqian10/neo-gogogo v0.0.0-20200716075409-923bd4879b43/go.mod h1:1fVDp4U1ROZQBRIooecbGNHHJpfs3bG9528sqlZ096g= +github.com/joeqian10/neo-gogogo v1.1.0 h1:TjqBwFQnNCtw6LK3QMog3yHa9sTZaZmqP+zqGOZ3SZ0= +github.com/joeqian10/neo-gogogo v1.1.0/go.mod h1:1fVDp4U1ROZQBRIooecbGNHHJpfs3bG9528sqlZ096g= +github.com/joeqian10/neo3-gogogo v0.3.3 h1:QKf18gGLql19bbBrPLzl+DKyoYuYIhGHNUXNBvEMfc8= +github.com/joeqian10/neo3-gogogo v0.3.3/go.mod h1:yvYQyEha3An0uYFhzR9asMU/O9HyeYy6RApRnLGPEtM= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= @@ -438,6 +444,8 @@ github.com/kardiachain/go-kardia v1.1.1-0.20210514114009-042c640f55d4 h1:vYkCSEC github.com/kardiachain/go-kardia v1.1.1-0.20210514114009-042c640f55d4/go.mod h1:XV2KPJf+Ib3es9iAFH5Io5fISzHpu7pk06um9bgAVKU= github.com/kardiachain/go-kardia v1.1.1-0.20210518073513-843096e91762 h1:Jkua+KxKgB3unn8wcCfkylIn8PVcrzVGThxHcrijkbA= github.com/kardiachain/go-kardia v1.1.1-0.20210518073513-843096e91762/go.mod h1:dIcZ5VO21q0HAjL9LiHqJ8bKMDkoE3T/4H0vy8urggs= +github.com/kardiachain/go-kardia v1.1.1-0.20210524050836-7b1961837a7a h1:KlxsfWdrLUeQ7WbwOpLKkjoqsgYkhcqhSUeQNTyJKNo= +github.com/kardiachain/go-kardia v1.1.1-0.20210524050836-7b1961837a7a/go.mod h1:dIcZ5VO21q0HAjL9LiHqJ8bKMDkoE3T/4H0vy8urggs= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= @@ -486,6 +494,7 @@ github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3N github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 h1:hLDRPB66XQT/8+wG9WsDpiCvZf1yKO7sz7scAjSlBa0= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= github.com/minio/highwayhash v1.0.0/go.mod h1:xQboMTeM9nY9v/LlAOxFctujiv5+Aq2hR5dxBpaMbdc= +github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0= github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -567,6 +576,7 @@ github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= @@ -637,12 +647,14 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= +github.com/sasha-s/go-deadlock v0.2.0 h1:lMqc+fUb7RrFS3gQLtoQsJ7/6TV/pAIFvBsqX73DK8Y= github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/scylladb/go-set v1.0.2/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs= @@ -809,6 +821,8 @@ golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 h1:phUcVbl53swtrUN8kQEXFhUxPlIlWyBfKmidCu7P95o= golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w= +golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= @@ -861,6 +875,8 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -913,8 +929,12 @@ golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= diff --git a/native/service/header_sync/entrance.go b/native/service/header_sync/entrance.go index 7e23e65e5..25fae091c 100644 --- a/native/service/header_sync/entrance.go +++ b/native/service/header_sync/entrance.go @@ -22,8 +22,8 @@ import ( "github.com/polynetwork/poly/native/service/header_sync/neo" "github.com/polynetwork/poly/native/service/header_sync/neo3" - "github.com/polynetwork/poly/native/service/cross_chain_manager/kai" "github.com/polynetwork/poly/native/service/header_sync/heco" + "github.com/polynetwork/poly/native/service/header_sync/kai" "github.com/polynetwork/poly/native/service/header_sync/msc" "github.com/polynetwork/poly/native/service/header_sync/okex" diff --git a/native/service/header_sync/kai/header_sync.go b/native/service/header_sync/kai/header_sync.go index 7789eb929..4ea6de0a6 100644 --- a/native/service/header_sync/kai/header_sync.go +++ b/native/service/header_sync/kai/header_sync.go @@ -19,17 +19,59 @@ package kai import ( "encoding/json" "fmt" + "strconv" "github.com/polynetwork/poly/common" "github.com/polynetwork/poly/common/log" "github.com/polynetwork/poly/native" + "github.com/polynetwork/poly/native/service/governance/node_manager" hscommon "github.com/polynetwork/poly/native/service/header_sync/common" + "github.com/polynetwork/poly/native/service/utils" ) // Handler ... type Handler struct { } +func NewHandler() *Handler { + return &Handler{} +} + +func (h *Handler) SyncGenesisHeader(native *native.NativeService) error { + param := new(hscommon.SyncGenesisHeaderParam) + if err := param.Deserialization(common.NewZeroCopySource(native.GetInput())); err != nil { + return fmt.Errorf("Handler SyncGenesisHeader, contract params deserialize error: %v", err) + } + // Get current epoch operator + operatorAddress, err := node_manager.GetCurConOperator(native) + if err != nil { + return fmt.Errorf("Handler SyncGenesisHeader, get current consensus operator address error: %v", err) + } + //check witness + err = utils.ValidateOwner(native, operatorAddress) + if err != nil { + return fmt.Errorf("Handler SyncGenesisHeader, checkWitness error: %v", err) + } + // get genesis header from input parameters + var header Header + if err := json.Unmarshal(param.GenesisHeader, &header); err != nil { + return fmt.Errorf("Handler SyncGenesisHeader, Unmarshal error: %v", err) + } + + // check if has genesis header + info, err := GetEpochSwitchInfo(native, param.ChainID) + if err == nil && info != nil { + return fmt.Errorf("Handler SyncGenesisHeader, genesis header had been initialized") + } + PutEpochSwitchInfo(native, param.ChainID, &EpochSwitchInfo{ + Height: int64(header.Header.Height), + NextValidatorsHash: header.Header.NextValidatorsHash.Bytes(), + ChainID: strconv.Itoa(int(param.ChainID)), + BlockHash: header.Header.Hash().Bytes(), + }) + return nil +} + // SyncBlockHeader ... func (h *Handler) SyncBlockHeader(native *native.NativeService) error { params := new(hscommon.SyncBlockHeaderParam) diff --git a/native/service/header_sync/kai/header_sync_test.go b/native/service/header_sync/kai/header_sync_test.go index 0fc6c7afe..1f8181b2c 100644 --- a/native/service/header_sync/kai/header_sync_test.go +++ b/native/service/header_sync/kai/header_sync_test.go @@ -1 +1,231 @@ +/* + * Copyright (C) 2020 The poly network Authors + * This file is part of The poly network library. + * + * The poly network is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The poly network is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The poly network . If not, see . + */ package kai + +import ( + "context" + "encoding/json" + "math/big" + "strings" + "testing" + + "github.com/kardiachain/go-kardia/lib/bytes" + "github.com/ontio/ontology-crypto/keypair" + "github.com/polynetwork/poly/account" + "github.com/polynetwork/poly/common" + vconfig "github.com/polynetwork/poly/consensus/vbft/config" + "github.com/polynetwork/poly/core/genesis" + "github.com/polynetwork/poly/core/states" + "github.com/polynetwork/poly/core/store/leveldbstore" + "github.com/polynetwork/poly/core/store/overlaydb" + "github.com/polynetwork/poly/core/types" + "github.com/polynetwork/poly/native" + "github.com/polynetwork/poly/native/service/governance/node_manager" + scom "github.com/polynetwork/poly/native/service/header_sync/common" + "github.com/polynetwork/poly/native/service/header_sync/kai/kaiclient" + "github.com/polynetwork/poly/native/service/utils" + "github.com/polynetwork/poly/native/storage" + "gotest.tools/assert" +) + +var ( + acct *account.Account = account.NewAccount("") + setBKers = func() { + genesis.GenesisBookkeepers = []keypair.PublicKey{acct.PublicKey} + } + tool *kaiclient.Client +) + +func init() { + setBKers() + tool = newKaiClient() +} + +func newKaiClient() *kaiclient.Client { + kaiclient, err := kaiclient.Dial("https://dev-6.kardiachain.io") + if err != nil { + panic(err) + } + return kaiclient +} + +func NewNative(args []byte, tx *types.Transaction, db *storage.CacheDB) (*native.NativeService, error) { + if db == nil { + store, _ := leveldbstore.NewMemLevelDBStore() + db = storage.NewCacheDB(overlaydb.NewOverlayDB(store)) + sink := common.NewZeroCopySink(nil) + view := &node_manager.GovernanceView{ + TxHash: common.UINT256_EMPTY, + Height: 0, + View: 0, + } + view.Serialization(sink) + db.Put(utils.ConcatKey(utils.NodeManagerContractAddress, []byte(node_manager.GOVERNANCE_VIEW)), states.GenRawStorageItem(sink.Bytes())) + + peerPoolMap := &node_manager.PeerPoolMap{ + PeerPoolMap: map[string]*node_manager.PeerPoolItem{ + vconfig.PubkeyID(acct.PublicKey): { + Address: acct.Address, + Status: node_manager.ConsensusStatus, + PeerPubkey: vconfig.PubkeyID(acct.PublicKey), + Index: 0, + }, + }, + } + sink.Reset() + peerPoolMap.Serialization(sink) + db.Put(utils.ConcatKey(utils.NodeManagerContractAddress, + []byte(node_manager.PEER_POOL), utils.GetUint32Bytes(0)), states.GenRawStorageItem(sink.Bytes())) + + } + return native.NewNativeService(db, tx, 0, 0, common.Uint256{0}, 0, args, false) +} + +const ( + SUCCESS = iota + GENESIS_PARAM_ERROR + GENESIS_INITIALIZED + SYNCBLOCK_PARAM_ERROR + SYNCBLOCK_ORPHAN + DIFFICULTY_ERROR + NONCE_ERROR + OPERATOR_ERROR + UNKNOWN +) + +func typeOfError(e error) int { + if e == nil { + return SUCCESS + } + errDesc := e.Error() + if strings.Contains(errDesc, "genesis had been initialized") { + return GENESIS_INITIALIZED + } else if strings.Contains(errDesc, "deserialize GenesisHeader err") { + return GENESIS_PARAM_ERROR + // } else if strings.Contains(errDesc, "SyncBlockHeader, deserialize header err:") { + // return SYNCBLOCK_PARAM_ERROR + // } else if strings.Contains(errDesc, "SyncBlockHeader, get the parent block failed. Error:") { + // return SYNCBLOCK_ORPHAN + // } else if strings.Contains(errDesc, "SyncBlockHeader, invalid difficulty:") { + // return DIFFICULTY_ERROR + // } else if strings.Contains(errDesc, "SyncBlockHeader, verify header error:") { + // return NONCE_ERROR + } else if strings.Contains(errDesc, "SyncGenesisHeader, checkWitness error:") { + return OPERATOR_ERROR + } + return UNKNOWN +} + +const ChainID = 138 + +func getGenesisHeaderByHeight(t *testing.T, epochHeight uint64) *kaiclient.KaiHeader { + h, err := tool.FullHeaderByNumber(context.Background(), big.NewInt(int64(epochHeight))) + assert.NilError(t, err) + return h +} + +func getGenesisHeader(t *testing.T) *kaiclient.KaiHeader { + return getGenesisHeaderByHeight(t, 5) +} + +func TestSyncGenesisHeader(t *testing.T) { + + genesisHeader := getGenesisHeader(t) + genesisHeaderBytes, err := json.Marshal(genesisHeader) + assert.NilError(t, err) + + param := new(scom.SyncGenesisHeaderParam) + param.ChainID = ChainID + param.GenesisHeader = genesisHeaderBytes + sink := common.NewZeroCopySink(nil) + param.Serialization(sink) + + tx := &types.Transaction{ + SignedAddr: []common.Address{acct.Address}, + } + + native, err := NewNative(sink.Bytes(), tx, nil) + assert.NilError(t, err) + handler := NewHandler() + err = handler.SyncGenesisHeader(native) + assert.NilError(t, err) + + epochInfo, err := GetEpochSwitchInfo(native, 138) + assert.NilError(t, err) + assert.Equal(t, epochInfo.Height, int64(5)) + assert.Equal(t, epochInfo.NextValidatorsHash.String(), bytes.HexBytes(genesisHeader.Header.NextValidatorsHash.Bytes()).String()) + assert.Equal(t, epochInfo.ChainID, "138") + assert.Equal(t, epochInfo.BlockHash.String(), bytes.HexBytes(genesisHeader.Header.Hash().Bytes()).String()) +} + +func syncGenesisBlockHeader(t *testing.T) *native.NativeService { + genesisHeader := getGenesisHeader(t) + genesisHeaderBytes, err := json.Marshal(genesisHeader) + assert.NilError(t, err) + + param := new(scom.SyncGenesisHeaderParam) + param.ChainID = ChainID + param.GenesisHeader = genesisHeaderBytes + sink := common.NewZeroCopySink(nil) + param.Serialization(sink) + + tx := &types.Transaction{ + SignedAddr: []common.Address{acct.Address}, + } + + native, err := NewNative(sink.Bytes(), tx, nil) + assert.NilError(t, err) + handler := NewHandler() + err = handler.SyncGenesisHeader(native) + assert.NilError(t, err) + return native +} + +func TestSyncBlockHeader(t *testing.T) { + native := syncGenesisBlockHeader(t) + + param := new(scom.SyncBlockHeaderParam) + param.ChainID = ChainID + param.Address = acct.Address + + h1 := getGenesisHeaderByHeight(t, 6) + hb1, err := json.Marshal(h1) + assert.NilError(t, err) + + h2 := getGenesisHeaderByHeight(t, 7) + hb2, err := json.Marshal(h2) + assert.NilError(t, err) + + param.Headers = append(param.Headers, hb1) + param.Headers = append(param.Headers, hb2) + + sink := common.NewZeroCopySink(nil) + param.Serialization(sink) + + tx := &types.Transaction{ + SignedAddr: []common.Address{acct.Address}, + } + + native, err = NewNative(sink.Bytes(), tx, native.GetCacheDB()) + assert.NilError(t, err) + handler := NewHandler() + _ = handler.SyncBlockHeader(native) +} + +func TestVerifyHeader(t *testing.T) { + +} diff --git a/native/service/header_sync/kai/kaiclient/client.go b/native/service/header_sync/kai/kaiclient/client.go new file mode 100644 index 000000000..d8dc6e28f --- /dev/null +++ b/native/service/header_sync/kai/kaiclient/client.go @@ -0,0 +1,483 @@ +package kaiclient + +// Copyright 2016 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +// Package ethclient provides a client for the Ethereum RPC API. + +import ( + "context" + "encoding/json" + "fmt" + "math/big" + + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/rpc" + + kai "github.com/kardiachain/go-kardia/mainchain" + ktypes "github.com/kardiachain/go-kardia/types" +) + +// Client defines typed wrappers for the Ethereum RPC API. +type Client struct { + c *rpc.Client +} + +// Dial connects a client to the given URL. +func Dial(rawurl string) (*Client, error) { + return DialContext(context.Background(), rawurl) +} + +func DialContext(ctx context.Context, rawurl string) (*Client, error) { + c, err := rpc.DialContext(ctx, rawurl) + if err != nil { + return nil, err + } + return NewClient(c), nil +} + +// NewClient creates a client that uses the given RPC client. +func NewClient(c *rpc.Client) *Client { + return &Client{c} +} + +func (ec *Client) Close() { + ec.c.Close() +} + +// Blockchain Access + +// ChainId retrieves the current chain ID for transaction replay protection. +func (ec *Client) ChainID(ctx context.Context) (*big.Int, error) { + var result hexutil.Big + err := ec.c.CallContext(ctx, &result, "kai_chainId") + if err != nil { + return nil, err + } + return (*big.Int)(&result), err +} + +// BlockByHash returns the given full block. +// +// Note that loading full blocks requires two requests. Use HeaderByHash +// if you don't need all transactions or uncle headers. +func (ec *Client) BlockByHash(ctx context.Context, hash common.Hash) (*ktypes.Block, error) { + return ec.getBlock(ctx, "kai_getBlockByHash", hash, true) +} + +// BlockByNumber returns a block from the current canonical chain. If number is nil, the +// latest known block is returned. +// +// Note that loading full blocks requires two requests. Use HeaderByNumber +// if you don't need all transactions or uncle headers. +func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*ktypes.Block, error) { + return ec.getBlock(ctx, "kai_getBlockByNumber", toBlockNumArg(number), true) +} + +type rpcBlock struct { + Hash common.Hash `json:"hash"` + Transactions []rpcTransaction `json:"transactions"` + UncleHashes []common.Hash `json:"uncles"` +} + +func (ec *Client) getBlock(ctx context.Context, method string, args ...interface{}) (*ktypes.Block, error) { + var raw ktypes.Block + err := ec.c.CallContext(ctx, &raw, method, args...) + if err != nil { + return nil, err + } + return &raw, nil +} + +// HeaderByHash returns the block header with the given hash. +func (ec *Client) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { + var head *types.Header + err := ec.c.CallContext(ctx, &head, "kai_getBlockByHash", hash, false) + if err == nil && head == nil { + err = ethereum.NotFound + } + return head, err +} + +// HeaderByNumber returns a block header from the current canonical chain. If number is +// nil, the latest known header is returned. +func (ec *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*ktypes.Header, error) { + var head *ktypes.Header + err := ec.c.CallContext(ctx, &head, "kai_getBlockByNumber", toBlockNumArg(number)) + if err == nil && head == nil { + err = ethereum.NotFound + } + return head, err +} + +type KaiHeader struct { + Header *ktypes.Header + Commit *ktypes.Commit + ValidatorSet *ktypes.ValidatorSet +} + +func (ec *Client) FullHeaderByNumber(ctx context.Context, number *big.Int) (*KaiHeader, error) { + header, err := ec.HeaderByNumber(ctx, number) + if err != nil { + return nil, err + } + validators, err := ec.GetValidators(ctx, number) + if err != nil { + return nil, err + } + + commit, err := ec.GetCommit(ctx, number.Sub(number, big.NewInt(1))) + if err != nil { + return nil, err + } + return &KaiHeader{ + Header: header, + ValidatorSet: validators, + Commit: commit, + }, nil +} + +func (ec *Client) GetValidators(ctx context.Context, number *big.Int) (*ktypes.ValidatorSet, error) { + var valSet *ktypes.ValidatorSet + err := ec.c.CallContext(ctx, &valSet, "kai_getValidatorSet", toBlockNumArg(number)) + if err == nil && valSet == nil { + err = ethereum.NotFound + } + return valSet, err +} + +func (ec *Client) GetCommit(ctx context.Context, number *big.Int) (*ktypes.Commit, error) { + var commit *ktypes.Commit + err := ec.c.CallContext(ctx, &commit, "kai_getCommit", toBlockNumArg(number)) + if err == nil && commit == nil { + err = ethereum.NotFound + } + return commit, err +} + +func (ec *Client) GetProof(ctx context.Context, address common.Address, storageKeys []string, number *big.Int) (*kai.AccountResult, error) { + var accountR *kai.AccountResult + err := ec.c.CallContext(ctx, &accountR, "kai_getProof", address, storageKeys, toBlockNumArg(number), false) + if err == nil && accountR == nil { + err = ethereum.NotFound + } + return accountR, err +} + +type rpcTransaction struct { + tx *types.Transaction + txExtraInfo +} + +type txExtraInfo struct { + BlockNumber *string `json:"blockNumber,omitempty"` + BlockHash *common.Hash `json:"blockHash,omitempty"` + From *common.Address `json:"from,omitempty"` +} + +func (tx *rpcTransaction) UnmarshalJSON(msg []byte) error { + if err := json.Unmarshal(msg, &tx.tx); err != nil { + return err + } + return json.Unmarshal(msg, &tx.txExtraInfo) +} + +// TransactionCount returns the total number of transactions in the given block. +func (ec *Client) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) { + var num hexutil.Uint + err := ec.c.CallContext(ctx, &num, "kai_getBlockTransactionCountByHash", blockHash) + return uint(num), err +} + +// TransactionReceipt returns the receipt of a transaction by transaction hash. +// Note that the receipt is not available for pending transactions. +func (ec *Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { + var r *types.Receipt + err := ec.c.CallContext(ctx, &r, "kai_getTransactionReceipt", txHash) + if err == nil { + if r == nil { + return nil, ethereum.NotFound + } + } + return r, err +} + +func toBlockNumArg(number *big.Int) string { + if number == nil { + return "latest" + } + pending := big.NewInt(-1) + if number.Cmp(pending) == 0 { + return "pending" + } + return number.String() +} + +type rpcProgress struct { + StartingBlock hexutil.Uint64 + CurrentBlock hexutil.Uint64 + HighestBlock hexutil.Uint64 + PulledStates hexutil.Uint64 + KnownStates hexutil.Uint64 +} + +// SyncProgress retrieves the current progress of the sync algorithm. If there's +// no sync currently running, it returns nil. +func (ec *Client) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) { + var raw json.RawMessage + if err := ec.c.CallContext(ctx, &raw, "kai_syncing"); err != nil { + return nil, err + } + // Handle the possible response types + var syncing bool + if err := json.Unmarshal(raw, &syncing); err == nil { + return nil, nil // Not syncing (always false) + } + var progress *rpcProgress + if err := json.Unmarshal(raw, &progress); err != nil { + return nil, err + } + return ðereum.SyncProgress{ + StartingBlock: uint64(progress.StartingBlock), + CurrentBlock: uint64(progress.CurrentBlock), + HighestBlock: uint64(progress.HighestBlock), + PulledStates: uint64(progress.PulledStates), + KnownStates: uint64(progress.KnownStates), + }, nil +} + +// SubscribeNewHead subscribes to notifications about the current blockchain head +// on the given channel. +func (ec *Client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) { + return ec.c.EthSubscribe(ctx, ch, "newHeads") +} + +// State Access + +// NetworkID returns the network ID (also known as the chain ID) for this chain. +func (ec *Client) NetworkID(ctx context.Context) (*big.Int, error) { + version := new(big.Int) + var ver string + if err := ec.c.CallContext(ctx, &ver, "net_version"); err != nil { + return nil, err + } + if _, ok := version.SetString(ver, 10); !ok { + return nil, fmt.Errorf("invalid net_version result %q", ver) + } + return version, nil +} + +// BalanceAt returns the wei balance of the given account. +// The block number can be nil, in which case the balance is taken from the latest known block. +func (ec *Client) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) { + var result hexutil.Big + err := ec.c.CallContext(ctx, &result, "kai_getBalance", account, toBlockNumArg(blockNumber)) + return (*big.Int)(&result), err +} + +// StorageAt returns the value of key in the contract storage of the given account. +// The block number can be nil, in which case the value is taken from the latest known block. +func (ec *Client) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) { + var result hexutil.Bytes + err := ec.c.CallContext(ctx, &result, "kai_getStorageAt", account, key, toBlockNumArg(blockNumber)) + return result, err +} + +// CodeAt returns the contract code of the given account. +// The block number can be nil, in which case the code is taken from the latest known block. +func (ec *Client) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) { + var result hexutil.Bytes + err := ec.c.CallContext(ctx, &result, "kai_getCode", account, toBlockNumArg(blockNumber)) + return result, err +} + +// NonceAt returns the account nonce of the given account. +// The block number can be nil, in which case the nonce is taken from the latest known block. +func (ec *Client) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) { + var result hexutil.Uint64 + err := ec.c.CallContext(ctx, &result, "kai_getTransactionCount", account, toBlockNumArg(blockNumber)) + return uint64(result), err +} + +// Filters + +// FilterLogs executes a filter query. +func (ec *Client) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) { + var result []types.Log + arg, err := toFilterArg(q) + if err != nil { + return nil, err + } + err = ec.c.CallContext(ctx, &result, "kai_getLogs", arg) + return result, err +} + +// SubscribeFilterLogs subscribes to the results of a streaming filter query. +func (ec *Client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) { + arg, err := toFilterArg(q) + if err != nil { + return nil, err + } + return ec.c.EthSubscribe(ctx, ch, "logs", arg) +} + +func toFilterArg(q ethereum.FilterQuery) (interface{}, error) { + arg := map[string]interface{}{ + "address": q.Addresses, + "topics": q.Topics, + } + if q.BlockHash != nil { + arg["blockHash"] = *q.BlockHash + if q.FromBlock != nil || q.ToBlock != nil { + return nil, fmt.Errorf("cannot specify both BlockHash and FromBlock/ToBlock") + } + } else { + if q.FromBlock == nil { + arg["fromBlock"] = "0x0" + } else { + arg["fromBlock"] = toBlockNumArg(q.FromBlock) + } + arg["toBlock"] = toBlockNumArg(q.ToBlock) + } + return arg, nil +} + +// Pending State + +// PendingBalanceAt returns the wei balance of the given account in the pending state. +func (ec *Client) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) { + var result hexutil.Big + err := ec.c.CallContext(ctx, &result, "kai_getBalance", account, "pending") + return (*big.Int)(&result), err +} + +// PendingStorageAt returns the value of key in the contract storage of the given account in the pending state. +func (ec *Client) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error) { + var result hexutil.Bytes + err := ec.c.CallContext(ctx, &result, "kai_getStorageAt", account, key, "pending") + return result, err +} + +// PendingCodeAt returns the contract code of the given account in the pending state. +func (ec *Client) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) { + var result hexutil.Bytes + err := ec.c.CallContext(ctx, &result, "kai_getCode", account, "pending") + return result, err +} + +// PendingNonceAt returns the account nonce of the given account in the pending state. +// This is the nonce that should be used for the next transaction. +func (ec *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { + var result hexutil.Uint64 + err := ec.c.CallContext(ctx, &result, "kai_getTransactionCount", account, "pending") + return uint64(result), err +} + +// PendingTransactionCount returns the total number of transactions in the pending state. +func (ec *Client) PendingTransactionCount(ctx context.Context) (uint, error) { + var num hexutil.Uint + err := ec.c.CallContext(ctx, &num, "kai_getBlockTransactionCountByNumber", "pending") + return uint(num), err +} + +// TODO: SubscribePendingTransactions (needs server side) + +// Contract Calling + +// CallContract executes a message call transaction, which is directly executed in the VM +// of the node, but never mined into the blockchain. +// +// blockNumber selects the block height at which the call runs. It can be nil, in which +// case the code is taken from the latest known block. Note that state from very old +// blocks might not be available. +func (ec *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { + var hex hexutil.Bytes + err := ec.c.CallContext(ctx, &hex, "kai_call", toCallArg(msg), toBlockNumArg(blockNumber)) + if err != nil { + return nil, err + } + return hex, nil +} + +// PendingCallContract executes a message call transaction using the EVM. +// The state seen by the contract call is the pending state. +func (ec *Client) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) { + var hex hexutil.Bytes + err := ec.c.CallContext(ctx, &hex, "kai_call", toCallArg(msg), "pending") + if err != nil { + return nil, err + } + return hex, nil +} + +// SuggestGasPrice retrieves the currently suggested gas price to allow a timely +// execution of a transaction. +func (ec *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error) { + var hex hexutil.Big + if err := ec.c.CallContext(ctx, &hex, "kai_gasPrice"); err != nil { + return nil, err + } + return (*big.Int)(&hex), nil +} + +// EstimateGas tries to estimate the gas needed to execute a specific transaction based on +// the current pending state of the backend blockchain. There is no guarantee that this is +// the true gas limit requirement as other transactions may be added or removed by miners, +// but it should provide a basis for setting a reasonable default. +func (ec *Client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) { + var hex hexutil.Uint64 + err := ec.c.CallContext(ctx, &hex, "kai_estimateGas", toCallArg(msg)) + if err != nil { + return 0, err + } + return uint64(hex), nil +} + +// SendTransaction injects a signed transaction into the pending pool for execution. +// +// If the transaction was a contract creation use the TransactionReceipt method to get the +// contract address after the transaction has been mined. +func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error { + data, err := rlp.EncodeToBytes(tx) + if err != nil { + return err + } + return ec.c.CallContext(ctx, nil, "kai_sendRawTransaction", hexutil.Encode(data)) +} + +func toCallArg(msg ethereum.CallMsg) interface{} { + arg := map[string]interface{}{ + "from": msg.From, + "to": msg.To, + } + if len(msg.Data) > 0 { + arg["data"] = hexutil.Bytes(msg.Data) + } + if msg.Value != nil { + arg["value"] = (*hexutil.Big)(msg.Value) + } + if msg.Gas != 0 { + arg["gas"] = hexutil.Uint64(msg.Gas) + } + if msg.GasPrice != nil { + arg["gasPrice"] = (*hexutil.Big)(msg.GasPrice) + } + return arg +} From 9446cd3e5cedb98f75763e9dcf84eb208d5b53f8 Mon Sep 17 00:00:00 2001 From: dogecoindev Date: Tue, 25 May 2021 16:29:09 +0700 Subject: [PATCH 22/23] update unitest --- go.mod | 3 +- .../cross_chain_manager/kai/handler.go | 2 +- .../cross_chain_manager/kai/handler_test.go | 45 ++ native/service/header_sync/kai/header_sync.go | 5 +- .../header_sync/kai/header_sync_test.go | 35 +- .../header_sync/kai/kaiclient/client.go | 483 ------------------ native/service/header_sync/kai/state.go | 7 - native/service/header_sync/kai/utils.go | 7 +- 8 files changed, 75 insertions(+), 512 deletions(-) delete mode 100644 native/service/header_sync/kai/kaiclient/client.go diff --git a/go.mod b/go.mod index e53b706c3..927d176f0 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,8 @@ require ( github.com/itchyny/base58-go v0.1.0 github.com/joeqian10/neo-gogogo v1.1.0 github.com/joeqian10/neo3-gogogo v0.3.3 - github.com/kardiachain/go-kardia v1.1.1-0.20210524050836-7b1961837a7a // indirect + github.com/kardiachain/go-kaiclient v1.0.2-0.20210525090440-5f0648f4d185 // indirect + github.com/kardiachain/go-kardia v1.2.3-0.20210525082104-2913103edf92 // indirect github.com/ontio/ontology v1.11.1-0.20200812075204-26cf1fa5dd47 github.com/ontio/ontology-crypto v1.0.9 github.com/ontio/ontology-eventbus v0.9.1 diff --git a/native/service/cross_chain_manager/kai/handler.go b/native/service/cross_chain_manager/kai/handler.go index dcc71a7d3..01d17f87a 100644 --- a/native/service/cross_chain_manager/kai/handler.go +++ b/native/service/cross_chain_manager/kai/handler.go @@ -90,7 +90,7 @@ func (h *Handler) MakeDepositProposal(service *native.NativeService) (*scom.Make Height: int64(myHeader.Header.Height), BlockHash: myHeader.Header.Hash().Bytes(), NextValidatorsHash: myHeader.Header.NextValidatorsHash.Bytes(), - ChainID: "", + ChainID: info.ChainID, }) } diff --git a/native/service/cross_chain_manager/kai/handler_test.go b/native/service/cross_chain_manager/kai/handler_test.go index 0fc6c7afe..adeebcad8 100644 --- a/native/service/cross_chain_manager/kai/handler_test.go +++ b/native/service/cross_chain_manager/kai/handler_test.go @@ -1 +1,46 @@ package kai + +import ( + "encoding/hex" + "fmt" + "testing" + + "github.com/polynetwork/poly/common" + cstates "github.com/polynetwork/poly/core/states" + "github.com/polynetwork/poly/core/store/leveldbstore" + "github.com/polynetwork/poly/core/store/overlaydb" + "github.com/polynetwork/poly/core/types" + "github.com/polynetwork/poly/native" + "github.com/polynetwork/poly/native/service/governance/side_chain_manager" + "github.com/polynetwork/poly/native/service/utils" + "github.com/polynetwork/poly/native/storage" +) + +func NewNative(args []byte, tx *types.Transaction, db *storage.CacheDB) *native.NativeService { + if db == nil { + store, _ := leveldbstore.NewMemLevelDBStore() + db = storage.NewCacheDB(overlaydb.NewOverlayDB(store)) + } + ns, err := native.NewNativeService(db, tx, 0, 0, common.Uint256{0}, 0, args, false) + if err != nil { + panic(fmt.Errorf("NewNativeService error: %+v", err)) + } + + contaractAddr, _ := hex.DecodeString("48A77F43C0D7A6D6f588c4758dbA22bf6C5D95a0") + side := &side_chain_manager.SideChain{ + Name: "kai", + ChainId: 138, + BlocksToWait: 1, + Router: 1, + CCMCAddress: contaractAddr, + } + sink := common.NewZeroCopySink(nil) + _ = side.Serialization(sink) + ns.GetCacheDB().Put(utils.ConcatKey(utils.SideChainManagerContractAddress, []byte(side_chain_manager.SIDE_CHAIN), utils.GetUint64Bytes(2)), cstates.GenRawStorageItem(sink.Bytes())) + return ns +} + +func TestMakeDepositProposal(t *testing.T) { + //handler := NewHandler() + +} diff --git a/native/service/header_sync/kai/header_sync.go b/native/service/header_sync/kai/header_sync.go index 4ea6de0a6..c7d00d404 100644 --- a/native/service/header_sync/kai/header_sync.go +++ b/native/service/header_sync/kai/header_sync.go @@ -21,6 +21,7 @@ import ( "fmt" "strconv" + kaiclient "github.com/kardiachain/go-kaiclient/kardia" "github.com/polynetwork/poly/common" "github.com/polynetwork/poly/common/log" "github.com/polynetwork/poly/native" @@ -53,7 +54,7 @@ func (h *Handler) SyncGenesisHeader(native *native.NativeService) error { return fmt.Errorf("Handler SyncGenesisHeader, checkWitness error: %v", err) } // get genesis header from input parameters - var header Header + var header kaiclient.FullHeader if err := json.Unmarshal(param.GenesisHeader, &header); err != nil { return fmt.Errorf("Handler SyncGenesisHeader, Unmarshal error: %v", err) } @@ -84,7 +85,7 @@ func (h *Handler) SyncBlockHeader(native *native.NativeService) error { return fmt.Errorf("SyncBlockHeader, get epoch switching height failed: %v", err) } for _, v := range params.Headers { - var myHeader Header + var myHeader kaiclient.FullHeader if err := json.Unmarshal(v, &myHeader); err != nil { return fmt.Errorf("SyncBlockHeader failed to unmarshal header: %v", err) } diff --git a/native/service/header_sync/kai/header_sync_test.go b/native/service/header_sync/kai/header_sync_test.go index 1f8181b2c..82894bd84 100644 --- a/native/service/header_sync/kai/header_sync_test.go +++ b/native/service/header_sync/kai/header_sync_test.go @@ -19,10 +19,10 @@ package kai import ( "context" "encoding/json" - "math/big" "strings" "testing" + kaiclient "github.com/kardiachain/go-kaiclient/kardia" "github.com/kardiachain/go-kardia/lib/bytes" "github.com/ontio/ontology-crypto/keypair" "github.com/polynetwork/poly/account" @@ -36,7 +36,6 @@ import ( "github.com/polynetwork/poly/native" "github.com/polynetwork/poly/native/service/governance/node_manager" scom "github.com/polynetwork/poly/native/service/header_sync/common" - "github.com/polynetwork/poly/native/service/header_sync/kai/kaiclient" "github.com/polynetwork/poly/native/service/utils" "github.com/polynetwork/poly/native/storage" "gotest.tools/assert" @@ -47,20 +46,21 @@ var ( setBKers = func() { genesis.GenesisBookkeepers = []keypair.PublicKey{acct.PublicKey} } - tool *kaiclient.Client + tool kaiclient.Node ) -func init() { - setBKers() - tool = newKaiClient() -} - -func newKaiClient() *kaiclient.Client { - kaiclient, err := kaiclient.Dial("https://dev-6.kardiachain.io") +func newKaiClient() kaiclient.Node { + url := "https://dev-6.kardiachain.io" + node, err := kaiclient.NewNode(url, nil) if err != nil { panic(err) } - return kaiclient + return node +} + +func init() { + setBKers() + tool = newKaiClient() } func NewNative(args []byte, tx *types.Transaction, db *storage.CacheDB) (*native.NativeService, error) { @@ -132,13 +132,13 @@ func typeOfError(e error) int { const ChainID = 138 -func getGenesisHeaderByHeight(t *testing.T, epochHeight uint64) *kaiclient.KaiHeader { - h, err := tool.FullHeaderByNumber(context.Background(), big.NewInt(int64(epochHeight))) +func getGenesisHeaderByHeight(t *testing.T, epochHeight uint64) *kaiclient.FullHeader { + h, err := tool.FullHeaderByNumber(context.Background(), epochHeight) assert.NilError(t, err) return h } -func getGenesisHeader(t *testing.T) *kaiclient.KaiHeader { +func getGenesisHeader(t *testing.T) *kaiclient.FullHeader { return getGenesisHeaderByHeight(t, 5) } @@ -227,5 +227,10 @@ func TestSyncBlockHeader(t *testing.T) { } func TestVerifyHeader(t *testing.T) { - + native := syncGenesisBlockHeader(t) + epochInfo, err := GetEpochSwitchInfo(native, 138) + assert.NilError(t, err) + h6 := getGenesisHeaderByHeight(t, 6) + err = VerifyHeader(h6, epochInfo) + assert.NilError(t, err) } diff --git a/native/service/header_sync/kai/kaiclient/client.go b/native/service/header_sync/kai/kaiclient/client.go deleted file mode 100644 index d8dc6e28f..000000000 --- a/native/service/header_sync/kai/kaiclient/client.go +++ /dev/null @@ -1,483 +0,0 @@ -package kaiclient - -// Copyright 2016 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -// Package ethclient provides a client for the Ethereum RPC API. - -import ( - "context" - "encoding/json" - "fmt" - "math/big" - - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/rlp" - "github.com/ethereum/go-ethereum/rpc" - - kai "github.com/kardiachain/go-kardia/mainchain" - ktypes "github.com/kardiachain/go-kardia/types" -) - -// Client defines typed wrappers for the Ethereum RPC API. -type Client struct { - c *rpc.Client -} - -// Dial connects a client to the given URL. -func Dial(rawurl string) (*Client, error) { - return DialContext(context.Background(), rawurl) -} - -func DialContext(ctx context.Context, rawurl string) (*Client, error) { - c, err := rpc.DialContext(ctx, rawurl) - if err != nil { - return nil, err - } - return NewClient(c), nil -} - -// NewClient creates a client that uses the given RPC client. -func NewClient(c *rpc.Client) *Client { - return &Client{c} -} - -func (ec *Client) Close() { - ec.c.Close() -} - -// Blockchain Access - -// ChainId retrieves the current chain ID for transaction replay protection. -func (ec *Client) ChainID(ctx context.Context) (*big.Int, error) { - var result hexutil.Big - err := ec.c.CallContext(ctx, &result, "kai_chainId") - if err != nil { - return nil, err - } - return (*big.Int)(&result), err -} - -// BlockByHash returns the given full block. -// -// Note that loading full blocks requires two requests. Use HeaderByHash -// if you don't need all transactions or uncle headers. -func (ec *Client) BlockByHash(ctx context.Context, hash common.Hash) (*ktypes.Block, error) { - return ec.getBlock(ctx, "kai_getBlockByHash", hash, true) -} - -// BlockByNumber returns a block from the current canonical chain. If number is nil, the -// latest known block is returned. -// -// Note that loading full blocks requires two requests. Use HeaderByNumber -// if you don't need all transactions or uncle headers. -func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*ktypes.Block, error) { - return ec.getBlock(ctx, "kai_getBlockByNumber", toBlockNumArg(number), true) -} - -type rpcBlock struct { - Hash common.Hash `json:"hash"` - Transactions []rpcTransaction `json:"transactions"` - UncleHashes []common.Hash `json:"uncles"` -} - -func (ec *Client) getBlock(ctx context.Context, method string, args ...interface{}) (*ktypes.Block, error) { - var raw ktypes.Block - err := ec.c.CallContext(ctx, &raw, method, args...) - if err != nil { - return nil, err - } - return &raw, nil -} - -// HeaderByHash returns the block header with the given hash. -func (ec *Client) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { - var head *types.Header - err := ec.c.CallContext(ctx, &head, "kai_getBlockByHash", hash, false) - if err == nil && head == nil { - err = ethereum.NotFound - } - return head, err -} - -// HeaderByNumber returns a block header from the current canonical chain. If number is -// nil, the latest known header is returned. -func (ec *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*ktypes.Header, error) { - var head *ktypes.Header - err := ec.c.CallContext(ctx, &head, "kai_getBlockByNumber", toBlockNumArg(number)) - if err == nil && head == nil { - err = ethereum.NotFound - } - return head, err -} - -type KaiHeader struct { - Header *ktypes.Header - Commit *ktypes.Commit - ValidatorSet *ktypes.ValidatorSet -} - -func (ec *Client) FullHeaderByNumber(ctx context.Context, number *big.Int) (*KaiHeader, error) { - header, err := ec.HeaderByNumber(ctx, number) - if err != nil { - return nil, err - } - validators, err := ec.GetValidators(ctx, number) - if err != nil { - return nil, err - } - - commit, err := ec.GetCommit(ctx, number.Sub(number, big.NewInt(1))) - if err != nil { - return nil, err - } - return &KaiHeader{ - Header: header, - ValidatorSet: validators, - Commit: commit, - }, nil -} - -func (ec *Client) GetValidators(ctx context.Context, number *big.Int) (*ktypes.ValidatorSet, error) { - var valSet *ktypes.ValidatorSet - err := ec.c.CallContext(ctx, &valSet, "kai_getValidatorSet", toBlockNumArg(number)) - if err == nil && valSet == nil { - err = ethereum.NotFound - } - return valSet, err -} - -func (ec *Client) GetCommit(ctx context.Context, number *big.Int) (*ktypes.Commit, error) { - var commit *ktypes.Commit - err := ec.c.CallContext(ctx, &commit, "kai_getCommit", toBlockNumArg(number)) - if err == nil && commit == nil { - err = ethereum.NotFound - } - return commit, err -} - -func (ec *Client) GetProof(ctx context.Context, address common.Address, storageKeys []string, number *big.Int) (*kai.AccountResult, error) { - var accountR *kai.AccountResult - err := ec.c.CallContext(ctx, &accountR, "kai_getProof", address, storageKeys, toBlockNumArg(number), false) - if err == nil && accountR == nil { - err = ethereum.NotFound - } - return accountR, err -} - -type rpcTransaction struct { - tx *types.Transaction - txExtraInfo -} - -type txExtraInfo struct { - BlockNumber *string `json:"blockNumber,omitempty"` - BlockHash *common.Hash `json:"blockHash,omitempty"` - From *common.Address `json:"from,omitempty"` -} - -func (tx *rpcTransaction) UnmarshalJSON(msg []byte) error { - if err := json.Unmarshal(msg, &tx.tx); err != nil { - return err - } - return json.Unmarshal(msg, &tx.txExtraInfo) -} - -// TransactionCount returns the total number of transactions in the given block. -func (ec *Client) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) { - var num hexutil.Uint - err := ec.c.CallContext(ctx, &num, "kai_getBlockTransactionCountByHash", blockHash) - return uint(num), err -} - -// TransactionReceipt returns the receipt of a transaction by transaction hash. -// Note that the receipt is not available for pending transactions. -func (ec *Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { - var r *types.Receipt - err := ec.c.CallContext(ctx, &r, "kai_getTransactionReceipt", txHash) - if err == nil { - if r == nil { - return nil, ethereum.NotFound - } - } - return r, err -} - -func toBlockNumArg(number *big.Int) string { - if number == nil { - return "latest" - } - pending := big.NewInt(-1) - if number.Cmp(pending) == 0 { - return "pending" - } - return number.String() -} - -type rpcProgress struct { - StartingBlock hexutil.Uint64 - CurrentBlock hexutil.Uint64 - HighestBlock hexutil.Uint64 - PulledStates hexutil.Uint64 - KnownStates hexutil.Uint64 -} - -// SyncProgress retrieves the current progress of the sync algorithm. If there's -// no sync currently running, it returns nil. -func (ec *Client) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) { - var raw json.RawMessage - if err := ec.c.CallContext(ctx, &raw, "kai_syncing"); err != nil { - return nil, err - } - // Handle the possible response types - var syncing bool - if err := json.Unmarshal(raw, &syncing); err == nil { - return nil, nil // Not syncing (always false) - } - var progress *rpcProgress - if err := json.Unmarshal(raw, &progress); err != nil { - return nil, err - } - return ðereum.SyncProgress{ - StartingBlock: uint64(progress.StartingBlock), - CurrentBlock: uint64(progress.CurrentBlock), - HighestBlock: uint64(progress.HighestBlock), - PulledStates: uint64(progress.PulledStates), - KnownStates: uint64(progress.KnownStates), - }, nil -} - -// SubscribeNewHead subscribes to notifications about the current blockchain head -// on the given channel. -func (ec *Client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) { - return ec.c.EthSubscribe(ctx, ch, "newHeads") -} - -// State Access - -// NetworkID returns the network ID (also known as the chain ID) for this chain. -func (ec *Client) NetworkID(ctx context.Context) (*big.Int, error) { - version := new(big.Int) - var ver string - if err := ec.c.CallContext(ctx, &ver, "net_version"); err != nil { - return nil, err - } - if _, ok := version.SetString(ver, 10); !ok { - return nil, fmt.Errorf("invalid net_version result %q", ver) - } - return version, nil -} - -// BalanceAt returns the wei balance of the given account. -// The block number can be nil, in which case the balance is taken from the latest known block. -func (ec *Client) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) { - var result hexutil.Big - err := ec.c.CallContext(ctx, &result, "kai_getBalance", account, toBlockNumArg(blockNumber)) - return (*big.Int)(&result), err -} - -// StorageAt returns the value of key in the contract storage of the given account. -// The block number can be nil, in which case the value is taken from the latest known block. -func (ec *Client) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) { - var result hexutil.Bytes - err := ec.c.CallContext(ctx, &result, "kai_getStorageAt", account, key, toBlockNumArg(blockNumber)) - return result, err -} - -// CodeAt returns the contract code of the given account. -// The block number can be nil, in which case the code is taken from the latest known block. -func (ec *Client) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) { - var result hexutil.Bytes - err := ec.c.CallContext(ctx, &result, "kai_getCode", account, toBlockNumArg(blockNumber)) - return result, err -} - -// NonceAt returns the account nonce of the given account. -// The block number can be nil, in which case the nonce is taken from the latest known block. -func (ec *Client) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) { - var result hexutil.Uint64 - err := ec.c.CallContext(ctx, &result, "kai_getTransactionCount", account, toBlockNumArg(blockNumber)) - return uint64(result), err -} - -// Filters - -// FilterLogs executes a filter query. -func (ec *Client) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) { - var result []types.Log - arg, err := toFilterArg(q) - if err != nil { - return nil, err - } - err = ec.c.CallContext(ctx, &result, "kai_getLogs", arg) - return result, err -} - -// SubscribeFilterLogs subscribes to the results of a streaming filter query. -func (ec *Client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) { - arg, err := toFilterArg(q) - if err != nil { - return nil, err - } - return ec.c.EthSubscribe(ctx, ch, "logs", arg) -} - -func toFilterArg(q ethereum.FilterQuery) (interface{}, error) { - arg := map[string]interface{}{ - "address": q.Addresses, - "topics": q.Topics, - } - if q.BlockHash != nil { - arg["blockHash"] = *q.BlockHash - if q.FromBlock != nil || q.ToBlock != nil { - return nil, fmt.Errorf("cannot specify both BlockHash and FromBlock/ToBlock") - } - } else { - if q.FromBlock == nil { - arg["fromBlock"] = "0x0" - } else { - arg["fromBlock"] = toBlockNumArg(q.FromBlock) - } - arg["toBlock"] = toBlockNumArg(q.ToBlock) - } - return arg, nil -} - -// Pending State - -// PendingBalanceAt returns the wei balance of the given account in the pending state. -func (ec *Client) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) { - var result hexutil.Big - err := ec.c.CallContext(ctx, &result, "kai_getBalance", account, "pending") - return (*big.Int)(&result), err -} - -// PendingStorageAt returns the value of key in the contract storage of the given account in the pending state. -func (ec *Client) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error) { - var result hexutil.Bytes - err := ec.c.CallContext(ctx, &result, "kai_getStorageAt", account, key, "pending") - return result, err -} - -// PendingCodeAt returns the contract code of the given account in the pending state. -func (ec *Client) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) { - var result hexutil.Bytes - err := ec.c.CallContext(ctx, &result, "kai_getCode", account, "pending") - return result, err -} - -// PendingNonceAt returns the account nonce of the given account in the pending state. -// This is the nonce that should be used for the next transaction. -func (ec *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { - var result hexutil.Uint64 - err := ec.c.CallContext(ctx, &result, "kai_getTransactionCount", account, "pending") - return uint64(result), err -} - -// PendingTransactionCount returns the total number of transactions in the pending state. -func (ec *Client) PendingTransactionCount(ctx context.Context) (uint, error) { - var num hexutil.Uint - err := ec.c.CallContext(ctx, &num, "kai_getBlockTransactionCountByNumber", "pending") - return uint(num), err -} - -// TODO: SubscribePendingTransactions (needs server side) - -// Contract Calling - -// CallContract executes a message call transaction, which is directly executed in the VM -// of the node, but never mined into the blockchain. -// -// blockNumber selects the block height at which the call runs. It can be nil, in which -// case the code is taken from the latest known block. Note that state from very old -// blocks might not be available. -func (ec *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { - var hex hexutil.Bytes - err := ec.c.CallContext(ctx, &hex, "kai_call", toCallArg(msg), toBlockNumArg(blockNumber)) - if err != nil { - return nil, err - } - return hex, nil -} - -// PendingCallContract executes a message call transaction using the EVM. -// The state seen by the contract call is the pending state. -func (ec *Client) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) { - var hex hexutil.Bytes - err := ec.c.CallContext(ctx, &hex, "kai_call", toCallArg(msg), "pending") - if err != nil { - return nil, err - } - return hex, nil -} - -// SuggestGasPrice retrieves the currently suggested gas price to allow a timely -// execution of a transaction. -func (ec *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error) { - var hex hexutil.Big - if err := ec.c.CallContext(ctx, &hex, "kai_gasPrice"); err != nil { - return nil, err - } - return (*big.Int)(&hex), nil -} - -// EstimateGas tries to estimate the gas needed to execute a specific transaction based on -// the current pending state of the backend blockchain. There is no guarantee that this is -// the true gas limit requirement as other transactions may be added or removed by miners, -// but it should provide a basis for setting a reasonable default. -func (ec *Client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) { - var hex hexutil.Uint64 - err := ec.c.CallContext(ctx, &hex, "kai_estimateGas", toCallArg(msg)) - if err != nil { - return 0, err - } - return uint64(hex), nil -} - -// SendTransaction injects a signed transaction into the pending pool for execution. -// -// If the transaction was a contract creation use the TransactionReceipt method to get the -// contract address after the transaction has been mined. -func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error { - data, err := rlp.EncodeToBytes(tx) - if err != nil { - return err - } - return ec.c.CallContext(ctx, nil, "kai_sendRawTransaction", hexutil.Encode(data)) -} - -func toCallArg(msg ethereum.CallMsg) interface{} { - arg := map[string]interface{}{ - "from": msg.From, - "to": msg.To, - } - if len(msg.Data) > 0 { - arg["data"] = hexutil.Bytes(msg.Data) - } - if msg.Value != nil { - arg["value"] = (*hexutil.Big)(msg.Value) - } - if msg.Gas != 0 { - arg["gas"] = hexutil.Uint64(msg.Gas) - } - if msg.GasPrice != nil { - arg["gasPrice"] = (*hexutil.Big)(msg.GasPrice) - } - return arg -} diff --git a/native/service/header_sync/kai/state.go b/native/service/header_sync/kai/state.go index 1125c17bb..907447b46 100644 --- a/native/service/header_sync/kai/state.go +++ b/native/service/header_sync/kai/state.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/kardiachain/go-kardia/lib/bytes" - "github.com/kardiachain/go-kardia/types" "github.com/polynetwork/poly/common" ) @@ -52,9 +51,3 @@ func (info *EpochSwitchInfo) Deserialization(source *common.ZeroCopySource) erro } return nil } - -type Header struct { - Header *types.Header - Commit *types.Commit - Vset *types.ValidatorSet -} diff --git a/native/service/header_sync/kai/utils.go b/native/service/header_sync/kai/utils.go index c583b03b5..de28b4e6d 100644 --- a/native/service/header_sync/kai/utils.go +++ b/native/service/header_sync/kai/utils.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" + kaiclient "github.com/kardiachain/go-kaiclient/kardia" "github.com/polynetwork/poly/common" "github.com/polynetwork/poly/common/config" cstates "github.com/polynetwork/poly/core/states" @@ -13,8 +14,8 @@ import ( "github.com/polynetwork/poly/native/service/utils" ) -func VerifyHeader(myHeader *Header, info *EpochSwitchInfo) error { - valset := myHeader.Vset +func VerifyHeader(myHeader *kaiclient.FullHeader, info *EpochSwitchInfo) error { + valset := myHeader.ValidatorSet // now verify this header if !bytes.Equal(info.NextValidatorsHash, valset.Hash().Bytes()) { return fmt.Errorf("VerifyHeader, block validator is not right, next validator hash: %s, "+ @@ -24,7 +25,7 @@ func VerifyHeader(myHeader *Header, info *EpochSwitchInfo) error { return fmt.Errorf("VerifyHeader, block validator is not right!, header validator hash: %s, "+ "validator set hash: %s", myHeader.Header.ValidatorsHash.String(), valset.Hash().Hex()) } - if err := valset.VerifyCommit(info.ChainID, myHeader.Header.LastBlockID, myHeader.Header.Height, myHeader.Commit); err != nil { + if err := valset.VerifyCommit("", myHeader.Header.LastBlockID, myHeader.Header.Height-1, myHeader.Commit); err != nil { return err } return nil From 48907b9936869832929968f0cafe206fe37b3d9c Mon Sep 17 00:00:00 2001 From: dogecoindev Date: Tue, 25 May 2021 17:30:19 +0700 Subject: [PATCH 23/23] fix import kai full header --- native/service/cross_chain_manager/kai/handler.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/native/service/cross_chain_manager/kai/handler.go b/native/service/cross_chain_manager/kai/handler.go index 01d17f87a..2a47d5e3d 100644 --- a/native/service/cross_chain_manager/kai/handler.go +++ b/native/service/cross_chain_manager/kai/handler.go @@ -29,6 +29,7 @@ import ( "github.com/ethereum/go-ethereum/light" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" + kaiclient "github.com/kardiachain/go-kaiclient/kardia" "github.com/kardiachain/go-kardia/types" "github.com/polynetwork/poly/common" "github.com/polynetwork/poly/common/log" @@ -66,7 +67,7 @@ func (h *Handler) MakeDepositProposal(service *native.NativeService) (*scom.Make return nil, fmt.Errorf("you must commit the header used to verify transaction's proof and get none") } - var myHeader hskai.Header + var myHeader kaiclient.FullHeader if err := json.Unmarshal(params.HeaderOrCrossChainMsg, &myHeader); err != nil { return nil, fmt.Errorf("KAI MakeDepositProposal, unmarshal cosmos header failed: %v", err) }