From 5396a9ec25bd864da754804ed4887dea78f1fe6a Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 11 Nov 2020 18:20:47 +0800 Subject: [PATCH 001/107] init: project --- .gitignore | 2 + cmd/root.go | 62 +++ cmd/run.go | 26 ++ config.yaml | 1 + db/db.go | 59 +++ go.mod | 13 + go.sum | 828 ++++++++++++++++++++++++++++++++++++++++ main.go | 7 + service/poly2zil.go | 1 + service/sync_service.go | 47 +++ service/zil2poly.go | 1 + 11 files changed, 1047 insertions(+) create mode 100644 .gitignore create mode 100644 cmd/root.go create mode 100644 cmd/run.go create mode 100644 config.yaml create mode 100644 db/db.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 service/poly2zil.go create mode 100644 service/sync_service.go create mode 100644 service/zil2poly.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ac0a8d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +zilliqa-relayer +.idea \ No newline at end of file diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..d35a135 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,62 @@ +package cmd + +import ( + "fmt" + "github.com/mitchellh/go-homedir" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "os" +) + +var cfgFile string + +func init() { + cobra.OnInitialize(initConfig) + RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)") +} + +func initConfig() { + if cfgFile != "" { + // Use config file from the flag. + viper.SetConfigFile(cfgFile) + } else { + // Find home directory. + home, err := homedir.Dir() + if err != nil { + er(err) + } + + // Search config in home directory with name ".cobra" (without extension). + viper.AddConfigPath(home) + viper.SetConfigName(".cobra") + } + + viper.AutomaticEnv() + + err := viper.ReadInConfig() + if err == nil { + fmt.Println("Using config file:", viper.ConfigFileUsed()) + } else { + fmt.Println(err.Error()) + } +} + +func er(msg interface{}) { + fmt.Println("Error:", msg) + os.Exit(1) +} + +var RootCmd = &cobra.Command{ + Use: "zilliqa-relayer", + Short: "To run zilliqa relayer for poly network", + Long: `To run zilliqa relayer for poly network`, + Run: func(cmd *cobra.Command, args []string) { + }, +} + +func Execute() { + if err := RootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/cmd/run.go b/cmd/run.go new file mode 100644 index 0000000..6c8133e --- /dev/null +++ b/cmd/run.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "fmt" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "log" +) + + +func init() { + RootCmd.AddCommand(runCmd) + runCmd.Flags().String("api", "https://api.zilliqa.com", "zilliqa api endpoint") + if err := viper.BindPFlag("api", runCmd.Flags().Lookup("api")); err != nil { + log.Fatal("Unable to bind flag:", err) + }} + +var runCmd = &cobra.Command{ + Use: "run", + Short: "Run zilliqa relayer", + Long: `Run zilliqa relayer`, + Run: func(cmd *cobra.Command, args []string) { + msg := viper.GetString("api") + fmt.Println(msg) + }, +} diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..72233f7 --- /dev/null +++ b/config.yaml @@ -0,0 +1 @@ +api: https://dev-api.zilliqa.com \ No newline at end of file diff --git a/db/db.go b/db/db.go new file mode 100644 index 0000000..29fd324 --- /dev/null +++ b/db/db.go @@ -0,0 +1,59 @@ +package db + +import ( + "github.com/boltdb/bolt" + "path" + "strings" + "sync" +) + +type BoltDB struct { + rwLock *sync.RWMutex + db *bolt.DB + filePath string +} + +var ( + BKTCheck = []byte("Check") + BKTRetry = []byte("Retry") +) + +func NewBoltDB(filePath string) (*BoltDB, error) { + if !strings.Contains(filePath, ".bin") { + filePath = path.Join(filePath, "bolt.bin") + } + + w := new(BoltDB) + db, err := bolt.Open(filePath, 0644, &bolt.Options{InitialMmapSize: 500000}) + if err != nil { + return nil, err + } + + w.db = db + w.rwLock = new(sync.RWMutex) + w.filePath = filePath + + // poly check + if err = db.Update(func(btx *bolt.Tx) error { + _, err := btx.CreateBucketIfNotExists(BKTCheck) + if err != nil { + return err + } + return nil + }); err != nil { + return nil, err + } + + // poly retry + if err = db.Update(func(btx *bolt.Tx) error { + _, err := btx.CreateBucketIfNotExists(BKTRetry) + if err != nil { + return err + } + return nil + }); err != nil { + return nil, err + } + + return w, nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..967a801 --- /dev/null +++ b/go.mod @@ -0,0 +1,13 @@ +module github.com/polynetwork/zilliqa-relayer + +go 1.15 + +require ( + github.com/Zilliqa/gozilliqa-sdk v1.2.0 + github.com/boltdb/bolt v1.3.1 + github.com/mitchellh/go-homedir v1.1.0 + github.com/polynetwork/poly v0.0.0-20200715030435-4f1d1a0adb44 + github.com/polynetwork/poly-go-sdk v0.0.0-20200817120957-365691ad3493 + github.com/spf13/cobra v1.1.1 + github.com/spf13/viper v1.7.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3b4f4cd --- /dev/null +++ b/go.sum @@ -0,0 +1,828 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/99designs/keyring v1.1.3/go.mod h1:657DQuMrBZRtuL/voxVyiyb6zpMehlm5vLB9Qwrv904= +github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= +github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc= +github.com/Azure/azure-storage-blob-go v0.7.0/go.mod h1:f9YQKtsG1nMisotuTPpO0tjNuEjKRYAcJU8/ydDI++4= +github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= +github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= +github.com/Azure/go-autorest/autorest/adal v0.8.0/go.mod h1:Z6vX6WXXuyieHAXwMj0S6HY6e6wcHn37qQMBQlvY3lc= +github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA= +github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g= +github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= +github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= +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/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/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc= +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= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/OneOfOne/xxhash v1.2.5/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q= +github.com/OpenBazaar/jsonpb v0.0.0-20171123000858-37d32ddf4eef/go.mod h1:55mCznBcN9WQgrtgaAkv+p2LxeW/tQRdidyyE9D0I5k= +github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= +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/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/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.0 h1:pxINq2woI80BQkMb8dnIVsHw0pk6AkEnZ7DNE94bDMo= +github.com/Zilliqa/gozilliqa-sdk v1.2.0/go.mod h1:eSYp2T6f0apnuW8TzhV3f6Aff2SE8Dwio++U4ha4yEM= +github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +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/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= +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/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= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= +github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= +github.com/aws/aws-sdk-go v1.25.48/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= +github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= +github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= +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/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= +github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= +github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ= +github.com/btcsuite/btcd v0.0.0-20190115013929-ed77733ec07d/go.mod h1:d3C0AkH6BRcvO8T0UEPu53cnw4IbV63x1bEjildYhO0= +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/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= +github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/btcutil v1.0.2 h1:9iZ1Terx9fMIOtq1VrwdqfsATL9MC2l8ZrUY6YZ2uts= +github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts= +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/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/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= +github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= +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/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= +github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +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/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= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +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/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= +github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= +github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= +github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9QWFanOyI= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/danieljoos/wincred v1.0.2/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U= +github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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/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/dop251/goja v0.0.0-20200219165308-d1232e640a87/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/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/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= +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= +github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +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 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= +github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= +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/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= +github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= +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/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/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/bchlog v0.0.0-20180913005452-b4f036f92fa6 h1:3pZvWJ8MSfWstGrb8Hfh4ZpLyZNcXypcGx2Ju4ZibVM= +github.com/gcash/bchlog v0.0.0-20180913005452-b4f036f92fa6/go.mod h1:PpfmXTLfjRp7Tf6v/DCGTRXHz+VFbiRcsoUxi7HvwlQ= +github.com/gcash/bchutil v0.0.0-20190625002603-800e62fe9aff/go.mod h1:zXSP0Fg2L52wpSEDApQDQMiSygnQiK5HDquDl0a5BHg= +github.com/gcash/bchutil v0.0.0-20191012211144-98e73ec336ba/go.mod h1:nUIrcbbtEQdCsRwcp+j/CndDKMQE9Fi8p2F8cIZmIqI= +github.com/gcash/bchutil v0.0.0-20200229194731-128fc9884722/go.mod h1:wB++2ZcHUvGLN1OgO9swBmJK1vmyshJLW9SNS+apXwc= +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/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +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= +github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4= +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-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= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= +github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +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/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= +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.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.3.1/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= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2-0.20190517061210-b285ee9cfc6c/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +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/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/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/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/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +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/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gosuri/uilive v0.0.3/go.mod h1:qkLSc0A5EXSP6B04TrN4oQoxqFI7A8XvoXSlJi8cwk8= +github.com/gosuri/uilive v0.0.4/go.mod h1:V/epo5LjjlDE5RJUcqx8dbw+zc93y5Ya3yg8tfZ74VI= +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= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +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/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uMzcc= +github.com/gtank/ristretto255 v0.1.2/go.mod h1:Ph5OpO6c7xKUGROZfWVLiJf9icMDwUeIvY4OmlYW69o= +github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= +github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= +github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +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/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs= +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/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/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= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +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/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/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +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/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= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +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/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +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/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +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= +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.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +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/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= +github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= +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 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +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= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0= +github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= +github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= +github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= +github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= +github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= +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/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= +github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c h1:1RHs3tNxjXGHeul8z2t6H2N2TlAqpKe5yryJztRx4Jk= +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/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +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/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/ontio/go-bip32 v0.0.0-20190520025953-d3cea6894a2b h1:UQDN12BzdWhXQL0t2QcRixHqAIG+JKNvQ20DhrIODtU= +github.com/ontio/go-bip32 v0.0.0-20190520025953-d3cea6894a2b/go.mod h1:J0eVc7BEMmVVXbGv9PHoxjRSEwOwLr0qfzPk8Rdl5iw= +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-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/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= +github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= +github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA= +github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= +github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= +github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= +github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6 h1:lNCW6THrCKBiJBpz8kbVGjC7MgdCGKwuvBgc7LoD6sw= +github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI= +github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pborman/uuid v0.0.0-20170112150404-1b00554d8222/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34= +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/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= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +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/poly v0.0.0-20200715030435-4f1d1a0adb44 h1:QXznsPhBBa1vY6Fhav8S9+qoHBi8iGy6g1VeIMdYglI= +github.com/polynetwork/poly v0.0.0-20200715030435-4f1d1a0adb44/go.mod h1:UzlGEWk0eCGsuMJOZfBoZjRbmu4Yw/SudKAIFe1gPnY= +github.com/polynetwork/poly-go-sdk v0.0.0-20200817120957-365691ad3493 h1:wob4aH5NxiDFIOWlpKbmoIb88QOccDNa1+rl93czjr8= +github.com/polynetwork/poly-go-sdk v0.0.0-20200817120957-365691ad3493/go.mod h1:a1wMo/VFoUAKX2yVjipvFug6Yu5BPhf/2tP5xywqfIc= +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_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/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/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/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= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +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/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= +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/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/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/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/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/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +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= +github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= +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.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= +github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= +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.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM= +github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= +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= +github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 h1:njlZPzLwU639dk2kqnCPPv+wNjq7Xb6EfUxe/oX0/NM= +github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU= +github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= +github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= +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/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.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/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= +github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk= +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.13.2 h1:O1m08/Ciy53l9IYmf75uIRVvrNsfjEbre8u/yCu/oqk= +github.com/tendermint/iavl v0.13.2/go.mod h1:vE1u0XAGXYjHykd4BLp8p/yivrw2PF1TuoljBcsQoGA= +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/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/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/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/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +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= +github.com/zquestz/grab v0.0.0-20190224022517-abcee96e61b1/go.mod h1:bslhAiUxakrA6z6CHmVyvkfpnxx18RJBwVyx2TluJWw= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= +go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= +go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4/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/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +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-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/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-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +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/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= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +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-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +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/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +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/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-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-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +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= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +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-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/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/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +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= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +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-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/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/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +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= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +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/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= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +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/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/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +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= +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/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/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/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +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= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +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= +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-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/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= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +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/main.go b/main.go new file mode 100644 index 0000000..04dd152 --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/polynetwork/zilliqa-relayer/cmd" + +func main() { + cmd.Execute() +} diff --git a/service/poly2zil.go b/service/poly2zil.go new file mode 100644 index 0000000..6d43c33 --- /dev/null +++ b/service/poly2zil.go @@ -0,0 +1 @@ +package service diff --git a/service/sync_service.go b/service/sync_service.go new file mode 100644 index 0000000..be48523 --- /dev/null +++ b/service/sync_service.go @@ -0,0 +1,47 @@ +package service + +import ( + "github.com/Zilliqa/gozilliqa-sdk/provider" + poly "github.com/polynetwork/poly-go-sdk" + "github.com/polynetwork/poly/account" + "github.com/polynetwork/zilliqa-relayer/db" + "log" + "os" +) + +type SyncService struct { + relayAccount *poly.Account + relaySdk *poly.PolySdk + relaySyncHeight uint32 + + zilAccount *account.Account + zilSdk *provider.Provider + + db *db.BoltDB +} + +func NewSyncService(replayAccount *poly.Account, replaySdk *poly.PolySdk, zilAccount *account.Account, zilSdk *provider.Provider, path string) *SyncService { + if !checkIfExist(path) { + os.Mkdir(path, os.ModePerm) + } + boltDB, err := db.NewBoltDB(path) + if err != nil { + log.Fatal("cannot init bolt db") + } + + return &SyncService{ + relayAccount: replayAccount, + relaySdk: replaySdk, + zilAccount: zilAccount, + zilSdk: zilSdk, + db: boltDB, + } +} + +func checkIfExist(dir string) bool { + _, err := os.Stat(dir) + if err != nil && !os.IsExist(err) { + return false + } + return true +} diff --git a/service/zil2poly.go b/service/zil2poly.go new file mode 100644 index 0000000..6d43c33 --- /dev/null +++ b/service/zil2poly.go @@ -0,0 +1 @@ +package service From f5d508b7ee33eeee53bb5a5e0e11a0304e51638f Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 25 Nov 2020 17:17:00 +0800 Subject: [PATCH 002/107] chore: define config file, and restruct some part --- .gitignore | 4 ++- cmd/root.go | 40 ------------------------- cmd/run.go | 66 ++++++++++++++++++++++++++++++++++++++--- config.yaml | 4 ++- config/config.go | 9 ++++++ service/sync_service.go | 39 ++++++++++++++++++------ service/zil2poly.go | 12 ++++++++ 7 files changed, 119 insertions(+), 55 deletions(-) create mode 100644 config/config.go diff --git a/.gitignore b/.gitignore index 5ac0a8d..8fb3c1f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ zilliqa-relayer -.idea \ No newline at end of file +.idea +bolt.bin +zilliqa-relayer \ No newline at end of file diff --git a/cmd/root.go b/cmd/root.go index d35a135..7eaf328 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,50 +2,10 @@ package cmd import ( "fmt" - "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" - "github.com/spf13/viper" "os" ) -var cfgFile string - -func init() { - cobra.OnInitialize(initConfig) - RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)") -} - -func initConfig() { - if cfgFile != "" { - // Use config file from the flag. - viper.SetConfigFile(cfgFile) - } else { - // Find home directory. - home, err := homedir.Dir() - if err != nil { - er(err) - } - - // Search config in home directory with name ".cobra" (without extension). - viper.AddConfigPath(home) - viper.SetConfigName(".cobra") - } - - viper.AutomaticEnv() - - err := viper.ReadInConfig() - if err == nil { - fmt.Println("Using config file:", viper.ConfigFileUsed()) - } else { - fmt.Println(err.Error()) - } -} - -func er(msg interface{}) { - fmt.Println("Error:", msg) - os.Exit(1) -} - var RootCmd = &cobra.Command{ Use: "zilliqa-relayer", Short: "To run zilliqa relayer for poly network", diff --git a/cmd/run.go b/cmd/run.go index 6c8133e..8e5e6b6 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -2,25 +2,83 @@ package cmd import ( "fmt" + "github.com/mitchellh/go-homedir" + "github.com/polynetwork/zilliqa-relayer/config" + "github.com/polynetwork/zilliqa-relayer/service" "github.com/spf13/cobra" "github.com/spf13/viper" "log" + "os" ) +var cfgFile string func init() { - RootCmd.AddCommand(runCmd) + cobra.OnInitialize(initConfig) + RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)") + runCmd.Flags().String("api", "https://api.zilliqa.com", "zilliqa api endpoint") if err := viper.BindPFlag("api", runCmd.Flags().Lookup("api")); err != nil { log.Fatal("Unable to bind flag:", err) - }} + } + runCmd.Flags().String("zil_start_height", "1", "the from block number will be syncing to poly network") + if err := viper.BindPFlag("api", runCmd.Flags().Lookup("zil_start_height")); err != nil { + log.Fatal("Unable to bind flag:", err) + } + + runCmd.Flags().String("zil_scan_interval", "2", "the interval scanning zilliqa block") + if err := viper.BindPFlag("zil_scan_interval", runCmd.Flags().Lookup("zil_scan_interval")); err != nil { + log.Fatal("Unable to bind flag:", err) + } + + RootCmd.AddCommand(runCmd) +} + +func initConfig() { + if cfgFile != "" { + // Use config file from the flag. + viper.SetConfigFile(cfgFile) + } else { + // Find home directory. + home, err := homedir.Dir() + if err != nil { + er(err) + } + + // Search config in home directory with name ".cobra" (without extension). + viper.AddConfigPath(home) + viper.SetConfigName(".cobra") + } + + viper.AutomaticEnv() + + err := viper.ReadInConfig() + if err == nil { + fmt.Println("Using config file:", viper.ConfigFileUsed()) + } else { + fmt.Println(err.Error()) + } + +} + +func er(msg interface{}) { + fmt.Println("Error:", msg) + os.Exit(1) +} var runCmd = &cobra.Command{ Use: "run", Short: "Run zilliqa relayer", Long: `Run zilliqa relayer`, Run: func(cmd *cobra.Command, args []string) { - msg := viper.GetString("api") - fmt.Println(msg) + + cfg := &config.Config{ + ZilApiEndpoint: viper.GetString("api"), + ZilStartHeight: viper.GetUint32("zil_start_height"), + ZilScanInterval: viper.GetUint64("zil_scan_interval"), + } + + syncService := service.NewSyncService(cfg) + syncService.Run() }, } diff --git a/config.yaml b/config.yaml index 72233f7..7928fe1 100644 --- a/config.yaml +++ b/config.yaml @@ -1 +1,3 @@ -api: https://dev-api.zilliqa.com \ No newline at end of file +api: https://dev-api.zilliqa.com +zil_start_height: 1 +zil_scan_interval: 5 \ No newline at end of file diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..b26be77 --- /dev/null +++ b/config/config.go @@ -0,0 +1,9 @@ +package config + +type Config struct { + Path string + + ZilScanInterval uint64 + ZilApiEndpoint string + ZilStartHeight uint32 +} diff --git a/service/sync_service.go b/service/sync_service.go index be48523..7a0fe06 100644 --- a/service/sync_service.go +++ b/service/sync_service.go @@ -4,9 +4,12 @@ import ( "github.com/Zilliqa/gozilliqa-sdk/provider" poly "github.com/polynetwork/poly-go-sdk" "github.com/polynetwork/poly/account" + "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/db" "log" "os" + "os/signal" + "syscall" ) type SyncService struct { @@ -17,27 +20,31 @@ type SyncService struct { zilAccount *account.Account zilSdk *provider.Provider + cfg *config.Config + db *db.BoltDB } -func NewSyncService(replayAccount *poly.Account, replaySdk *poly.PolySdk, zilAccount *account.Account, zilSdk *provider.Provider, path string) *SyncService { - if !checkIfExist(path) { - os.Mkdir(path, os.ModePerm) +func NewSyncService(cfg *config.Config) *SyncService { + if !checkIfExist(cfg.Path) { + os.Mkdir(cfg.Path, os.ModePerm) } - boltDB, err := db.NewBoltDB(path) + boltDB, err := db.NewBoltDB(cfg.Path) if err != nil { log.Fatal("cannot init bolt db") } return &SyncService{ - relayAccount: replayAccount, - relaySdk: replaySdk, - zilAccount: zilAccount, - zilSdk: zilSdk, - db: boltDB, + db: boltDB, + cfg: cfg, } } +func (s *SyncService) Run() { + go s.Zil2Poly() + waitToExit() +} + func checkIfExist(dir string) bool { _, err := os.Stat(dir) if err != nil && !os.IsExist(err) { @@ -45,3 +52,17 @@ func checkIfExist(dir string) bool { } return true } + +func waitToExit() { + exit := make(chan bool, 0) + sc := make(chan os.Signal, 1) + signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) + go func() { + for sig := range sc { + log.Println("Zilliqa Relayer received exit signal: %v.", sig.String()) + close(exit) + break + } + }() + <-exit +} diff --git a/service/zil2poly.go b/service/zil2poly.go index 6d43c33..905b5ad 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -1 +1,13 @@ package service + +import ( + "log" + "time" +) + +func (s *SyncService) Zil2Poly() { + for { + log.Println("start scan block") + time.Sleep(time.Duration(s.cfg.ZilScanInterval) * time.Second) + } +} From cfccd10a20554bd9bb166e130263edfd96fd5a5c Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 13 Jan 2021 18:37:31 +0800 Subject: [PATCH 003/107] chore: add build and run script --- build.sh | 2 ++ cmd/run.go | 14 ++++---------- run.sh | 2 ++ 3 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 build.sh create mode 100644 run.sh diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..b972750 --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +#!/bin/sh +go build \ No newline at end of file diff --git a/cmd/run.go b/cmd/run.go index 8e5e6b6..6afd2cb 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - "github.com/mitchellh/go-homedir" "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/service" "github.com/spf13/cobra" @@ -39,15 +38,8 @@ func initConfig() { // Use config file from the flag. viper.SetConfigFile(cfgFile) } else { - // Find home directory. - home, err := homedir.Dir() - if err != nil { - er(err) - } - - // Search config in home directory with name ".cobra" (without extension). - viper.AddConfigPath(home) - viper.SetConfigName(".cobra") + viper.AddConfigPath("./") + viper.SetConfigName("config") } viper.AutomaticEnv() @@ -78,6 +70,8 @@ var runCmd = &cobra.Command{ ZilScanInterval: viper.GetUint64("zil_scan_interval"), } + log.Printf("config file: %+v\n", cfg) + syncService := service.NewSyncService(cfg) syncService.Run() }, diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..052a2ce --- /dev/null +++ b/run.sh @@ -0,0 +1,2 @@ +#!/bin/sh +./zilliqa-relayer run \ No newline at end of file From 9d9cb37892ed77b43e0d057b555f51ac14076caf Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 13 Jan 2021 19:36:42 +0800 Subject: [PATCH 004/107] feat: monitor tx block number --- cmd/run.go | 6 ++--- config.yaml | 4 +-- config/config.go | 6 ++--- service/sync_service.go | 21 ++++++++------- service/zil2poly.go | 58 ++++++++++++++++++++++++++++++++++++++--- 5 files changed, 74 insertions(+), 21 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 6afd2cb..4d1322a 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -65,9 +65,9 @@ var runCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { cfg := &config.Config{ - ZilApiEndpoint: viper.GetString("api"), - ZilStartHeight: viper.GetUint32("zil_start_height"), - ZilScanInterval: viper.GetUint64("zil_scan_interval"), + ZilApiEndpoint: viper.GetString("api"), + ZilStartHeight: viper.GetUint32("zil_start_height"), + ZilMonitorInterval: viper.GetUint32("zil_monitor_interval"), } log.Printf("config file: %+v\n", cfg) diff --git a/config.yaml b/config.yaml index 7928fe1..09a8836 100644 --- a/config.yaml +++ b/config.yaml @@ -1,3 +1,3 @@ api: https://dev-api.zilliqa.com -zil_start_height: 1 -zil_scan_interval: 5 \ No newline at end of file +zil_start_height: 2291449 +zil_monitor_interval: 40 \ No newline at end of file diff --git a/config/config.go b/config/config.go index b26be77..323fe4a 100644 --- a/config/config.go +++ b/config/config.go @@ -3,7 +3,7 @@ package config type Config struct { Path string - ZilScanInterval uint64 - ZilApiEndpoint string - ZilStartHeight uint32 + ZilMonitorInterval uint32 + ZilApiEndpoint string + ZilStartHeight uint32 } diff --git a/service/sync_service.go b/service/sync_service.go index 7a0fe06..8d506c4 100644 --- a/service/sync_service.go +++ b/service/sync_service.go @@ -16,13 +16,12 @@ type SyncService struct { relayAccount *poly.Account relaySdk *poly.PolySdk relaySyncHeight uint32 - - zilAccount *account.Account - zilSdk *provider.Provider - - cfg *config.Config - - db *db.BoltDB + zilAccount *account.Account + currentHeight uint64 + zilSdk *provider.Provider + cfg *config.Config + db *db.BoltDB + exitChan chan int } func NewSyncService(cfg *config.Config) *SyncService { @@ -35,13 +34,15 @@ func NewSyncService(cfg *config.Config) *SyncService { } return &SyncService{ - db: boltDB, - cfg: cfg, + db: boltDB, + cfg: cfg, + zilSdk: provider.NewProvider(cfg.ZilApiEndpoint), + currentHeight: uint64(cfg.ZilStartHeight), } } func (s *SyncService) Run() { - go s.Zil2Poly() + go s.MonitorChain() waitToExit() } diff --git a/service/zil2poly.go b/service/zil2poly.go index 905b5ad..c592e9f 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -2,12 +2,64 @@ package service import ( "log" + "strconv" "time" ) -func (s *SyncService) Zil2Poly() { +func (s *SyncService) handleNewBlock(height uint64) bool { + log.Printf("handle new block: %d\n", height) + ret := s.handleBlockHeader(height) + if !ret { + log.Printf("handleNewBlock - handleBlockHeader on height :%d failed\n", height) + return false + } + ret = s.fetchLockDepositEvents(height) + if !ret { + log.Printf("handleNewBlock - fetchLockDepositEvents on height :%d failed\n", height) + } + return true +} + +func (s *SyncService) handleBlockHeader(height uint64) bool { + // todo + return true +} + +func (s *SyncService) fetchLockDepositEvents(height uint64) bool { + // todo + return true +} + +func (s *SyncService) MonitorChain() { + log.Printf("start scan block at height: %d\n", s.currentHeight) + fetchBlockTicker := time.NewTicker(time.Duration(s.cfg.ZilMonitorInterval) * time.Second) for { - log.Println("start scan block") - time.Sleep(time.Duration(s.cfg.ZilScanInterval) * time.Second) + select { + case <-fetchBlockTicker.C: + txBlock, err := s.zilSdk.GetLatestTxBlock() + if err != nil { + log.Printf("MonitorChain - cannot get node hight, err: %s\n", err.Error()) + continue + } + log.Printf("current tx block height: %s\n", txBlock.Header.BlockNum) + blockNumber, err2 := strconv.ParseUint(txBlock.Header.BlockNum, 10, 32) + if err2 != nil { + log.Printf("MonitorChain - cannot parse block height, err: %s\n", err2.Error()) + } + if s.currentHeight >= blockNumber { + log.Printf("cuurent height is not changed, skip") + continue + } + + for s.currentHeight < blockNumber { + s.handleNewBlock(s.currentHeight + 1) + s.currentHeight++ + } + + case <-s.exitChan: + return + + } + } } From 63d470e887d9d12fb6585a0ddcae6ae00fe220e9 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 13 Jan 2021 21:51:29 +0800 Subject: [PATCH 005/107] wip: monitor transactions come to cross chain manager, parse event, store to local db --- README.md | 27 +++++++++++++++++- build.sh | 0 cmd/root.go | 5 ++-- cmd/run.go | 22 ++++++-------- config.yaml | 5 ++-- config/config.go | 7 +++-- db/db.go | 15 ++++++++++ go.mod | 2 +- go.sum | 3 ++ run.sh | 0 service/sync_service.go | 25 +++++++++------- service/zil2poly.go | 63 ++++++++++++++++++++++++++++++++++------- 12 files changed, 130 insertions(+), 44 deletions(-) mode change 100644 => 100755 build.sh mode change 100644 => 100755 run.sh diff --git a/README.md b/README.md index 5274f53..bd347eb 100644 --- a/README.md +++ b/README.md @@ -1 +1,26 @@ -# zilliqa-relayer \ No newline at end of file +# zilliqa-relayer + +Zilliqa Relayer is an important character of Poly cross-chain interactive protocol which is responsible for relaying cross-chain transaction from and to Zilliqa. + +## Build From Source + +### Prerequisites + +- [Golang](https://golang.org/doc/install) version 1.14 or later + +```shell +git clone https://github.com/polynetwork/zil-relayer.git +cd zil-relayer +./build.sh +``` + +After building the source code successfully, you should see the executable program `zilliqa-relayer`. + +## Other Resources + +- [zilliqa cross chain manager proxy](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/ZilCrossChainManagerProxy.scilla) +- [zilliqa cross chain manager](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/ZilCrossChainManager.scilla) +- [zilliqa lock proxy](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/LockProxy.scilla) + + + diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/cmd/root.go b/cmd/root.go index 7eaf328..e095e1b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,8 +1,9 @@ package cmd import ( - "fmt" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "os" ) @@ -16,7 +17,7 @@ var RootCmd = &cobra.Command{ func Execute() { if err := RootCmd.Execute(); err != nil { - fmt.Println(err) + log.Error(err) os.Exit(1) } } diff --git a/cmd/run.go b/cmd/run.go index 4d1322a..c165c8c 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -1,13 +1,11 @@ package cmd import ( - "fmt" "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/service" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" - "log" - "os" ) var cfgFile string @@ -46,18 +44,13 @@ func initConfig() { err := viper.ReadInConfig() if err == nil { - fmt.Println("Using config file:", viper.ConfigFileUsed()) + log.Info("Using config file:", viper.ConfigFileUsed()) } else { - fmt.Println(err.Error()) + log.Error(err.Error()) } } -func er(msg interface{}) { - fmt.Println("Error:", msg) - os.Exit(1) -} - var runCmd = &cobra.Command{ Use: "run", Short: "Run zilliqa relayer", @@ -65,12 +58,13 @@ var runCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { cfg := &config.Config{ - ZilApiEndpoint: viper.GetString("api"), - ZilStartHeight: viper.GetUint32("zil_start_height"), - ZilMonitorInterval: viper.GetUint32("zil_monitor_interval"), + ZilApiEndpoint: viper.GetString("api"), + ZilStartHeight: viper.GetUint32("zil_start_height"), + ZilMonitorInterval: viper.GetUint32("zil_monitor_interval"), + CrossChainManagerContract: viper.GetString("corss_chain_manager_address"), } - log.Printf("config file: %+v\n", cfg) + log.Infof("config file: %+v\n", cfg) syncService := service.NewSyncService(cfg) syncService.Run() diff --git a/config.yaml b/config.yaml index 09a8836..e41d8e2 100644 --- a/config.yaml +++ b/config.yaml @@ -1,3 +1,4 @@ api: https://dev-api.zilliqa.com -zil_start_height: 2291449 -zil_monitor_interval: 40 \ No newline at end of file +zil_start_height: 2291747 +zil_monitor_interval: 40 +corss_chain_manager_address: zil1y0mesa67hvsm92mupp9alqqevzst3ymspggj40 \ No newline at end of file diff --git a/config/config.go b/config/config.go index 323fe4a..6cb38d1 100644 --- a/config/config.go +++ b/config/config.go @@ -3,7 +3,8 @@ package config type Config struct { Path string - ZilMonitorInterval uint32 - ZilApiEndpoint string - ZilStartHeight uint32 + ZilMonitorInterval uint32 + ZilApiEndpoint string + ZilStartHeight uint32 + CrossChainManagerContract string } diff --git a/db/db.go b/db/db.go index 29fd324..bf2e63d 100644 --- a/db/db.go +++ b/db/db.go @@ -57,3 +57,18 @@ func NewBoltDB(filePath string) (*BoltDB, error) { return w, nil } + +func (w *BoltDB) PutRetry(k []byte) error { + w.rwLock.Lock() + defer w.rwLock.Unlock() + + return w.db.Update(func(btx *bolt.Tx) error { + bucket := btx.Bucket(BKTRetry) + err := bucket.Put(k, []byte{0x00}) + if err != nil { + return err + } + + return nil + }) +} diff --git a/go.mod b/go.mod index 967a801..66292ca 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,9 @@ go 1.15 require ( github.com/Zilliqa/gozilliqa-sdk v1.2.0 github.com/boltdb/bolt v1.3.1 - github.com/mitchellh/go-homedir v1.1.0 github.com/polynetwork/poly v0.0.0-20200715030435-4f1d1a0adb44 github.com/polynetwork/poly-go-sdk v0.0.0-20200817120957-365691ad3493 + github.com/sirupsen/logrus v1.7.0 github.com/spf13/cobra v1.1.1 github.com/spf13/viper v1.7.0 ) diff --git a/go.sum b/go.sum index 3b4f4cd..e688149 100644 --- a/go.sum +++ b/go.sum @@ -505,6 +505,8 @@ github.com/shirou/gopsutil v2.20.5-0.20200531151128-663af789c085+incompatible/go 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.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= 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= @@ -700,6 +702,7 @@ golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/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-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= diff --git a/run.sh b/run.sh old mode 100644 new mode 100755 diff --git a/service/sync_service.go b/service/sync_service.go index 8d506c4..050038a 100644 --- a/service/sync_service.go +++ b/service/sync_service.go @@ -6,7 +6,7 @@ import ( "github.com/polynetwork/poly/account" "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/db" - "log" + log "github.com/sirupsen/logrus" "os" "os/signal" "syscall" @@ -17,11 +17,13 @@ type SyncService struct { relaySdk *poly.PolySdk relaySyncHeight uint32 zilAccount *account.Account - currentHeight uint64 - zilSdk *provider.Provider - cfg *config.Config - db *db.BoltDB - exitChan chan int + + currentHeight uint64 + zilSdk *provider.Provider + corssChainManagerAddress string + cfg *config.Config + db *db.BoltDB + exitChan chan int } func NewSyncService(cfg *config.Config) *SyncService { @@ -34,10 +36,11 @@ func NewSyncService(cfg *config.Config) *SyncService { } return &SyncService{ - db: boltDB, - cfg: cfg, - zilSdk: provider.NewProvider(cfg.ZilApiEndpoint), - currentHeight: uint64(cfg.ZilStartHeight), + db: boltDB, + cfg: cfg, + zilSdk: provider.NewProvider(cfg.ZilApiEndpoint), + currentHeight: uint64(cfg.ZilStartHeight), + corssChainManagerAddress: cfg.CrossChainManagerContract, } } @@ -60,7 +63,7 @@ func waitToExit() { signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) go func() { for sig := range sc { - log.Println("Zilliqa Relayer received exit signal: %v.", sig.String()) + log.Infof("Zilliqa Relayer received exit signal: %v.", sig.String()) close(exit) break } diff --git a/service/zil2poly.go b/service/zil2poly.go index c592e9f..fa708d3 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -1,21 +1,39 @@ package service import ( - "log" + "github.com/Zilliqa/gozilliqa-sdk/bech32" + "github.com/polynetwork/poly/common" + log "github.com/sirupsen/logrus" "strconv" "time" ) +type CrossTransfer struct { + txIndex string + txId []byte + value []byte + toChain uint32 + height uint64 +} + +func (this *CrossTransfer) Serialization(sink *common.ZeroCopySink) { + sink.WriteString(this.txIndex) + sink.WriteVarBytes(this.txId) + sink.WriteVarBytes(this.value) + sink.WriteUint32(this.toChain) + sink.WriteUint64(this.height) +} + func (s *SyncService) handleNewBlock(height uint64) bool { - log.Printf("handle new block: %d\n", height) + log.Infof("handle new block: %d\n", height) ret := s.handleBlockHeader(height) if !ret { - log.Printf("handleNewBlock - handleBlockHeader on height :%d failed\n", height) + log.Infof("handleNewBlock - handleBlockHeader on height :%d failed\n", height) return false } ret = s.fetchLockDepositEvents(height) if !ret { - log.Printf("handleNewBlock - fetchLockDepositEvents on height :%d failed\n", height) + log.Infof("handleNewBlock - fetchLockDepositEvents on height :%d failed\n", height) } return true } @@ -25,29 +43,54 @@ func (s *SyncService) handleBlockHeader(height uint64) bool { return true } +// the workflow is: user -> LockProxy on zilliqa -> Cross Chain Manager -> emit event +// so here we need to filter out those transactions related to cross chain manager +// and parse the events, commit them to the polynetwork func (s *SyncService) fetchLockDepositEvents(height uint64) bool { - // todo + transactions, err := s.zilSdk.GetTxnBodiesForTxBlock(strconv.FormatUint(height, 10)) + if err != nil { + log.Infof("get transactions for tx block %d failed: %s\n", height, err.Error()) + return false + } + + for _, transaction := range transactions { + toAddr, _ := bech32.ToBech32Address(transaction.ToAddr) + log.Infof("to address: %s\n", toAddr) + if toAddr == s.corssChainManagerAddress { + log.Infof("found transaction to cross chain manager: %+v\n", transaction) + // todo parse event to struct CrossTransfer + crossTx := &CrossTransfer{} + sink := common.NewZeroCopySink(nil) + crossTx.Serialization(sink) + err1 := s.db.PutRetry(sink.Bytes()) + if err1 != nil { + log.Errorf("fetchLockDepositEvents - this.db.PutRetry error: %s", err) + } + log.Infof("fetchLockDepositEvent - height: %d", height) + } + } + return true } func (s *SyncService) MonitorChain() { - log.Printf("start scan block at height: %d\n", s.currentHeight) + log.Infof("start scan block at height: %d\n", s.currentHeight) fetchBlockTicker := time.NewTicker(time.Duration(s.cfg.ZilMonitorInterval) * time.Second) for { select { case <-fetchBlockTicker.C: txBlock, err := s.zilSdk.GetLatestTxBlock() if err != nil { - log.Printf("MonitorChain - cannot get node hight, err: %s\n", err.Error()) + log.Infof("MonitorChain - cannot get node hight, err: %s\n", err.Error()) continue } - log.Printf("current tx block height: %s\n", txBlock.Header.BlockNum) + log.Infof("current tx block height: %s\n", txBlock.Header.BlockNum) blockNumber, err2 := strconv.ParseUint(txBlock.Header.BlockNum, 10, 32) if err2 != nil { - log.Printf("MonitorChain - cannot parse block height, err: %s\n", err2.Error()) + log.Infof("MonitorChain - cannot parse block height, err: %s\n", err2.Error()) } if s.currentHeight >= blockNumber { - log.Printf("cuurent height is not changed, skip") + log.Infof("cuurent height is not changed, skip") continue } From 94be137c7cc31fe18944b791efc205055638f345 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 14 Jan 2021 03:55:45 +0800 Subject: [PATCH 006/107] feat: add dockerfile support --- Dockerfile | 11 +++++++++++ README.md | 8 ++++++++ service/zil2poly.go | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1f44a16 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.15 AS build +WORKDIR /app +RUN git clone https://github.com/Zilliqa/zilliqa-relayer.git && \ + cd zilliqa-relayer && \ + go build + +FROM ubuntu:18.04 +WORKDIR /app +COPY config.yaml config.yaml +COPY --from=build /app/zilliqa-relayer run +CMD ["/bin/bash"] \ No newline at end of file diff --git a/README.md b/README.md index bd347eb..3342bab 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,20 @@ Zilliqa Relayer is an important character of Poly cross-chain interactive protoc - [Golang](https://golang.org/doc/install) version 1.14 or later +### Build + ```shell git clone https://github.com/polynetwork/zil-relayer.git cd zil-relayer ./build.sh ``` +### Build Docker Image + +``` +docker build -t polynetwork/zilliqa-relayer -f Dockerfile ./ +``` + After building the source code successfully, you should see the executable program `zilliqa-relayer`. ## Other Resources diff --git a/service/zil2poly.go b/service/zil2poly.go index fa708d3..f31b97b 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -45,7 +45,7 @@ func (s *SyncService) handleBlockHeader(height uint64) bool { // the workflow is: user -> LockProxy on zilliqa -> Cross Chain Manager -> emit event // so here we need to filter out those transactions related to cross chain manager -// and parse the events, commit them to the polynetwork +// and parse the events, store them to local db, and commit them to the polynetwork func (s *SyncService) fetchLockDepositEvents(height uint64) bool { transactions, err := s.zilSdk.GetTxnBodiesForTxBlock(strconv.FormatUint(height, 10)) if err != nil { @@ -90,7 +90,7 @@ func (s *SyncService) MonitorChain() { log.Infof("MonitorChain - cannot parse block height, err: %s\n", err2.Error()) } if s.currentHeight >= blockNumber { - log.Infof("cuurent height is not changed, skip") + log.Infof("current height is not changed, skip") continue } From bbf073cbbbffae0a56466107fb0b62f9a0f8219b Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 14 Jan 2021 04:02:02 +0800 Subject: [PATCH 007/107] doc: update readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3342bab..2e607e9 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,16 @@ cd zil-relayer ./build.sh ``` +After building the source code successfully, you should see the executable program `zilliqa-relayer`. + ### Build Docker Image ``` docker build -t polynetwork/zilliqa-relayer -f Dockerfile ./ ``` -After building the source code successfully, you should see the executable program `zilliqa-relayer`. +This command will copy config.yaml to /app/config.yaml in the image. So you need to prepare config.yaml before running this command and you should start the zilliqa-relayer in container basing on the configuration in /app/config.yaml. + ## Other Resources From f814d4348c6fefc4e03a90ddfe11697d09b15ff0 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 14 Jan 2021 04:27:59 +0800 Subject: [PATCH 008/107] chore: fix dockerfile, add more scripts --- Dockerfile | 3 ++- build-docker.sh | 2 ++ run-docker.sh | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100755 build-docker.sh create mode 100755 run-docker.sh diff --git a/Dockerfile b/Dockerfile index 1f44a16..76a444a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,5 +7,6 @@ RUN git clone https://github.com/Zilliqa/zilliqa-relayer.git && \ FROM ubuntu:18.04 WORKDIR /app COPY config.yaml config.yaml -COPY --from=build /app/zilliqa-relayer run +COPY run.sh run.sh +COPY --from=build /app/zilliqa-relayer/zilliqa-relayer zilliqa-relayer CMD ["/bin/bash"] \ No newline at end of file diff --git a/build-docker.sh b/build-docker.sh new file mode 100755 index 0000000..da9dae9 --- /dev/null +++ b/build-docker.sh @@ -0,0 +1,2 @@ +#!/bin/sh +docker build -t polynetwork/zilliqa-relayer -f Dockerfile ./ \ No newline at end of file diff --git a/run-docker.sh b/run-docker.sh new file mode 100755 index 0000000..cd05573 --- /dev/null +++ b/run-docker.sh @@ -0,0 +1,2 @@ +#!/bin/sh +docker run polynetwork/zilliqa-relayer /app/run.sh \ No newline at end of file From 8d614a639a8047b16a27a324a5aa032ee5e6de6a Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 14 Jan 2021 04:48:17 +0800 Subject: [PATCH 009/107] feat: add polywallet file --- Dockerfile | 1 + README.md | 23 +++++++++++++++++++++++ config.yaml | 4 +++- wallet.dat | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 wallet.dat diff --git a/Dockerfile b/Dockerfile index 76a444a..8f820ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ RUN git clone https://github.com/Zilliqa/zilliqa-relayer.git && \ FROM ubuntu:18.04 WORKDIR /app COPY config.yaml config.yaml +COPY wallet.dat wallet.dat COPY run.sh run.sh COPY --from=build /app/zilliqa-relayer/zilliqa-relayer zilliqa-relayer CMD ["/bin/bash"] \ No newline at end of file diff --git a/README.md b/README.md index 2e607e9..696539b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # zilliqa-relayer +*This program is still under developing!* + Zilliqa Relayer is an important character of Poly cross-chain interactive protocol which is responsible for relaying cross-chain transaction from and to Zilliqa. ## Build From Source @@ -27,11 +29,32 @@ docker build -t polynetwork/zilliqa-relayer -f Dockerfile ./ This command will copy config.yaml to /app/config.yaml in the image. So you need to prepare config.yaml before running this command and you should start the zilliqa-relayer in container basing on the configuration in /app/config.yaml. +## Run Relayer +Before you can run the relayer you will need to create a wallet file of PolyNetwork by running(build Poly CLI first): + +```shell +./poly account add -d +``` + +After creation, you need to register it as a Relayer to Poly net and get consensus nodes approving your registeration. And then you can send transaction to Poly net and start relaying. + +Before running, you need feed the configuration file `config.yaml`. + +```yaml +api: https://dev-api.zilliqa.com +zil_start_height: 2291747 +zil_monitor_interval: 40 +corss_chain_manager_address: zil1y0mesa67hvsm92mupp9alqqevzst3ymspggj40 +poly_wallet_file: wallet.dat +poly_wallet_pwd: dummy +``` + ## Other Resources - [zilliqa cross chain manager proxy](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/ZilCrossChainManagerProxy.scilla) - [zilliqa cross chain manager](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/ZilCrossChainManager.scilla) - [zilliqa lock proxy](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/LockProxy.scilla) +- [polynetwork](https://github.com/polynetwork/poly) diff --git a/config.yaml b/config.yaml index e41d8e2..132337b 100644 --- a/config.yaml +++ b/config.yaml @@ -1,4 +1,6 @@ api: https://dev-api.zilliqa.com zil_start_height: 2291747 zil_monitor_interval: 40 -corss_chain_manager_address: zil1y0mesa67hvsm92mupp9alqqevzst3ymspggj40 \ No newline at end of file +corss_chain_manager_address: zil1y0mesa67hvsm92mupp9alqqevzst3ymspggj40 +poly_wallet_file: wallet.dat +poly_wallet_pwd: dummy \ No newline at end of file diff --git a/wallet.dat b/wallet.dat new file mode 100644 index 0000000..1646009 --- /dev/null +++ b/wallet.dat @@ -0,0 +1 @@ +{"name":"MyWallet","version":"1.1","scrypt":{"p":8,"n":16384,"r":8,"dkLen":64},"accounts":[{"address":"AVEHisrXBo5GUGU7HVpCWp59eyjGEyDRrT","enc-alg":"aes-256-gcm","key":"FO/fRk6Olt2598U+aqcwLGB5iMZd7346r87kjIAhMLCh8z1+JqWrZpLYf20ZP8CK","algorithm":"ECDSA","salt":"0xPZtgwpes7kEoXn9VO/gQ==","parameters":{"curve":""},"label":"","publicKey":"12050373c6373bfd436992b4de52a8bb8ef544a50fd24dd2ebb99d6acd1f52ac3d4bb8","signatureScheme":"SHA256withECDSA","isDefault":true,"lock":false}]} \ No newline at end of file From 90abef46de862de08d330f2345c9ba9cbd147ad8 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Fri, 15 Jan 2021 15:25:26 +0800 Subject: [PATCH 010/107] feat: parse cross chain event --- config.yaml | 6 ++--- go.mod | 2 +- go.sum | 48 ++++++++++++++++++++++++++++++++++++++++ service/zil2poly.go | 53 +++++++++++++++++++++++++++++++++++---------- 4 files changed, 93 insertions(+), 16 deletions(-) diff --git a/config.yaml b/config.yaml index 132337b..859d4a2 100644 --- a/config.yaml +++ b/config.yaml @@ -1,6 +1,6 @@ -api: https://dev-api.zilliqa.com -zil_start_height: 2291747 +api: https://polynetworkcc3dcb2-5-api.dev.z7a.xyz +zil_start_height: 38 zil_monitor_interval: 40 -corss_chain_manager_address: zil1y0mesa67hvsm92mupp9alqqevzst3ymspggj40 +corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f poly_wallet_file: wallet.dat poly_wallet_pwd: dummy \ No newline at end of file diff --git a/go.mod b/go.mod index 66292ca..9b4257d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.0 + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43 github.com/boltdb/bolt v1.3.1 github.com/polynetwork/poly v0.0.0-20200715030435-4f1d1a0adb44 github.com/polynetwork/poly-go-sdk v0.0.0-20200817120957-365691ad3493 diff --git a/go.sum b/go.sum index e688149..848c4aa 100644 --- a/go.sum +++ b/go.sum @@ -50,6 +50,8 @@ github.com/Workiva/go-datastructures v1.0.52 h1:PLSK6pwn8mYdaoaCZEMsXBpBotr4HHn9 github.com/Workiva/go-datastructures v1.0.52/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA= github.com/Zilliqa/gozilliqa-sdk v1.2.0 h1:pxINq2woI80BQkMb8dnIVsHw0pk6AkEnZ7DNE94bDMo= github.com/Zilliqa/gozilliqa-sdk v1.2.0/go.mod h1:eSYp2T6f0apnuW8TzhV3f6Aff2SE8Dwio++U4ha4yEM= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43 h1:m90pmiBsPC1B8CFLWMU6EMfqtVt6lZgeCAah7yuWvJA= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -147,8 +149,10 @@ 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= @@ -167,6 +171,8 @@ github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHj 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/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= @@ -179,6 +185,8 @@ github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVB 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 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= 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= @@ -236,9 +244,13 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W 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= @@ -248,6 +260,7 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw 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/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/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -308,6 +321,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO 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/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= @@ -404,6 +419,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/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= @@ -414,9 +430,13 @@ github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c/go.mod h1 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/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/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 h1:UQDN12BzdWhXQL0t2QcRixHqAIG+JKNvQ20DhrIODtU= github.com/ontio/go-bip32 v0.0.0-20190520025953-d3cea6894a2b/go.mod h1:J0eVc7BEMmVVXbGv9PHoxjRSEwOwLr0qfzPk8Rdl5iw= github.com/ontio/ontology v1.11.0 h1:0T/hxFDHQqRcs1+yEdgaym5YIvGx5yebOsHYdKVWgHI= @@ -502,6 +522,8 @@ github.com/scylladb/go-set v1.0.2/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQw 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/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= @@ -555,6 +577,8 @@ 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.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= @@ -626,6 +650,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= @@ -639,9 +664,11 @@ golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHl 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-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +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= @@ -669,8 +696,12 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 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/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/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -700,9 +731,12 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/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-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-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -711,10 +745,16 @@ golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7w 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/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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/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= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -741,10 +781,13 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn 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-20191112195655-aa38f8e97acc/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/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/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= @@ -794,6 +837,8 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE 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= @@ -808,6 +853,7 @@ gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7 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/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= @@ -819,6 +865,8 @@ 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= 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= diff --git a/service/zil2poly.go b/service/zil2poly.go index f31b97b..02e1427 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -1,9 +1,12 @@ package service import ( + "encoding/hex" "github.com/Zilliqa/gozilliqa-sdk/bech32" + "github.com/Zilliqa/gozilliqa-sdk/util" "github.com/polynetwork/poly/common" log "github.com/sirupsen/logrus" + "math/big" "strconv" "time" ) @@ -43,6 +46,13 @@ func (s *SyncService) handleBlockHeader(height uint64) bool { return true } +func EncodeBigInt(b *big.Int) string { + if b.Uint64() == 0 { + return "00" + } + return hex.EncodeToString(b.Bytes()) +} + // the workflow is: user -> LockProxy on zilliqa -> Cross Chain Manager -> emit event // so here we need to filter out those transactions related to cross chain manager // and parse the events, store them to local db, and commit them to the polynetwork @@ -54,19 +64,38 @@ func (s *SyncService) fetchLockDepositEvents(height uint64) bool { } for _, transaction := range transactions { - toAddr, _ := bech32.ToBech32Address(transaction.ToAddr) - log.Infof("to address: %s\n", toAddr) - if toAddr == s.corssChainManagerAddress { - log.Infof("found transaction to cross chain manager: %+v\n", transaction) - // todo parse event to struct CrossTransfer - crossTx := &CrossTransfer{} - sink := common.NewZeroCopySink(nil) - crossTx.Serialization(sink) - err1 := s.db.PutRetry(sink.Bytes()) - if err1 != nil { - log.Errorf("fetchLockDepositEvents - this.db.PutRetry error: %s", err) + events := transaction.Receipt.EventLogs + for _, event := range events { + toAddr, _ := bech32.ToBech32Address(event.Address) + log.Infof("to address: %s\n", toAddr) + if toAddr == s.corssChainManagerAddress { + log.Infof("found event on cross chain manager: %+v\n", event) + // todo parse event to struct CrossTransfer + crossTx := &CrossTransfer{} + for _, param := range event.Params { + switch param.VName { + case "txId": + index := big.NewInt(0) + index.SetBytes(util.DecodeHex(param.Value.(string))) + crossTx.txIndex = EncodeBigInt(index) + case "toChainId": + toChainId,_ := strconv.ParseUint(param.Value.(string),10,32) + crossTx.toChain = uint32(toChainId) + case "rawData": + crossTx.value = []byte(param.Value.(string)) + } + } + crossTx.height = height + crossTx.txId = util.DecodeHex(transaction.ID) + log.Infof("parsed cross tx is: %+v\n",crossTx) + sink := common.NewZeroCopySink(nil) + crossTx.Serialization(sink) + err1 := s.db.PutRetry(sink.Bytes()) + if err1 != nil { + log.Errorf("fetchLockDepositEvents - this.db.PutRetry error: %s", err) + } + log.Infof("fetchLockDepositEvent - height: %d", height) } - log.Infof("fetchLockDepositEvent - height: %d", height) } } From f3f9b1d309dadc49561a33386af270877bef333b Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Fri, 15 Jan 2021 17:39:57 +0800 Subject: [PATCH 011/107] chore: introduce MonitorDeposit for zil manager, adjust config hierarchy --- cmd/run.go | 13 +++++++++---- config.yaml | 15 +++++++++------ config/config.go | 8 ++++++-- db/db.go | 27 +++++++++++++++++++++++++++ service/sync_service.go | 16 ++++++++-------- service/zil2poly.go | 41 +++++++++++++++++++++++++---------------- tools/utils.go | 13 +++++++++++++ 7 files changed, 97 insertions(+), 36 deletions(-) create mode 100644 tools/utils.go diff --git a/cmd/run.go b/cmd/run.go index c165c8c..bba85eb 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -56,12 +56,17 @@ var runCmd = &cobra.Command{ Short: "Run zilliqa relayer", Long: `Run zilliqa relayer`, Run: func(cmd *cobra.Command, args []string) { + zilConfigMap := viper.GetStringMap("zil_config") + api := zilConfigMap["zil_api"].(string) + zilConfig := &config.ZILConfig{ZilApiEndpoint: api, + ZilStartHeight: uint32(zilConfigMap["zil_start_height"].(int)), + ZilMonitorInterval: uint32(zilConfigMap["zil_monitor_interval"].(int)), + SideChainId: uint64(zilConfigMap["side_chain_id"].(int)), + CrossChainManagerContract: zilConfigMap["corss_chain_manager_address"].(string), + } cfg := &config.Config{ - ZilApiEndpoint: viper.GetString("api"), - ZilStartHeight: viper.GetUint32("zil_start_height"), - ZilMonitorInterval: viper.GetUint32("zil_monitor_interval"), - CrossChainManagerContract: viper.GetString("corss_chain_manager_address"), + ZilConfig: zilConfig, } log.Infof("config file: %+v\n", cfg) diff --git a/config.yaml b/config.yaml index 859d4a2..81ff659 100644 --- a/config.yaml +++ b/config.yaml @@ -1,6 +1,9 @@ -api: https://polynetworkcc3dcb2-5-api.dev.z7a.xyz -zil_start_height: 38 -zil_monitor_interval: 40 -corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f -poly_wallet_file: wallet.dat -poly_wallet_pwd: dummy \ No newline at end of file +zil_config: + zil_api: https://polynetworkcc3dcb2-5-api.dev.z7a.xyz + zil_start_height: 38 + zil_monitor_interval: 40 + corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f + side_chain_id: 1 +poly_config: + poly_wallet_file: wallet.dat + poly_wallet_pwd: dummy \ No newline at end of file diff --git a/config/config.go b/config/config.go index 6cb38d1..3e5f9aa 100644 --- a/config/config.go +++ b/config/config.go @@ -1,10 +1,14 @@ package config type Config struct { - Path string + ZilConfig *ZILConfig + Path string +} - ZilMonitorInterval uint32 +type ZILConfig struct { ZilApiEndpoint string + ZilMonitorInterval uint32 ZilStartHeight uint32 + SideChainId uint64 CrossChainManagerContract string } diff --git a/db/db.go b/db/db.go index bf2e63d..98c7e90 100644 --- a/db/db.go +++ b/db/db.go @@ -1,12 +1,15 @@ package db import ( + "fmt" "github.com/boltdb/bolt" "path" "strings" "sync" ) +const MAX_NUM = 1000 + type BoltDB struct { rwLock *sync.RWMutex db *bolt.DB @@ -72,3 +75,27 @@ func (w *BoltDB) PutRetry(k []byte) error { return nil }) } + +func (w *BoltDB) GetAllRetry() ([][]byte, error) { + w.rwLock.Lock() + defer w.rwLock.Unlock() + + retryList := make([][]byte, 0) + err := w.db.Update(func(tx *bolt.Tx) error { + bw := tx.Bucket(BKTRetry) + bw.ForEach(func(k, _ []byte) error { + _k := make([]byte, len(k)) + copy(_k, k) + retryList = append(retryList, _k) + if len(retryList) >= MAX_NUM { + return fmt.Errorf("max num") + } + return nil + }) + return nil + }) + if err != nil { + return nil, err + } + return retryList, nil +} diff --git a/service/sync_service.go b/service/sync_service.go index 050038a..bcb02f1 100644 --- a/service/sync_service.go +++ b/service/sync_service.go @@ -13,11 +13,10 @@ import ( ) type SyncService struct { - relayAccount *poly.Account - relaySdk *poly.PolySdk - relaySyncHeight uint32 - zilAccount *account.Account - + polySigner *poly.Account + polySdk *poly.PolySdk + relaySyncHeight uint32 + zilAccount *account.Account currentHeight uint64 zilSdk *provider.Provider corssChainManagerAddress string @@ -38,14 +37,15 @@ func NewSyncService(cfg *config.Config) *SyncService { return &SyncService{ db: boltDB, cfg: cfg, - zilSdk: provider.NewProvider(cfg.ZilApiEndpoint), - currentHeight: uint64(cfg.ZilStartHeight), - corssChainManagerAddress: cfg.CrossChainManagerContract, + zilSdk: provider.NewProvider(cfg.ZilConfig.ZilApiEndpoint), + currentHeight: uint64(cfg.ZilConfig.ZilStartHeight), + corssChainManagerAddress: cfg.ZilConfig.CrossChainManagerContract, } } func (s *SyncService) Run() { go s.MonitorChain() + go s.MonitorDeposit() waitToExit() } diff --git a/service/zil2poly.go b/service/zil2poly.go index 02e1427..13374aa 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -1,10 +1,10 @@ package service import ( - "encoding/hex" "github.com/Zilliqa/gozilliqa-sdk/bech32" "github.com/Zilliqa/gozilliqa-sdk/util" "github.com/polynetwork/poly/common" + "github.com/polynetwork/zilliqa-relayer/tools" log "github.com/sirupsen/logrus" "math/big" "strconv" @@ -46,13 +46,6 @@ func (s *SyncService) handleBlockHeader(height uint64) bool { return true } -func EncodeBigInt(b *big.Int) string { - if b.Uint64() == 0 { - return "00" - } - return hex.EncodeToString(b.Bytes()) -} - // the workflow is: user -> LockProxy on zilliqa -> Cross Chain Manager -> emit event // so here we need to filter out those transactions related to cross chain manager // and parse the events, store them to local db, and commit them to the polynetwork @@ -77,9 +70,9 @@ func (s *SyncService) fetchLockDepositEvents(height uint64) bool { case "txId": index := big.NewInt(0) index.SetBytes(util.DecodeHex(param.Value.(string))) - crossTx.txIndex = EncodeBigInt(index) + crossTx.txIndex = tools.EncodeBigInt(index) case "toChainId": - toChainId,_ := strconv.ParseUint(param.Value.(string),10,32) + toChainId, _ := strconv.ParseUint(param.Value.(string), 10, 32) crossTx.toChain = uint32(toChainId) case "rawData": crossTx.value = []byte(param.Value.(string)) @@ -87,7 +80,7 @@ func (s *SyncService) fetchLockDepositEvents(height uint64) bool { } crossTx.height = height crossTx.txId = util.DecodeHex(transaction.ID) - log.Infof("parsed cross tx is: %+v\n",crossTx) + log.Infof("parsed cross tx is: %+v\n", crossTx) sink := common.NewZeroCopySink(nil) crossTx.Serialization(sink) err1 := s.db.PutRetry(sink.Bytes()) @@ -103,8 +96,8 @@ func (s *SyncService) fetchLockDepositEvents(height uint64) bool { } func (s *SyncService) MonitorChain() { - log.Infof("start scan block at height: %d\n", s.currentHeight) - fetchBlockTicker := time.NewTicker(time.Duration(s.cfg.ZilMonitorInterval) * time.Second) + log.Infof("MonitorChain - start scan block at height: %d\n", s.currentHeight) + fetchBlockTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) for { select { case <-fetchBlockTicker.C: @@ -113,13 +106,13 @@ func (s *SyncService) MonitorChain() { log.Infof("MonitorChain - cannot get node hight, err: %s\n", err.Error()) continue } - log.Infof("current tx block height: %s\n", txBlock.Header.BlockNum) + log.Infof("MonitorChain - current tx block height: %s\n", txBlock.Header.BlockNum) blockNumber, err2 := strconv.ParseUint(txBlock.Header.BlockNum, 10, 32) if err2 != nil { log.Infof("MonitorChain - cannot parse block height, err: %s\n", err2.Error()) } if s.currentHeight >= blockNumber { - log.Infof("current height is not changed, skip") + log.Infof("MonitorChain - current height is not changed, skip") continue } @@ -130,8 +123,24 @@ func (s *SyncService) MonitorChain() { case <-s.exitChan: return - } + } +} +func (s *SyncService) MonitorDeposit() { + log.Infof("MonitorDeposit - start monitor deposit\n") + monitorTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) + for { + select { + case <-monitorTicker.C: + txBlock, err := s.zilSdk.GetLatestTxBlock() + if err != nil { + log.Infof("MonitorDeposit - cannot get node hight, err: %s\n", err.Error()) + continue + } + log.Infof("MonitorDeposit - current tx block height: %s\n", txBlock.Header.BlockNum) + case <-s.exitChan: + return + } } } diff --git a/tools/utils.go b/tools/utils.go new file mode 100644 index 0000000..95210b1 --- /dev/null +++ b/tools/utils.go @@ -0,0 +1,13 @@ +package tools + +import ( + "encoding/hex" + "math/big" +) + +func EncodeBigInt(b *big.Int) string { + if b.Uint64() == 0 { + return "00" + } + return hex.EncodeToString(b.Bytes()) +} From 31586f799b97c4659f988144474ccb45c925cdf1 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Fri, 15 Jan 2021 17:44:37 +0800 Subject: [PATCH 012/107] doc: update readme --- README.md | 17 +++++++++++------ config.yaml | 4 +++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 696539b..77bb6f0 100644 --- a/README.md +++ b/README.md @@ -41,12 +41,17 @@ After creation, you need to register it as a Relayer to Poly net and get consens Before running, you need feed the configuration file `config.yaml`. ```yaml -api: https://dev-api.zilliqa.com -zil_start_height: 2291747 -zil_monitor_interval: 40 -corss_chain_manager_address: zil1y0mesa67hvsm92mupp9alqqevzst3ymspggj40 -poly_wallet_file: wallet.dat -poly_wallet_pwd: dummy +zil_config: + zil_api: https://polynetworkcc3dcb2-5-api.dev.z7a.xyz + zil_start_height: 38 + zil_monitor_interval: 40 + corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f + side_chain_id: 1 +poly_config: + poly_wallet_file: wallet.dat + poly_wallet_pwd: dummy + entrance_contract_address: 0300000000000000000000000000000000000000 + rest_url: http://beta1.poly.network ``` ## Other Resources diff --git a/config.yaml b/config.yaml index 81ff659..9d3a807 100644 --- a/config.yaml +++ b/config.yaml @@ -6,4 +6,6 @@ zil_config: side_chain_id: 1 poly_config: poly_wallet_file: wallet.dat - poly_wallet_pwd: dummy \ No newline at end of file + poly_wallet_pwd: dummy + entrance_contract_address: 0300000000000000000000000000000000000000 + rest_url: http://beta1.poly.network \ No newline at end of file From accbbffa46207b38a8e5a008ee6e4458646c7d07 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Sat, 16 Jan 2021 02:08:53 +0800 Subject: [PATCH 013/107] feat: support poly config --- cmd/run.go | 20 ++++++++++++++++---- config.yaml | 2 +- config/config.go | 12 ++++++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index bba85eb..3d52fd6 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -1,6 +1,7 @@ package cmd import ( + "encoding/json" "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/service" log "github.com/sirupsen/logrus" @@ -57,19 +58,30 @@ var runCmd = &cobra.Command{ Long: `Run zilliqa relayer`, Run: func(cmd *cobra.Command, args []string) { zilConfigMap := viper.GetStringMap("zil_config") - api := zilConfigMap["zil_api"].(string) - zilConfig := &config.ZILConfig{ZilApiEndpoint: api, + zilConfig := &config.ZILConfig{ + ZilApiEndpoint: zilConfigMap["zil_api"].(string), ZilStartHeight: uint32(zilConfigMap["zil_start_height"].(int)), ZilMonitorInterval: uint32(zilConfigMap["zil_monitor_interval"].(int)), SideChainId: uint64(zilConfigMap["side_chain_id"].(int)), CrossChainManagerContract: zilConfigMap["corss_chain_manager_address"].(string), } + polyConfigMap := viper.GetStringMap("poly_config") + polyConfig := &config.POLYConfig{ + PolyWalletFile: polyConfigMap["poly_wallet_file"].(string), + PolyWalletPassword: polyConfigMap["poly_wallet_pwd"].(string), + EntranceContractAddress: polyConfigMap["entrance_contract_address"].(string), + RestUrl: polyConfigMap["rest_url"].(string), + } + cfg := &config.Config{ - ZilConfig: zilConfig, + ZilConfig: zilConfig, + PolyConfig: polyConfig, } - log.Infof("config file: %+v\n", cfg) + // todo delete it + cfgStr,_ := json.Marshal(cfg) + log.Infof("config file: %s\n", cfgStr) syncService := service.NewSyncService(cfg) syncService.Run() diff --git a/config.yaml b/config.yaml index 9d3a807..85c40a1 100644 --- a/config.yaml +++ b/config.yaml @@ -7,5 +7,5 @@ zil_config: poly_config: poly_wallet_file: wallet.dat poly_wallet_pwd: dummy - entrance_contract_address: 0300000000000000000000000000000000000000 + entrance_contract_address: "0300000000000000000000000000000000000000" rest_url: http://beta1.poly.network \ No newline at end of file diff --git a/config/config.go b/config/config.go index 3e5f9aa..71208e4 100644 --- a/config/config.go +++ b/config/config.go @@ -1,8 +1,9 @@ package config type Config struct { - ZilConfig *ZILConfig - Path string + ZilConfig *ZILConfig + PolyConfig *POLYConfig + Path string } type ZILConfig struct { @@ -12,3 +13,10 @@ type ZILConfig struct { SideChainId uint64 CrossChainManagerContract string } + +type POLYConfig struct { + PolyWalletFile string + PolyWalletPassword string + EntranceContractAddress string + RestUrl string +} From 67f2d6a435df71ac81643c5f71d69df67605119c Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Mon, 18 Jan 2021 11:40:36 +0800 Subject: [PATCH 014/107] chore: rename sync service name, divide it into two managers(zilliqasyncmanager and polysyncmanager) --- cmd/run.go | 4 ++-- service/poly2zil.go | 3 +++ service/sync_service.go | 16 +++++++++++---- service/zil2poly.go | 43 ++++++++++++++++++++--------------------- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 3d52fd6..716251f 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -80,10 +80,10 @@ var runCmd = &cobra.Command{ } // todo delete it - cfgStr,_ := json.Marshal(cfg) + cfgStr, _ := json.Marshal(cfg) log.Infof("config file: %s\n", cfgStr) - syncService := service.NewSyncService(cfg) + syncService := service.NewZilliqaSyncManager(cfg) syncService.Run() }, } diff --git a/service/poly2zil.go b/service/poly2zil.go index 6d43c33..93b717f 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -1 +1,4 @@ package service + +func (p *PolySyncManager) MonitorChain() { +} diff --git a/service/sync_service.go b/service/sync_service.go index bcb02f1..c45db48 100644 --- a/service/sync_service.go +++ b/service/sync_service.go @@ -12,7 +12,7 @@ import ( "syscall" ) -type SyncService struct { +type ZilliqaSyncManager struct { polySigner *poly.Account polySdk *poly.PolySdk relaySyncHeight uint32 @@ -25,7 +25,7 @@ type SyncService struct { exitChan chan int } -func NewSyncService(cfg *config.Config) *SyncService { +func NewZilliqaSyncManager(cfg *config.Config) *ZilliqaSyncManager { if !checkIfExist(cfg.Path) { os.Mkdir(cfg.Path, os.ModePerm) } @@ -34,7 +34,7 @@ func NewSyncService(cfg *config.Config) *SyncService { log.Fatal("cannot init bolt db") } - return &SyncService{ + return &ZilliqaSyncManager{ db: boltDB, cfg: cfg, zilSdk: provider.NewProvider(cfg.ZilConfig.ZilApiEndpoint), @@ -43,12 +43,20 @@ func NewSyncService(cfg *config.Config) *SyncService { } } -func (s *SyncService) Run() { +func (s *ZilliqaSyncManager) Run() { go s.MonitorChain() go s.MonitorDeposit() waitToExit() } +type PolySyncManager struct { + cfg *config.Config +} + +func (p *PolySyncManager) Run() { + waitToExit() +} + func checkIfExist(dir string) bool { _, err := os.Stat(dir) if err != nil && !os.IsExist(err) { diff --git a/service/zil2poly.go b/service/zil2poly.go index 13374aa..b80d23b 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -27,21 +27,21 @@ func (this *CrossTransfer) Serialization(sink *common.ZeroCopySink) { sink.WriteUint64(this.height) } -func (s *SyncService) handleNewBlock(height uint64) bool { - log.Infof("handle new block: %d\n", height) +func (s *ZilliqaSyncManager) handleNewBlock(height uint64) bool { + log.Infof("ZilliqaSyncManager handle new block: %d\n", height) ret := s.handleBlockHeader(height) if !ret { - log.Infof("handleNewBlock - handleBlockHeader on height :%d failed\n", height) + log.Infof("ZilliqaSyncManager handleNewBlock - handleBlockHeader on height :%d failed\n", height) return false } ret = s.fetchLockDepositEvents(height) if !ret { - log.Infof("handleNewBlock - fetchLockDepositEvents on height :%d failed\n", height) + log.Infof("ZilliqaSyncManager handleNewBlock - fetchLockDepositEvents on height :%d failed\n", height) } return true } -func (s *SyncService) handleBlockHeader(height uint64) bool { +func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { // todo return true } @@ -49,10 +49,10 @@ func (s *SyncService) handleBlockHeader(height uint64) bool { // the workflow is: user -> LockProxy on zilliqa -> Cross Chain Manager -> emit event // so here we need to filter out those transactions related to cross chain manager // and parse the events, store them to local db, and commit them to the polynetwork -func (s *SyncService) fetchLockDepositEvents(height uint64) bool { +func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { transactions, err := s.zilSdk.GetTxnBodiesForTxBlock(strconv.FormatUint(height, 10)) if err != nil { - log.Infof("get transactions for tx block %d failed: %s\n", height, err.Error()) + log.Infof("ZilliqaSyncManager get transactions for tx block %d failed: %s\n", height, err.Error()) return false } @@ -60,9 +60,8 @@ func (s *SyncService) fetchLockDepositEvents(height uint64) bool { events := transaction.Receipt.EventLogs for _, event := range events { toAddr, _ := bech32.ToBech32Address(event.Address) - log.Infof("to address: %s\n", toAddr) if toAddr == s.corssChainManagerAddress { - log.Infof("found event on cross chain manager: %+v\n", event) + log.Infof("ZilliqaSyncManager found event on cross chain manager: %+v\n", event) // todo parse event to struct CrossTransfer crossTx := &CrossTransfer{} for _, param := range event.Params { @@ -80,14 +79,14 @@ func (s *SyncService) fetchLockDepositEvents(height uint64) bool { } crossTx.height = height crossTx.txId = util.DecodeHex(transaction.ID) - log.Infof("parsed cross tx is: %+v\n", crossTx) + log.Infof("ZilliqaSyncManager parsed cross tx is: %+v\n", crossTx) sink := common.NewZeroCopySink(nil) crossTx.Serialization(sink) err1 := s.db.PutRetry(sink.Bytes()) if err1 != nil { - log.Errorf("fetchLockDepositEvents - this.db.PutRetry error: %s", err) + log.Errorf("ZilliqaSyncManager fetchLockDepositEvents - this.db.PutRetry error: %s", err) } - log.Infof("fetchLockDepositEvent - height: %d", height) + log.Infof("ZilliqaSyncManager fetchLockDepositEvent - height: %d", height) } } } @@ -95,24 +94,24 @@ func (s *SyncService) fetchLockDepositEvents(height uint64) bool { return true } -func (s *SyncService) MonitorChain() { - log.Infof("MonitorChain - start scan block at height: %d\n", s.currentHeight) +func (s *ZilliqaSyncManager) MonitorChain() { + log.Infof("ZilliqaSyncManager MonitorChain - start scan block at height: %d\n", s.currentHeight) fetchBlockTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) for { select { case <-fetchBlockTicker.C: txBlock, err := s.zilSdk.GetLatestTxBlock() if err != nil { - log.Infof("MonitorChain - cannot get node hight, err: %s\n", err.Error()) + log.Infof("ZilliqaSyncManager MonitorChain - cannot get node hight, err: %s\n", err.Error()) continue } - log.Infof("MonitorChain - current tx block height: %s\n", txBlock.Header.BlockNum) + log.Infof("ZilliqaSyncManager MonitorChain - current tx block height: %s\n", txBlock.Header.BlockNum) blockNumber, err2 := strconv.ParseUint(txBlock.Header.BlockNum, 10, 32) if err2 != nil { - log.Infof("MonitorChain - cannot parse block height, err: %s\n", err2.Error()) + log.Infof("ZilliqaSyncManager MonitorChain - cannot parse block height, err: %s\n", err2.Error()) } if s.currentHeight >= blockNumber { - log.Infof("MonitorChain - current height is not changed, skip") + log.Infof("ZilliqaSyncManager MonitorChain - current height is not changed, skip") continue } @@ -127,18 +126,18 @@ func (s *SyncService) MonitorChain() { } } -func (s *SyncService) MonitorDeposit() { - log.Infof("MonitorDeposit - start monitor deposit\n") +func (s *ZilliqaSyncManager) MonitorDeposit() { + log.Infof("ZilliqaSyncManager MonitorDeposit - start monitor deposit\n") monitorTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) for { select { case <-monitorTicker.C: txBlock, err := s.zilSdk.GetLatestTxBlock() if err != nil { - log.Infof("MonitorDeposit - cannot get node hight, err: %s\n", err.Error()) + log.Infof("ZilliqaSyncManager MonitorDeposit - cannot get node hight, err: %s\n", err.Error()) continue } - log.Infof("MonitorDeposit - current tx block height: %s\n", txBlock.Header.BlockNum) + log.Infof("ZilliqaSyncManager MonitorDeposit - current tx block height: %s\n", txBlock.Header.BlockNum) case <-s.exitChan: return } From 44c4d2d0f2fcdc02d53dec3021e57b31b8313ee0 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 19 Jan 2021 14:50:51 +0800 Subject: [PATCH 015/107] wip: struct Monitor poly chain --- cmd/run.go | 1 + config.yaml | 1 + config/config.go | 5 +++++ db/db.go | 19 ++++++++++++++-- service/poly2zil.go | 48 +++++++++++++++++++++++++++++++++++++++++ service/sync_service.go | 10 ++++++--- service/zil2poly.go | 6 +++--- 7 files changed, 82 insertions(+), 8 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 716251f..aaf13f0 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -70,6 +70,7 @@ var runCmd = &cobra.Command{ polyConfig := &config.POLYConfig{ PolyWalletFile: polyConfigMap["poly_wallet_file"].(string), PolyWalletPassword: polyConfigMap["poly_wallet_pwd"].(string), + PolyMonitorInterval: uint32(polyConfigMap["poly_monitor_interval"].(int)), EntranceContractAddress: polyConfigMap["entrance_contract_address"].(string), RestUrl: polyConfigMap["rest_url"].(string), } diff --git a/config.yaml b/config.yaml index 85c40a1..1795ec9 100644 --- a/config.yaml +++ b/config.yaml @@ -7,5 +7,6 @@ zil_config: poly_config: poly_wallet_file: wallet.dat poly_wallet_pwd: dummy + poly_monitor_interval: 40 entrance_contract_address: "0300000000000000000000000000000000000000" rest_url: http://beta1.poly.network \ No newline at end of file diff --git a/config/config.go b/config/config.go index 71208e4..6a237f9 100644 --- a/config/config.go +++ b/config/config.go @@ -1,5 +1,9 @@ package config +const ( + OntUsefulBlockNum = 1 +) + type Config struct { ZilConfig *ZILConfig PolyConfig *POLYConfig @@ -17,6 +21,7 @@ type ZILConfig struct { type POLYConfig struct { PolyWalletFile string PolyWalletPassword string + PolyMonitorInterval uint32 EntranceContractAddress string RestUrl string } diff --git a/db/db.go b/db/db.go index 98c7e90..6882594 100644 --- a/db/db.go +++ b/db/db.go @@ -1,6 +1,7 @@ package db import ( + "encoding/binary" "fmt" "github.com/boltdb/bolt" "path" @@ -17,8 +18,9 @@ type BoltDB struct { } var ( - BKTCheck = []byte("Check") - BKTRetry = []byte("Retry") + BKTCheck = []byte("Check") + BKTRetry = []byte("Retry") + BKTHeight = []byte("Height") ) func NewBoltDB(filePath string) (*BoltDB, error) { @@ -99,3 +101,16 @@ func (w *BoltDB) GetAllRetry() ([][]byte, error) { } return retryList, nil } + +func (w *BoltDB) UpdatePolyHeight(h uint32) error { + w.rwLock.Lock() + defer w.rwLock.Unlock() + + raw := make([]byte, 4) + binary.LittleEndian.PutUint32(raw, h) + + return w.db.Update(func(tx *bolt.Tx) error { + bkt := tx.Bucket(BKTHeight) + return bkt.Put([]byte("poly_height"), raw) + }) +} diff --git a/service/poly2zil.go b/service/poly2zil.go index 93b717f..946de1c 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -1,4 +1,52 @@ package service +import ( + "github.com/polynetwork/zilliqa-relayer/config" + log "github.com/sirupsen/logrus" + "time" +) + func (p *PolySyncManager) MonitorChain() { + log.Infof("PolySyncManager MonitorChain - start scan block at height: %d\n", p.currentHeight) + monitorTicker := time.NewTicker(time.Duration(p.cfg.PolyConfig.PolyMonitorInterval) * time.Second) + var blockHandleResult bool + for { + select { + case <-monitorTicker.C: + latestHeight, err := p.polySdk.GetCurrentBlockHeight() + if err != nil { + log.Errorf("PolySyncManager MonitorChain - cannot get node hight, err: %s\n", err.Error()) + continue + } + latestHeight-- + if latestHeight-p.currentHeight < config.OntUsefulBlockNum { + continue + } + log.Infof("PolySyncManager MonitorChain - poly chain current height: %d", latestHeight) + blockHandleResult = true + for p.currentHeight <= latestHeight-config.OntUsefulBlockNum { + blockHandleResult = p.handleDepositEvents(p.currentHeight) + if blockHandleResult == false { + break + } + p.currentHeight++ + } + if err = p.db.UpdatePolyHeight(p.currentHeight - 1); err != nil { + log.Errorf("MonitorChain - failed to save height of poly: %v", err) + } + case <-p.exitChan: + return + + } + } +} + +func (p *PolySyncManager) handleDepositEvents(height uint32) bool { + // todo + return true +} + +func (p *PolySyncManager) findLatestHeight() uint32 { + // todo get substate of cross chain manager + return 0 } diff --git a/service/sync_service.go b/service/sync_service.go index c45db48..4806f00 100644 --- a/service/sync_service.go +++ b/service/sync_service.go @@ -19,7 +19,7 @@ type ZilliqaSyncManager struct { zilAccount *account.Account currentHeight uint64 zilSdk *provider.Provider - corssChainManagerAddress string + crossChainManagerAddress string cfg *config.Config db *db.BoltDB exitChan chan int @@ -39,7 +39,7 @@ func NewZilliqaSyncManager(cfg *config.Config) *ZilliqaSyncManager { cfg: cfg, zilSdk: provider.NewProvider(cfg.ZilConfig.ZilApiEndpoint), currentHeight: uint64(cfg.ZilConfig.ZilStartHeight), - corssChainManagerAddress: cfg.ZilConfig.CrossChainManagerContract, + crossChainManagerAddress: cfg.ZilConfig.CrossChainManagerContract, } } @@ -50,7 +50,11 @@ func (s *ZilliqaSyncManager) Run() { } type PolySyncManager struct { - cfg *config.Config + currentHeight uint32 + polySdk *poly.PolySdk + exitChan chan int + cfg *config.Config + db *db.BoltDB } func (p *PolySyncManager) Run() { diff --git a/service/zil2poly.go b/service/zil2poly.go index b80d23b..2e54e51 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -60,7 +60,7 @@ func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { events := transaction.Receipt.EventLogs for _, event := range events { toAddr, _ := bech32.ToBech32Address(event.Address) - if toAddr == s.corssChainManagerAddress { + if toAddr == s.crossChainManagerAddress { log.Infof("ZilliqaSyncManager found event on cross chain manager: %+v\n", event) // todo parse event to struct CrossTransfer crossTx := &CrossTransfer{} @@ -102,13 +102,13 @@ func (s *ZilliqaSyncManager) MonitorChain() { case <-fetchBlockTicker.C: txBlock, err := s.zilSdk.GetLatestTxBlock() if err != nil { - log.Infof("ZilliqaSyncManager MonitorChain - cannot get node hight, err: %s\n", err.Error()) + log.Errorf("ZilliqaSyncManager MonitorChain - cannot get node hight, err: %s\n", err.Error()) continue } log.Infof("ZilliqaSyncManager MonitorChain - current tx block height: %s\n", txBlock.Header.BlockNum) blockNumber, err2 := strconv.ParseUint(txBlock.Header.BlockNum, 10, 32) if err2 != nil { - log.Infof("ZilliqaSyncManager MonitorChain - cannot parse block height, err: %s\n", err2.Error()) + log.Errorf("ZilliqaSyncManager MonitorChain - cannot parse block height, err: %s\n", err2.Error()) } if s.currentHeight >= blockNumber { log.Infof("ZilliqaSyncManager MonitorChain - current height is not changed, skip") From 06882c169384c1fda4c63d1753279cc5ed223b2a Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 19 Jan 2021 18:09:19 +0800 Subject: [PATCH 016/107] feat: parse event from polynetwork --- config/config.go | 7 +- service/poly2zil.go | 176 ++++++++++++++++++++++++++++++++++++++- service/poly2zil_test.go | 24 ++++++ service/sync_service.go | 2 + tools/utils.go | 35 ++++++++ 5 files changed, 237 insertions(+), 7 deletions(-) create mode 100644 service/poly2zil_test.go diff --git a/config/config.go b/config/config.go index 6a237f9..8c65e61 100644 --- a/config/config.go +++ b/config/config.go @@ -5,9 +5,10 @@ const ( ) type Config struct { - ZilConfig *ZILConfig - PolyConfig *POLYConfig - Path string + ZilConfig *ZILConfig + PolyConfig *POLYConfig + Path string + TargetContracts []map[string]map[string][]uint64 } type ZILConfig struct { diff --git a/service/poly2zil.go b/service/poly2zil.go index 946de1c..7a34c08 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -1,8 +1,19 @@ package service import ( + "encoding/hex" + "encoding/json" + "github.com/Zilliqa/gozilliqa-sdk/bech32" + "github.com/Zilliqa/gozilliqa-sdk/util" + "github.com/ontio/ontology-crypto/signature" + "github.com/polynetwork/poly/common" + "github.com/polynetwork/poly/consensus/vbft/config" + polytypes "github.com/polynetwork/poly/core/types" + common2 "github.com/polynetwork/poly/native/service/cross_chain_manager/common" "github.com/polynetwork/zilliqa-relayer/config" + "github.com/polynetwork/zilliqa-relayer/tools" log "github.com/sirupsen/logrus" + "strconv" "time" ) @@ -32,7 +43,7 @@ func (p *PolySyncManager) MonitorChain() { p.currentHeight++ } if err = p.db.UpdatePolyHeight(p.currentHeight - 1); err != nil { - log.Errorf("MonitorChain - failed to save height of poly: %v", err) + log.Errorf("PolySyncManager MonitorChain - failed to save height of poly: %v", err) } case <-p.exitChan: return @@ -42,11 +53,168 @@ func (p *PolySyncManager) MonitorChain() { } func (p *PolySyncManager) handleDepositEvents(height uint32) bool { - // todo + lastEpoch := p.findLatestHeight() + hdr, err := p.polySdk.GetHeaderByHeight(height + 1) + if err != nil { + log.Errorf("PolySyncManager handleBlockHeader - GetNodeHeader on height :%d failed", height) + return false + } + isCurr := lastEpoch < height+1 + info := &vconfig.VbftBlockInfo{} + if err := json.Unmarshal(hdr.ConsensusPayload, info); err != nil { + log.Errorf("PolySyncManager failed to unmarshal ConsensusPayload for height %d: %v", height+1, err) + return false + } + isEpoch := hdr.NextBookkeeper != common.ADDRESS_EMPTY && info.NewChainConfig != nil + var ( + anchor *polytypes.Header + hp string + ) + if !isCurr { + anchor, _ = p.polySdk.GetHeaderByHeight(lastEpoch + 1) + proof, _ := p.polySdk.GetMerkleProof(height+1, lastEpoch+1) + hp = proof.AuditPath + } else if isEpoch { + anchor, _ = p.polySdk.GetHeaderByHeight(height + 2) + proof, _ := p.polySdk.GetMerkleProof(height+1, height+2) + hp = proof.AuditPath + } + cnt := 0 + events, err := p.polySdk.GetSmartContractEventByBlock(height) + for err != nil { + log.Errorf("PolySyncManager handleDepositEvents - get block event at height:%d error: %s", height, err.Error()) + return false + } + for _, event := range events { + for _, notify := range event.Notify { + if notify.ContractAddress == p.cfg.PolyConfig.EntranceContractAddress { + states := notify.States.([]interface{}) + method, _ := states[0].(string) + if method != "makeProof" { + continue + } + if uint64(states[2].(float64)) != p.cfg.ZilConfig.SideChainId { + continue + } + proof, err := p.polySdk.GetCrossStatesProof(hdr.Height-1, states[5].(string)) + if err != nil { + log.Errorf("handleDepositEvents - failed to get proof for key %s: %v", states[5].(string), err) + continue + } + auditpath, _ := hex.DecodeString(proof.AuditPath) + value, _, _, _ := tools.ParseAuditpath(auditpath) + param := &common2.ToMerkleValue{} + if err := param.Deserialization(common.NewZeroCopySource(value)); err != nil { + log.Errorf("handleDepositEvents - failed to deserialize MakeTxParam (value: %x, err: %v)", value, err) + continue + } + var isTarget bool + if len(p.cfg.TargetContracts) > 0 { + // todo assuming ToContractAddress is not bech32 + // handle error + toContractStr, _ := bech32.ToBech32Address(util.EncodeHex(param.MakeTxParam.ToContractAddress)) + for _, v := range p.cfg.TargetContracts { + toChainIdArr, ok := v[toContractStr] + if ok { + if len(toChainIdArr["inbound"]) == 0 { + isTarget = true + break + } + for _, id := range toChainIdArr["inbound"] { + if id == param.FromChainID { + isTarget = true + break + } + } + if isTarget { + break + } + } + } + if !isTarget { + continue + } + } + cnt++ + sender := p.selectSender() + log.Infof("sender %s is handling poly tx ( hash: %s, height: %d )", + sender.acc, event.TxHash, height) + // temporarily ignore the error for tx + sender.commitDepositEventsWithHeader(hdr, param, hp, anchor, event.TxHash, auditpath) + //if !sender.commitDepositEventsWithHeader(hdr, param, hp, anchor, event.TxHash, auditpath) { + // return false + //} + } + } + } + return true } +func (p *PolySyncManager) selectSender() *ZilSender { + return &ZilSender{} +} + +type ZilSender struct { + acc string +} + +func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) { + // verifyHeaderAndExecuteTx + var ( + sigs []byte + headerData []byte + ) + if anchorHeader != nil && headerProof != "" { + for _, sig := range anchorHeader.SigData { + temp := make([]byte, len(sig)) + copy(temp, sig) + newsig, _ := signature.ConvertToEthCompatible(temp) + sigs = append(sigs, newsig...) + } + } else { + for _, sig := range header.SigData { + temp := make([]byte, len(sig)) + copy(temp, sig) + newsig, _ := signature.ConvertToEthCompatible(temp) + sigs = append(sigs, newsig...) + } + } +} + +type EpochStartHeight struct { + CurEpochStartHeight string `json:"curEpochStartHeight"` +} + +type EpochStartHeightRep struct { + Id string `json:"id"` + JsonRpc string `json:"jsonrpc"` + Result EpochStartHeight `json:"result"` +} + func (p *PolySyncManager) findLatestHeight() uint32 { - // todo get substate of cross chain manager - return 0 + ccm, err := bech32.FromBech32Addr(p.cfg.ZilConfig.CrossChainManagerContract) + if err != nil { + log.Errorf("PolySyncManager FindLatestHeight - failed to convert cross chain manager contract address: %s\n", err.Error()) + return 0 + } + curEpochStartHeight, err1 := p.zilSdk.GetSmartContractSubState(ccm, "curEpochStartHeight", []interface{}{}) + if err1 != nil { + log.Errorf("PolySyncManager FindLatestHeight - faild to get current epoch start height: %s\n", err1.Error()) + return 0 + } + + var epochStartHeightRep EpochStartHeightRep + err3 := json.Unmarshal([]byte(curEpochStartHeight), &epochStartHeightRep) + if err3 != nil { + log.Errorf("PolySyncManager FindLatestHeight - faild to unmarshal current epoch start height: %s\n", err3.Error()) + return 0 + } + + height, err2 := strconv.ParseUint(epochStartHeightRep.Result.CurEpochStartHeight, 10, 32) + if err2 != nil { + log.Errorf("PolySyncManager FindLatestHeight - faild to parse epoch start height: %s\n", err2.Error()) + return 0 + } + return uint32(height) } diff --git a/service/poly2zil_test.go b/service/poly2zil_test.go new file mode 100644 index 0000000..1ec4700 --- /dev/null +++ b/service/poly2zil_test.go @@ -0,0 +1,24 @@ +package service + +import ( + "fmt" + "github.com/Zilliqa/gozilliqa-sdk/provider" + "github.com/polynetwork/zilliqa-relayer/config" + "testing" +) + +var p *PolySyncManager + +func init() { + zilSdk := provider.NewProvider("https://polynetworkcc3dcb2-5-api.dev.z7a.xyz") + p = &PolySyncManager{ + zilSdk: zilSdk, + cfg: &config.Config{ZilConfig: &config.ZILConfig{ + CrossChainManagerContract: "zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f", + }}, + } +} + +func TestPolySyncManager_FindLatestHeight(t *testing.T) { + fmt.Println(p.findLatestHeight()) +} diff --git a/service/sync_service.go b/service/sync_service.go index 4806f00..5fc1944 100644 --- a/service/sync_service.go +++ b/service/sync_service.go @@ -55,6 +55,8 @@ type PolySyncManager struct { exitChan chan int cfg *config.Config db *db.BoltDB + + zilSdk *provider.Provider } func (p *PolySyncManager) Run() { diff --git a/tools/utils.go b/tools/utils.go index 95210b1..0d2c5a8 100644 --- a/tools/utils.go +++ b/tools/utils.go @@ -2,6 +2,7 @@ package tools import ( "encoding/hex" + "github.com/polynetwork/poly/common" "math/big" ) @@ -11,3 +12,37 @@ func EncodeBigInt(b *big.Int) string { } return hex.EncodeToString(b.Bytes()) } + +func ParseAuditpath(path []byte) ([]byte, []byte, [][32]byte, error) { + source := common.NewZeroCopySource(path) + /* + l, eof := source.NextUint64() + if eof { + return nil, nil, nil, nil + } + */ + value, eof := source.NextVarBytes() + if eof { + return nil, nil, nil, nil + } + size := int((source.Size() - source.Pos()) / common.UINT256_SIZE) + pos := make([]byte, 0) + hashs := make([][32]byte, 0) + for i := 0; i < size; i++ { + f, eof := source.NextByte() + if eof { + return nil, nil, nil, nil + } + pos = append(pos, f) + + v, eof := source.NextHash() + if eof { + return nil, nil, nil, nil + } + var onehash [32]byte + copy(onehash[:], (v.ToArray())[0:32]) + hashs = append(hashs, onehash) + } + + return value, pos, hashs, nil +} From 47f6fdc43c720371766b4c2e9e2da6baf9a813df Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 20 Jan 2021 10:44:23 +0800 Subject: [PATCH 017/107] feat(PolySyncManager): check if from chain transaction exist in zilliqa contract --- go.mod | 2 ++ service/poly2zil.go | 45 ++++++++++++++++++++++++++++++++++++++-- service/poly2zil_test.go | 12 ++++++++++- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9b4257d..3d82c91 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,8 @@ go 1.15 require ( github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43 github.com/boltdb/bolt v1.3.1 + github.com/magiconair/properties v1.8.1 + github.com/ontio/ontology-crypto v1.0.9 github.com/polynetwork/poly v0.0.0-20200715030435-4f1d1a0adb44 github.com/polynetwork/poly-go-sdk v0.0.0-20200817120957-365691ad3493 github.com/sirupsen/logrus v1.7.0 diff --git a/service/poly2zil.go b/service/poly2zil.go index 7a34c08..6e118d7 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -162,8 +162,8 @@ type ZilSender struct { func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) { // verifyHeaderAndExecuteTx var ( - sigs []byte - headerData []byte + sigs []byte + //headerData []byte ) if anchorHeader != nil && headerProof != "" { for _, sig := range anchorHeader.SigData { @@ -192,6 +192,47 @@ type EpochStartHeightRep struct { Result EpochStartHeight `json:"result"` } +type FromChainTxExist struct { + FromChainTxExist map[string]interface{} `json:"fromChainTxExist"` +} + +type FromChainTxExistRsp struct { + Id string `json:"id"` + JsonRpc string `json:"jsonrpc"` + Result *FromChainTxExist `json:"result"` +} + +// ZilCrossChainManager.scilla +// check fromChainTxExist map +func (p *PolySyncManager) checkIfFromChainTxExist(fromChainId uint64, fromTx string) bool { + ccm, err := bech32.FromBech32Addr(p.cfg.ZilConfig.CrossChainManagerContract) + if err != nil { + log.Errorf("PolySyncManager checkIfFromChainTxExist - failed to convert cross chain manager contract address: %s\n", err.Error()) + return false + } + + state, err1 := p.zilSdk.GetSmartContractSubState(ccm, "fromChainTxExist", []interface{}{strconv.FormatUint(fromChainId, 10), fromTx}) + if err1 != nil { + log.Errorf("PolySyncManager checkIfFromChainTxExist - failed to get state of fromChainTxExist: %s\n", err1.Error()) + return false + } + + var fromChainTxExistRsp FromChainTxExistRsp + err2 := json.Unmarshal([]byte(state), &fromChainTxExistRsp) + if err2 != nil { + log.Errorf("PolySyncManager checkIfFromChainTxExist - failed to parse fromChainTxExistRsp: %s\n", err2.Error()) + return false + } + + if fromChainTxExistRsp.Result == nil { + return false + } else { + return true + } +} + +// ZilCrossChainManager.scilla +// curEpochStartHeight func (p *PolySyncManager) findLatestHeight() uint32 { ccm, err := bech32.FromBech32Addr(p.cfg.ZilConfig.CrossChainManagerContract) if err != nil { diff --git a/service/poly2zil_test.go b/service/poly2zil_test.go index 1ec4700..c524a50 100644 --- a/service/poly2zil_test.go +++ b/service/poly2zil_test.go @@ -3,6 +3,7 @@ package service import ( "fmt" "github.com/Zilliqa/gozilliqa-sdk/provider" + "github.com/magiconair/properties/assert" "github.com/polynetwork/zilliqa-relayer/config" "testing" ) @@ -14,7 +15,7 @@ func init() { p = &PolySyncManager{ zilSdk: zilSdk, cfg: &config.Config{ZilConfig: &config.ZILConfig{ - CrossChainManagerContract: "zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f", + CrossChainManagerContract: "zil1ur4vwcmcz3jqypksgq7qeju2sk5jrskzaadau5", }}, } } @@ -22,3 +23,12 @@ func init() { func TestPolySyncManager_FindLatestHeight(t *testing.T) { fmt.Println(p.findLatestHeight()) } + +func TestPolySyncManager_CheckIfFromChainTxExist(t *testing.T) { + exist := p.checkIfFromChainTxExist(3, "0x00ca93f8738111a063d8ab7221f47c70a4cade0ca4a2829df494cd4b5e231bd6") + assert.Equal(t, exist, true) + + exist = p.checkIfFromChainTxExist(3, "0x00ca93f8738111a063d8ab7221f47c70a4cade0ca4a2829df494cd4b5e231bd7") + assert.Equal(t, exist, false) + +} From d4ab90e322545c42cc6e9df4ae47ce3d4a9f5476 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 20 Jan 2021 11:47:38 +0800 Subject: [PATCH 018/107] chore: restruct directory for more friendly readability --- go.sum | 1 + service/common.go | 30 ++++++++++++++ service/poly2zil.go | 29 ++++++++++---- service/poly2zil_test.go | 14 +++++-- service/polymanager.go | 22 ++++++++++ .../{sync_service.go => zilliqamanager.go} | 40 +------------------ 6 files changed, 86 insertions(+), 50 deletions(-) create mode 100644 service/common.go create mode 100644 service/polymanager.go rename service/{sync_service.go => zilliqamanager.go} (64%) diff --git a/go.sum b/go.sum index 848c4aa..54c06a4 100644 --- a/go.sum +++ b/go.sum @@ -266,6 +266,7 @@ github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OI github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 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/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= diff --git a/service/common.go b/service/common.go new file mode 100644 index 0000000..4a2be76 --- /dev/null +++ b/service/common.go @@ -0,0 +1,30 @@ +package service + +import ( + log "github.com/sirupsen/logrus" + "os" + "os/signal" + "syscall" +) + +func checkIfExist(dir string) bool { + _, err := os.Stat(dir) + if err != nil && !os.IsExist(err) { + return false + } + return true +} + +func waitToExit() { + exit := make(chan bool, 0) + sc := make(chan os.Signal, 1) + signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) + go func() { + for sig := range sc { + log.Infof("Zilliqa Relayer received exit signal: %v.", sig.String()) + close(exit) + break + } + }() + <-exit +} diff --git a/service/poly2zil.go b/service/poly2zil.go index 6e118d7..048e534 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "encoding/json" "github.com/Zilliqa/gozilliqa-sdk/bech32" + "github.com/Zilliqa/gozilliqa-sdk/provider" "github.com/Zilliqa/gozilliqa-sdk/util" "github.com/ontio/ontology-crypto/signature" "github.com/polynetwork/poly/common" @@ -141,9 +142,6 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { sender.acc, event.TxHash, height) // temporarily ignore the error for tx sender.commitDepositEventsWithHeader(hdr, param, hp, anchor, event.TxHash, auditpath) - //if !sender.commitDepositEventsWithHeader(hdr, param, hp, anchor, event.TxHash, auditpath) { - // return false - //} } } } @@ -152,14 +150,17 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { } func (p *PolySyncManager) selectSender() *ZilSender { + // todo return &ZilSender{} } type ZilSender struct { - acc string + cfg *config.Config + zilSdk *provider.Provider + acc string } -func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) { +func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { // verifyHeaderAndExecuteTx var ( sigs []byte @@ -180,6 +181,18 @@ func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, sigs = append(sigs, newsig...) } } + + // todo ensure that TxHash is bytes of hash, not utf8 bytes + exist := sender.checkIfFromChainTxExist(param.FromChainID, util.EncodeHex(param.TxHash)) + if exist { + log.Infof("ZilSender commitDepositEventsWithHeader - already relayed to zil: (from_chain_id: %d, from_txhash: %x, param.TxHash: %x\n)", param.FromChainID, param.TxHash, param.MakeTxParam.TxHash) + return true + } + + // todo + + return true + } type EpochStartHeight struct { @@ -204,14 +217,14 @@ type FromChainTxExistRsp struct { // ZilCrossChainManager.scilla // check fromChainTxExist map -func (p *PolySyncManager) checkIfFromChainTxExist(fromChainId uint64, fromTx string) bool { - ccm, err := bech32.FromBech32Addr(p.cfg.ZilConfig.CrossChainManagerContract) +func (z *ZilSender) checkIfFromChainTxExist(fromChainId uint64, fromTx string) bool { + ccm, err := bech32.FromBech32Addr(z.cfg.ZilConfig.CrossChainManagerContract) if err != nil { log.Errorf("PolySyncManager checkIfFromChainTxExist - failed to convert cross chain manager contract address: %s\n", err.Error()) return false } - state, err1 := p.zilSdk.GetSmartContractSubState(ccm, "fromChainTxExist", []interface{}{strconv.FormatUint(fromChainId, 10), fromTx}) + state, err1 := z.zilSdk.GetSmartContractSubState(ccm, "fromChainTxExist", []interface{}{strconv.FormatUint(fromChainId, 10), fromTx}) if err1 != nil { log.Errorf("PolySyncManager checkIfFromChainTxExist - failed to get state of fromChainTxExist: %s\n", err1.Error()) return false diff --git a/service/poly2zil_test.go b/service/poly2zil_test.go index c524a50..b2d547a 100644 --- a/service/poly2zil_test.go +++ b/service/poly2zil_test.go @@ -9,6 +9,7 @@ import ( ) var p *PolySyncManager +var s *ZilSender func init() { zilSdk := provider.NewProvider("https://polynetworkcc3dcb2-5-api.dev.z7a.xyz") @@ -18,17 +19,24 @@ func init() { CrossChainManagerContract: "zil1ur4vwcmcz3jqypksgq7qeju2sk5jrskzaadau5", }}, } + s = &ZilSender{ + cfg: &config.Config{ZilConfig: &config.ZILConfig{ + CrossChainManagerContract: "zil1ur4vwcmcz3jqypksgq7qeju2sk5jrskzaadau5", + }}, + zilSdk: zilSdk, + acc: "zil1ur4vwcmcz3jqypksgq7qeju2sk5jrskzaadau5", + } } func TestPolySyncManager_FindLatestHeight(t *testing.T) { fmt.Println(p.findLatestHeight()) } -func TestPolySyncManager_CheckIfFromChainTxExist(t *testing.T) { - exist := p.checkIfFromChainTxExist(3, "0x00ca93f8738111a063d8ab7221f47c70a4cade0ca4a2829df494cd4b5e231bd6") +func TestZilSender_CheckIfFromChainTxExist(t *testing.T) { + exist := s.checkIfFromChainTxExist(3, "0x00ca93f8738111a063d8ab7221f47c70a4cade0ca4a2829df494cd4b5e231bd6") assert.Equal(t, exist, true) - exist = p.checkIfFromChainTxExist(3, "0x00ca93f8738111a063d8ab7221f47c70a4cade0ca4a2829df494cd4b5e231bd7") + exist = s.checkIfFromChainTxExist(3, "0x00ca93f8738111a063d8ab7221f47c70a4cade0ca4a2829df494cd4b5e231bd7") assert.Equal(t, exist, false) } diff --git a/service/polymanager.go b/service/polymanager.go new file mode 100644 index 0000000..fb9d4f0 --- /dev/null +++ b/service/polymanager.go @@ -0,0 +1,22 @@ +package service + +import ( + "github.com/Zilliqa/gozilliqa-sdk/provider" + "github.com/polynetwork/poly-go-sdk" + "github.com/polynetwork/zilliqa-relayer/config" + "github.com/polynetwork/zilliqa-relayer/db" +) + +type PolySyncManager struct { + currentHeight uint32 + polySdk *poly_go_sdk.PolySdk + exitChan chan int + cfg *config.Config + db *db.BoltDB + + zilSdk *provider.Provider +} + +func (p *PolySyncManager) Run() { + waitToExit() +} diff --git a/service/sync_service.go b/service/zilliqamanager.go similarity index 64% rename from service/sync_service.go rename to service/zilliqamanager.go index 5fc1944..163a48b 100644 --- a/service/sync_service.go +++ b/service/zilliqamanager.go @@ -1,15 +1,13 @@ package service import ( + "github.com/Zilliqa/gozilliqa-sdk/account" "github.com/Zilliqa/gozilliqa-sdk/provider" poly "github.com/polynetwork/poly-go-sdk" - "github.com/polynetwork/poly/account" "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/db" log "github.com/sirupsen/logrus" "os" - "os/signal" - "syscall" ) type ZilliqaSyncManager struct { @@ -48,39 +46,3 @@ func (s *ZilliqaSyncManager) Run() { go s.MonitorDeposit() waitToExit() } - -type PolySyncManager struct { - currentHeight uint32 - polySdk *poly.PolySdk - exitChan chan int - cfg *config.Config - db *db.BoltDB - - zilSdk *provider.Provider -} - -func (p *PolySyncManager) Run() { - waitToExit() -} - -func checkIfExist(dir string) bool { - _, err := os.Stat(dir) - if err != nil && !os.IsExist(err) { - return false - } - return true -} - -func waitToExit() { - exit := make(chan bool, 0) - sc := make(chan os.Signal, 1) - signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) - go func() { - for sig := range sc { - log.Infof("Zilliqa Relayer received exit signal: %v.", sig.String()) - close(exit) - break - } - }() - <-exit -} From efc4109b59dc93d2aef09598cb2917a59aae7fc6 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 20 Jan 2021 12:04:37 +0800 Subject: [PATCH 019/107] feat(config): support zil chain id, message version and keystore(multiple) --- .gitignore | 3 +-- README.md | 18 ++++++++++++++++-- cmd/run.go | 4 ++++ config.yaml | 6 ++++++ config/config.go | 4 ++++ keystore | 2 ++ 6 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 keystore diff --git a/.gitignore b/.gitignore index 8fb3c1f..6f06244 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ zilliqa-relayer .idea -bolt.bin -zilliqa-relayer \ No newline at end of file +bolt.bin \ No newline at end of file diff --git a/README.md b/README.md index 77bb6f0..6e3fb53 100644 --- a/README.md +++ b/README.md @@ -43,15 +43,29 @@ Before running, you need feed the configuration file `config.yaml`. ```yaml zil_config: zil_api: https://polynetworkcc3dcb2-5-api.dev.z7a.xyz + zil_chain_id: 333 + zil_message_version: 1 zil_start_height: 38 zil_monitor_interval: 40 corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f side_chain_id: 1 + key_store_path: ./keystore + key_store_pwd_set: + 7d48043742a1103042d327111746531ca26be9be: "pwd1" + de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7: "pwd2" poly_config: poly_wallet_file: wallet.dat poly_wallet_pwd: dummy - entrance_contract_address: 0300000000000000000000000000000000000000 - rest_url: http://beta1.poly.network + poly_monitor_interval: 40 + entrance_contract_address: "0300000000000000000000000000000000000000" + rest_url: http://beta1.poly.network +``` + +A sample keystore file could be: + +```text +{"address":"7d48043742a1103042d327111746531ca26be9be","id":"6cd445ed-8f5f-4565-af2a-cc2306a82b73","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"d136660a4e5664709031ebc162616556e8c812ab37d0157ea3276aa08d0a6c2d","kdf":"pbkdf2","mac":"b30dd459f1fd9d99c0b2f3452ccd2bf11414ad92d32ac70d1d7b52f17281b4e5","cipherparams":{"iv":"6a14f95c8cbafe7d1f317bec88e9d1b8"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"c4939e7cead32935d1972a2cd06d249dd501181e6ad2d1872fa0eb397d7fea20"}}} +{"address":"de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7","id":"e6ed9aba-7be3-40ca-8fab-7f9438fdf7cf","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"b96b59ea5861c7048f62cf15c219faa9e1494495030f42f021b6277622ab819f","kdf":"pbkdf2","mac":"ad06d0f0f5df29ad0947a62954ed08b084c2fc11aec66a36ab2c79eb1398768c","cipherparams":{"iv":"ef08dc8dbca886b1141e13fb7e988817"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"26bc16e8bc0dc2749c1cde2e62aa5c9990898c5c4d3f78c822fed2988c0ab682"}}} ``` ## Other Resources diff --git a/cmd/run.go b/cmd/run.go index aaf13f0..94979aa 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -60,10 +60,14 @@ var runCmd = &cobra.Command{ zilConfigMap := viper.GetStringMap("zil_config") zilConfig := &config.ZILConfig{ ZilApiEndpoint: zilConfigMap["zil_api"].(string), + ZilChainId: zilConfigMap["zil_chain_id"].(int), + ZilMessageVersion: zilConfigMap["zil_message_version"].(int), ZilStartHeight: uint32(zilConfigMap["zil_start_height"].(int)), ZilMonitorInterval: uint32(zilConfigMap["zil_monitor_interval"].(int)), SideChainId: uint64(zilConfigMap["side_chain_id"].(int)), CrossChainManagerContract: zilConfigMap["corss_chain_manager_address"].(string), + KeyStorePath: zilConfigMap["key_store_path"].(string), + KeyStorePwdSet: zilConfigMap["key_store_pwd_set"].(map[string]interface{}), } polyConfigMap := viper.GetStringMap("poly_config") diff --git a/config.yaml b/config.yaml index 1795ec9..32c91ad 100644 --- a/config.yaml +++ b/config.yaml @@ -1,9 +1,15 @@ zil_config: zil_api: https://polynetworkcc3dcb2-5-api.dev.z7a.xyz + zil_chain_id: 333 + zil_message_version: 1 zil_start_height: 38 zil_monitor_interval: 40 corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f side_chain_id: 1 + key_store_path: ./keystore + key_store_pwd_set: + 7d48043742a1103042d327111746531ca26be9be: "pwd1" + de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7: "pwd2" poly_config: poly_wallet_file: wallet.dat poly_wallet_pwd: dummy diff --git a/config/config.go b/config/config.go index 8c65e61..0594ce1 100644 --- a/config/config.go +++ b/config/config.go @@ -13,10 +13,14 @@ type Config struct { type ZILConfig struct { ZilApiEndpoint string + ZilChainId int + ZilMessageVersion int ZilMonitorInterval uint32 ZilStartHeight uint32 SideChainId uint64 CrossChainManagerContract string + KeyStorePath string + KeyStorePwdSet map[string]interface{} } type POLYConfig struct { diff --git a/keystore b/keystore new file mode 100644 index 0000000..97830b5 --- /dev/null +++ b/keystore @@ -0,0 +1,2 @@ +{"address":"7d48043742a1103042d327111746531ca26be9be","id":"6cd445ed-8f5f-4565-af2a-cc2306a82b73","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"d136660a4e5664709031ebc162616556e8c812ab37d0157ea3276aa08d0a6c2d","kdf":"pbkdf2","mac":"b30dd459f1fd9d99c0b2f3452ccd2bf11414ad92d32ac70d1d7b52f17281b4e5","cipherparams":{"iv":"6a14f95c8cbafe7d1f317bec88e9d1b8"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"c4939e7cead32935d1972a2cd06d249dd501181e6ad2d1872fa0eb397d7fea20"}}} +{"address":"de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7","id":"e6ed9aba-7be3-40ca-8fab-7f9438fdf7cf","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"b96b59ea5861c7048f62cf15c219faa9e1494495030f42f021b6277622ab819f","kdf":"pbkdf2","mac":"ad06d0f0f5df29ad0947a62954ed08b084c2fc11aec66a36ab2c79eb1398768c","cipherparams":{"iv":"ef08dc8dbca886b1141e13fb7e988817"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"26bc16e8bc0dc2749c1cde2e62aa5c9990898c5c4d3f78c822fed2988c0ab682"}}} \ No newline at end of file From 98e7b0e4ed633e7e8d99dabe49b3c29c00f66dd5 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 20 Jan 2021 23:48:19 +0800 Subject: [PATCH 020/107] feat: init polymanager, parse zil keystore with pwd set --- cmd/run.go | 53 +++++++++++++++++++++++++++++++++--- config.yaml | 6 ++--- service/common.go | 10 +------ service/poly2zil.go | 45 +------------------------------ service/poly2zil_test.go | 4 +-- service/polymanager.go | 56 +++++++++++++++++++++++++++++++++++++-- service/zil_sender.go | 56 +++++++++++++++++++++++++++++++++++++++ service/zilliqamanager.go | 15 ++--------- tools/utils.go | 22 +++++++++++++++ 9 files changed, 191 insertions(+), 76 deletions(-) create mode 100644 service/zil_sender.go diff --git a/cmd/run.go b/cmd/run.go index 94979aa..31952d2 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -2,11 +2,15 @@ package cmd import ( "encoding/json" + "github.com/Zilliqa/gozilliqa-sdk/provider" + poly_go_sdk "github.com/polynetwork/poly-go-sdk" "github.com/polynetwork/zilliqa-relayer/config" + "github.com/polynetwork/zilliqa-relayer/db" "github.com/polynetwork/zilliqa-relayer/service" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" + "os" ) var cfgFile string @@ -49,7 +53,24 @@ func initConfig() { } else { log.Error(err.Error()) } +} +func setUpPoly(poly *poly_go_sdk.PolySdk, RpcAddr string) error { + poly.NewRpcClient().SetAddress(RpcAddr) + hdr, err := poly.GetHeaderByHeight(0) + if err != nil { + return err + } + poly.SetChainId(hdr.ChainID) + return nil +} + +func checkIfExist(dir string) bool { + _, err := os.Stat(dir) + if err != nil && !os.IsExist(err) { + return false + } + return true } var runCmd = &cobra.Command{ @@ -84,11 +105,37 @@ var runCmd = &cobra.Command{ PolyConfig: polyConfig, } - // todo delete it cfgStr, _ := json.Marshal(cfg) log.Infof("config file: %s\n", cfgStr) - syncService := service.NewZilliqaSyncManager(cfg) - syncService.Run() + zilSdk := provider.NewProvider(cfg.ZilConfig.ZilApiEndpoint) + polySdk := poly_go_sdk.NewPolySdk() + err1 := setUpPoly(polySdk, cfg.PolyConfig.RestUrl) + if err1 != nil { + log.Errorf("init poly sdk error: %s\n", err1.Error()) + return + } + + if !checkIfExist(cfg.Path) { + os.Mkdir(cfg.Path, os.ModePerm) + } + boltDB, err2 := db.NewBoltDB(cfg.Path) + if err2 != nil { + log.Errorf("cannot init bolt db: %s\n", err2.Error()) + return + } + + zilliqaManager := service.NewZilliqaSyncManager(cfg, zilSdk, boltDB) + polyManager, err := service.NewPolySyncManager(cfg, zilSdk, polySdk, boltDB) + if err != nil { + log.Errorf("init polymanager error: %s\n", err.Error()) + return + } + + zilliqaManager.Run() + polyManager.Run() + + service.WaitToExit() + }, } diff --git a/config.yaml b/config.yaml index 32c91ad..fb3ff11 100644 --- a/config.yaml +++ b/config.yaml @@ -6,10 +6,10 @@ zil_config: zil_monitor_interval: 40 corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f side_chain_id: 1 - key_store_path: ./keystore + key_store_path: keystore key_store_pwd_set: - 7d48043742a1103042d327111746531ca26be9be: "pwd1" - de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7: "pwd2" + 7d48043742a1103042d327111746531ca26be9be: "xiaohuo" + de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7: "xiaohuo" poly_config: poly_wallet_file: wallet.dat poly_wallet_pwd: dummy diff --git a/service/common.go b/service/common.go index 4a2be76..a103d97 100644 --- a/service/common.go +++ b/service/common.go @@ -7,15 +7,7 @@ import ( "syscall" ) -func checkIfExist(dir string) bool { - _, err := os.Stat(dir) - if err != nil && !os.IsExist(err) { - return false - } - return true -} - -func waitToExit() { +func WaitToExit() { exit := make(chan bool, 0) sc := make(chan os.Signal, 1) signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) diff --git a/service/poly2zil.go b/service/poly2zil.go index 048e534..b6061ba 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -4,9 +4,7 @@ import ( "encoding/hex" "encoding/json" "github.com/Zilliqa/gozilliqa-sdk/bech32" - "github.com/Zilliqa/gozilliqa-sdk/provider" "github.com/Zilliqa/gozilliqa-sdk/util" - "github.com/ontio/ontology-crypto/signature" "github.com/polynetwork/poly/common" "github.com/polynetwork/poly/consensus/vbft/config" polytypes "github.com/polynetwork/poly/core/types" @@ -139,7 +137,7 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { cnt++ sender := p.selectSender() log.Infof("sender %s is handling poly tx ( hash: %s, height: %d )", - sender.acc, event.TxHash, height) + sender.address, event.TxHash, height) // temporarily ignore the error for tx sender.commitDepositEventsWithHeader(hdr, param, hp, anchor, event.TxHash, auditpath) } @@ -154,47 +152,6 @@ func (p *PolySyncManager) selectSender() *ZilSender { return &ZilSender{} } -type ZilSender struct { - cfg *config.Config - zilSdk *provider.Provider - acc string -} - -func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { - // verifyHeaderAndExecuteTx - var ( - sigs []byte - //headerData []byte - ) - if anchorHeader != nil && headerProof != "" { - for _, sig := range anchorHeader.SigData { - temp := make([]byte, len(sig)) - copy(temp, sig) - newsig, _ := signature.ConvertToEthCompatible(temp) - sigs = append(sigs, newsig...) - } - } else { - for _, sig := range header.SigData { - temp := make([]byte, len(sig)) - copy(temp, sig) - newsig, _ := signature.ConvertToEthCompatible(temp) - sigs = append(sigs, newsig...) - } - } - - // todo ensure that TxHash is bytes of hash, not utf8 bytes - exist := sender.checkIfFromChainTxExist(param.FromChainID, util.EncodeHex(param.TxHash)) - if exist { - log.Infof("ZilSender commitDepositEventsWithHeader - already relayed to zil: (from_chain_id: %d, from_txhash: %x, param.TxHash: %x\n)", param.FromChainID, param.TxHash, param.MakeTxParam.TxHash) - return true - } - - // todo - - return true - -} - type EpochStartHeight struct { CurEpochStartHeight string `json:"curEpochStartHeight"` } diff --git a/service/poly2zil_test.go b/service/poly2zil_test.go index b2d547a..5f6aaa1 100644 --- a/service/poly2zil_test.go +++ b/service/poly2zil_test.go @@ -23,8 +23,8 @@ func init() { cfg: &config.Config{ZilConfig: &config.ZILConfig{ CrossChainManagerContract: "zil1ur4vwcmcz3jqypksgq7qeju2sk5jrskzaadau5", }}, - zilSdk: zilSdk, - acc: "zil1ur4vwcmcz3jqypksgq7qeju2sk5jrskzaadau5", + zilSdk: zilSdk, + address: "zil1ur4vwcmcz3jqypksgq7qeju2sk5jrskzaadau5", } } diff --git a/service/polymanager.go b/service/polymanager.go index fb9d4f0..57aa799 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -1,10 +1,14 @@ package service import ( + "encoding/json" + "errors" + "github.com/Zilliqa/gozilliqa-sdk/crypto" "github.com/Zilliqa/gozilliqa-sdk/provider" "github.com/polynetwork/poly-go-sdk" "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/db" + "github.com/polynetwork/zilliqa-relayer/tools" ) type PolySyncManager struct { @@ -14,9 +18,57 @@ type PolySyncManager struct { cfg *config.Config db *db.BoltDB - zilSdk *provider.Provider + zilSdk *provider.Provider + senders []*ZilSender } func (p *PolySyncManager) Run() { - waitToExit() + +} + +func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk *poly_go_sdk.PolySdk, boltDB *db.BoltDB) (*PolySyncManager, error) { + keystores, err := tools.ReadLine(cfg.ZilConfig.KeyStorePath) + keystorepwdset := cfg.ZilConfig.KeyStorePwdSet + if err != nil { + return nil, err + } + descryptor := crypto.NewDefaultKeystore() + + var senders []*ZilSender + + for _, keystore := range keystores { + var ks crypto.KeystoreV3 + err1 := json.Unmarshal([]byte(keystore), &ks) + if err1 != nil { + return nil, err1 + } + pwd := keystorepwdset[ks.Address] + if pwd == nil { + return nil, errors.New("NewPolySyncManager - there is no password for keystore: " + ks.Address) + } + privateKey, err2 := descryptor.DecryptPrivateKey(keystore, pwd.(string)) + if err2 != nil { + return nil, errors.New("NewPolySyncManager - descrypt keystore error: " + err2.Error()) + } + + sender := &ZilSender{ + cfg: cfg, + zilSdk: zilSdk, + address: ks.Address, + privateKey: privateKey, + polySdk: polySdk, + } + + senders = append(senders, sender) + } + + return &PolySyncManager{ + currentHeight: cfg.PolyConfig.PolyMonitorInterval, + polySdk: polySdk, + exitChan: make(chan int), + cfg: cfg, + db: boltDB, + zilSdk: zilSdk, + senders: senders, + }, nil } diff --git a/service/zil_sender.go b/service/zil_sender.go new file mode 100644 index 0000000..64c4889 --- /dev/null +++ b/service/zil_sender.go @@ -0,0 +1,56 @@ +package service + +import ( + "github.com/Zilliqa/gozilliqa-sdk/provider" + "github.com/Zilliqa/gozilliqa-sdk/util" + "github.com/ontio/ontology-crypto/signature" + poly_go_sdk "github.com/polynetwork/poly-go-sdk" + polytypes "github.com/polynetwork/poly/core/types" + common2 "github.com/polynetwork/poly/native/service/cross_chain_manager/common" + "github.com/polynetwork/zilliqa-relayer/config" + log "github.com/sirupsen/logrus" +) + +type ZilSender struct { + cfg *config.Config + zilSdk *provider.Provider + address string //non-bech32 address + privateKey string + + polySdk *poly_go_sdk.PolySdk +} + +func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { + // verifyHeaderAndExecuteTx + var ( + sigs []byte + //headerData []byte + ) + if anchorHeader != nil && headerProof != "" { + for _, sig := range anchorHeader.SigData { + temp := make([]byte, len(sig)) + copy(temp, sig) + newsig, _ := signature.ConvertToEthCompatible(temp) + sigs = append(sigs, newsig...) + } + } else { + for _, sig := range header.SigData { + temp := make([]byte, len(sig)) + copy(temp, sig) + newsig, _ := signature.ConvertToEthCompatible(temp) + sigs = append(sigs, newsig...) + } + } + + // todo ensure that TxHash is bytes of hash, not utf8 bytes + exist := sender.checkIfFromChainTxExist(param.FromChainID, util.EncodeHex(param.TxHash)) + if exist { + log.Infof("ZilSender commitDepositEventsWithHeader - already relayed to zil: (from_chain_id: %d, from_txhash: %x, param.TxHash: %x\n)", param.FromChainID, param.TxHash, param.MakeTxParam.TxHash) + return true + } + + // todo + + return true + +} diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 163a48b..7ba9519 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -6,8 +6,6 @@ import ( poly "github.com/polynetwork/poly-go-sdk" "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/db" - log "github.com/sirupsen/logrus" - "os" ) type ZilliqaSyncManager struct { @@ -23,19 +21,11 @@ type ZilliqaSyncManager struct { exitChan chan int } -func NewZilliqaSyncManager(cfg *config.Config) *ZilliqaSyncManager { - if !checkIfExist(cfg.Path) { - os.Mkdir(cfg.Path, os.ModePerm) - } - boltDB, err := db.NewBoltDB(cfg.Path) - if err != nil { - log.Fatal("cannot init bolt db") - } - +func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, boltDB *db.BoltDB) *ZilliqaSyncManager { return &ZilliqaSyncManager{ db: boltDB, cfg: cfg, - zilSdk: provider.NewProvider(cfg.ZilConfig.ZilApiEndpoint), + zilSdk: zilSdk, currentHeight: uint64(cfg.ZilConfig.ZilStartHeight), crossChainManagerAddress: cfg.ZilConfig.CrossChainManagerContract, } @@ -44,5 +34,4 @@ func NewZilliqaSyncManager(cfg *config.Config) *ZilliqaSyncManager { func (s *ZilliqaSyncManager) Run() { go s.MonitorChain() go s.MonitorDeposit() - waitToExit() } diff --git a/tools/utils.go b/tools/utils.go index 0d2c5a8..d2017ec 100644 --- a/tools/utils.go +++ b/tools/utils.go @@ -1,9 +1,11 @@ package tools import ( + "bufio" "encoding/hex" "github.com/polynetwork/poly/common" "math/big" + "os" ) func EncodeBigInt(b *big.Int) string { @@ -46,3 +48,23 @@ func ParseAuditpath(path []byte) ([]byte, []byte, [][32]byte, error) { return value, pos, hashs, nil } + +func ReadLine(path string) ([]string, error) { + var lines []string + file, err := os.Open(path) + if err != nil { + return lines, err + } + defer file.Close() + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + lines = append(lines, scanner.Text()) + } + + if err1 := scanner.Err(); err1 != nil { + return lines, err1 + } + + return lines, nil +} From 8008ee78ed3098b7f0efc11853f0a8b6542f3135 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 21 Jan 2021 14:28:44 +0800 Subject: [PATCH 021/107] feat(zilsender): commitDepositEventsWithHeader --- cmd/run.go | 21 +++++++++-------- config.yaml | 1 + config/config.go | 19 ++++++++-------- service/nonce_manager.go | 5 ++++ service/polymanager.go | 49 ++++++++++++++++++++++++++++------------ service/zil_sender.go | 29 ++++++++++++++++++++---- 6 files changed, 86 insertions(+), 38 deletions(-) create mode 100644 service/nonce_manager.go diff --git a/cmd/run.go b/cmd/run.go index 31952d2..97e7b6e 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -80,15 +80,16 @@ var runCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { zilConfigMap := viper.GetStringMap("zil_config") zilConfig := &config.ZILConfig{ - ZilApiEndpoint: zilConfigMap["zil_api"].(string), - ZilChainId: zilConfigMap["zil_chain_id"].(int), - ZilMessageVersion: zilConfigMap["zil_message_version"].(int), - ZilStartHeight: uint32(zilConfigMap["zil_start_height"].(int)), - ZilMonitorInterval: uint32(zilConfigMap["zil_monitor_interval"].(int)), - SideChainId: uint64(zilConfigMap["side_chain_id"].(int)), - CrossChainManagerContract: zilConfigMap["corss_chain_manager_address"].(string), - KeyStorePath: zilConfigMap["key_store_path"].(string), - KeyStorePwdSet: zilConfigMap["key_store_pwd_set"].(map[string]interface{}), + ZilApiEndpoint: zilConfigMap["zil_api"].(string), + ZilChainId: zilConfigMap["zil_chain_id"].(int), + ZilMessageVersion: zilConfigMap["zil_message_version"].(int), + ZilStartHeight: uint32(zilConfigMap["zil_start_height"].(int)), + ZilMonitorInterval: uint32(zilConfigMap["zil_monitor_interval"].(int)), + SideChainId: uint64(zilConfigMap["side_chain_id"].(int)), + CrossChainManagerContract: zilConfigMap["corss_chain_manager_address"].(string), + CrossChainManagerProxyContract: zilConfigMap["cross_chain_manager_proxy_address"].(string), + KeyStorePath: zilConfigMap["key_store_path"].(string), + KeyStorePwdSet: zilConfigMap["key_store_pwd_set"].(map[string]interface{}), } polyConfigMap := viper.GetStringMap("poly_config") @@ -126,7 +127,7 @@ var runCmd = &cobra.Command{ } zilliqaManager := service.NewZilliqaSyncManager(cfg, zilSdk, boltDB) - polyManager, err := service.NewPolySyncManager(cfg, zilSdk, polySdk, boltDB) + polyManager, err := service.NewPolySyncManager(cfg, zilSdk, polySdk, boltDB, cfg.ZilConfig.CrossChainManagerContract, cfg.ZilConfig.CrossChainManagerProxyContract) if err != nil { log.Errorf("init polymanager error: %s\n", err.Error()) return diff --git a/config.yaml b/config.yaml index fb3ff11..c236a44 100644 --- a/config.yaml +++ b/config.yaml @@ -5,6 +5,7 @@ zil_config: zil_start_height: 38 zil_monitor_interval: 40 corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f + cross_chain_manager_proxy_address: zil1urrkyfpww7rzhxh36m9nhksr5z73ragpar53nk side_chain_id: 1 key_store_path: keystore key_store_pwd_set: diff --git a/config/config.go b/config/config.go index 0594ce1..89da2da 100644 --- a/config/config.go +++ b/config/config.go @@ -12,15 +12,16 @@ type Config struct { } type ZILConfig struct { - ZilApiEndpoint string - ZilChainId int - ZilMessageVersion int - ZilMonitorInterval uint32 - ZilStartHeight uint32 - SideChainId uint64 - CrossChainManagerContract string - KeyStorePath string - KeyStorePwdSet map[string]interface{} + ZilApiEndpoint string + ZilChainId int + ZilMessageVersion int + ZilMonitorInterval uint32 + ZilStartHeight uint32 + SideChainId uint64 + CrossChainManagerContract string + CrossChainManagerProxyContract string + KeyStorePath string + KeyStorePwdSet map[string]interface{} } type POLYConfig struct { diff --git a/service/nonce_manager.go b/service/nonce_manager.go new file mode 100644 index 0000000..73b34ed --- /dev/null +++ b/service/nonce_manager.go @@ -0,0 +1,5 @@ +package service + +// todo we don't consider nonce manager for now as mongo service is not completely exposed to public +type NonceManager struct { +} diff --git a/service/polymanager.go b/service/polymanager.go index 57aa799..6fa5d4a 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -3,6 +3,8 @@ package service import ( "encoding/json" "errors" + "github.com/Zilliqa/gozilliqa-sdk/account" + "github.com/Zilliqa/gozilliqa-sdk/crosschain/polynetwork" "github.com/Zilliqa/gozilliqa-sdk/crypto" "github.com/Zilliqa/gozilliqa-sdk/provider" "github.com/polynetwork/poly-go-sdk" @@ -18,15 +20,17 @@ type PolySyncManager struct { cfg *config.Config db *db.BoltDB - zilSdk *provider.Provider - senders []*ZilSender + zilSdk *provider.Provider + crossChainManager string + crossChainManagerProxy string + senders []*ZilSender } func (p *PolySyncManager) Run() { } -func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk *poly_go_sdk.PolySdk, boltDB *db.BoltDB) (*PolySyncManager, error) { +func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk *poly_go_sdk.PolySdk, boltDB *db.BoltDB, crossChainManager, crossChainManagerProxy string) (*PolySyncManager, error) { keystores, err := tools.ReadLine(cfg.ZilConfig.KeyStorePath) keystorepwdset := cfg.ZilConfig.KeyStorePwdSet if err != nil { @@ -51,24 +55,39 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * return nil, errors.New("NewPolySyncManager - descrypt keystore error: " + err2.Error()) } + // init cross chain smart contract proxy + wallet := account.NewWallet() + wallet.AddByPrivateKey(privateKey) + proxy := &polynetwork.Proxy{ + ProxyAddr: crossChainManagerProxy, + ImplAddr: crossChainManager, + Wallet: wallet, + Client: zilSdk, + ChainId: cfg.ZilConfig.ZilChainId, + MsgVersion: cfg.ZilConfig.ZilMessageVersion, + } + sender := &ZilSender{ - cfg: cfg, - zilSdk: zilSdk, - address: ks.Address, - privateKey: privateKey, - polySdk: polySdk, + cfg: cfg, + zilSdk: zilSdk, + address: ks.Address, + privateKey: privateKey, + polySdk: polySdk, + crossChainProxy: proxy, } senders = append(senders, sender) } return &PolySyncManager{ - currentHeight: cfg.PolyConfig.PolyMonitorInterval, - polySdk: polySdk, - exitChan: make(chan int), - cfg: cfg, - db: boltDB, - zilSdk: zilSdk, - senders: senders, + currentHeight: cfg.PolyConfig.PolyMonitorInterval, + polySdk: polySdk, + exitChan: make(chan int), + cfg: cfg, + db: boltDB, + zilSdk: zilSdk, + crossChainManager: crossChainManager, + crossChainManagerProxy: crossChainManagerProxy, + senders: senders, }, nil } diff --git a/service/zil_sender.go b/service/zil_sender.go index 64c4889..f94bd30 100644 --- a/service/zil_sender.go +++ b/service/zil_sender.go @@ -1,6 +1,7 @@ package service import ( + "github.com/Zilliqa/gozilliqa-sdk/crosschain/polynetwork" "github.com/Zilliqa/gozilliqa-sdk/provider" "github.com/Zilliqa/gozilliqa-sdk/util" "github.com/ontio/ontology-crypto/signature" @@ -17,14 +18,15 @@ type ZilSender struct { address string //non-bech32 address privateKey string - polySdk *poly_go_sdk.PolySdk + polySdk *poly_go_sdk.PolySdk + crossChainProxy *polynetwork.Proxy } func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { // verifyHeaderAndExecuteTx var ( - sigs []byte - //headerData []byte + sigs []byte + headerData []byte ) if anchorHeader != nil && headerProof != "" { for _, sig := range anchorHeader.SigData { @@ -49,8 +51,27 @@ func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, return true } - // todo + var rawAnchor []byte + if anchorHeader != nil { + rawAnchor = anchorHeader.GetMessage() + } + headerData = header.GetMessage() + + // todo carefully test this + pe := polynetwork.DeserializeProof(util.EncodeHex(rawAuditPath), 0) + rawHeader := util.EncodeHex(headerData) + hpe := polynetwork.DeserializeProof(headerProof, 0) + curRawHeader := util.EncodeHex(rawAnchor) + signatures, _ := polynetwork.SplitSignature(util.EncodeHex(sigs)) + + // todo use chan to handle result + transaction, err := sender.crossChainProxy.VerifyHeaderAndExecuteTx(pe, rawHeader, hpe, curRawHeader, signatures) + if err != nil { + log.Errorf("ZilSender commitDepositEventsWithHeader - failed to call VerifyHeaderAndExecuteTx: %s\n", err.Error()) + return false + } + log.Infof("ZilSender commitDepositEventsWithHeader - confirmed transaction: %s\n", transaction.ID) return true } From 53b6aca40506479d4dbd15296bb17df1b7b883d3 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 21 Jan 2021 14:40:57 +0800 Subject: [PATCH 022/107] feat: temp use one sender to intereact with cross chain contract --- service/poly2zil.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/poly2zil.go b/service/poly2zil.go index b6061ba..d7b4037 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -148,8 +148,8 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { } func (p *PolySyncManager) selectSender() *ZilSender { - // todo - return &ZilSender{} + // todo considering now we only have one admin which can control the contract + return p.senders[0] } type EpochStartHeight struct { From 68221c3f07312489672cde3c0ba8aaccbd29ddd3 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 21 Jan 2021 16:24:03 +0800 Subject: [PATCH 023/107] feat(zilsender): commitHeader --- go.mod | 2 ++ service/poly2zil.go | 5 ++++ service/zil_sender.go | 52 ++++++++++++++++++++++++++++++++++++++++ tools/utils.go | 55 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) diff --git a/go.mod b/go.mod index 3d82c91..6ab23cf 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43 github.com/boltdb/bolt v1.3.1 + github.com/btcsuite/btcd v0.20.1-beta github.com/magiconair/properties v1.8.1 github.com/ontio/ontology-crypto v1.0.9 github.com/polynetwork/poly v0.0.0-20200715030435-4f1d1a0adb44 @@ -12,4 +13,5 @@ require ( github.com/sirupsen/logrus v1.7.0 github.com/spf13/cobra v1.1.1 github.com/spf13/viper v1.7.0 + golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 ) diff --git a/service/poly2zil.go b/service/poly2zil.go index d7b4037..f69ac4b 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -144,6 +144,11 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { } } + if cnt == 0 && isEpoch && isCurr { + sender := p.selectSender() + return sender.commitHeader(hdr) + } + return true } diff --git a/service/zil_sender.go b/service/zil_sender.go index f94bd30..e8aeeaa 100644 --- a/service/zil_sender.go +++ b/service/zil_sender.go @@ -1,14 +1,19 @@ package service import ( + "encoding/hex" + "encoding/json" "github.com/Zilliqa/gozilliqa-sdk/crosschain/polynetwork" "github.com/Zilliqa/gozilliqa-sdk/provider" "github.com/Zilliqa/gozilliqa-sdk/util" + "github.com/ontio/ontology-crypto/keypair" "github.com/ontio/ontology-crypto/signature" poly_go_sdk "github.com/polynetwork/poly-go-sdk" + vconfig "github.com/polynetwork/poly/consensus/vbft/config" polytypes "github.com/polynetwork/poly/core/types" common2 "github.com/polynetwork/poly/native/service/cross_chain_manager/common" "github.com/polynetwork/zilliqa-relayer/config" + "github.com/polynetwork/zilliqa-relayer/tools" log "github.com/sirupsen/logrus" ) @@ -75,3 +80,50 @@ func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, return true } + +func (sender *ZilSender) commitHeader(hdr *polytypes.Header) bool { + headerdata := hdr.GetMessage() + var ( + bookkeepers []keypair.PublicKey + sigs []byte + ) + + for _, sig := range hdr.SigData { + temp := make([]byte, len(sig)) + copy(temp, sig) + newsig, _ := signature.ConvertToEthCompatible(temp) + sigs = append(sigs, newsig...) + } + + blkInfo := &vconfig.VbftBlockInfo{} + if err := json.Unmarshal(hdr.ConsensusPayload, blkInfo); err != nil { + log.Errorf("commitHeader - unmarshal blockInfo error: %s", err) + return false + } + + for _, peer := range blkInfo.NewChainConfig.Peers { + keystr, _ := hex.DecodeString(peer.ID) + key, _ := keypair.DeserializePublicKey(keystr) + bookkeepers = append(bookkeepers, key) + } + + bookkeepers = keypair.SortPublicKeys(bookkeepers) + publickeys := make([]byte, 0) + for _, key := range bookkeepers { + publickeys = append(publickeys, tools.GetNoCompresskey(key)...) + } + + // todo carefully test this, add more useful logs + rawHeader := util.EncodeHex(headerdata) + PubKeys, _ := polynetwork.SplitPubKeys(util.EncodeHex(publickeys)) + signatures, _ := polynetwork.SplitSignature(util.EncodeHex(sigs)) + transaction, err := sender.crossChainProxy.ChangeBookKeeper(rawHeader, PubKeys, signatures) + if err != nil { + log.Errorf("ZilSender commitHeader - failed to call VerifyHeaderAndExecuteTx: %s\n", err.Error()) + return false + } + + log.Infof("ZilSender commitHeader - confirmed transaction: %s\n", transaction.ID) + return true + +} diff --git a/tools/utils.go b/tools/utils.go index d2017ec..704078a 100644 --- a/tools/utils.go +++ b/tools/utils.go @@ -2,10 +2,18 @@ package tools import ( "bufio" + "bytes" + "crypto/elliptic" "encoding/hex" + "github.com/btcsuite/btcd/btcec" + "github.com/ontio/ontology-crypto/ec" + "github.com/ontio/ontology-crypto/keypair" + "github.com/ontio/ontology-crypto/sm2" "github.com/polynetwork/poly/common" + "golang.org/x/crypto/ed25519" "math/big" "os" + "strings" ) func EncodeBigInt(b *big.Int) string { @@ -68,3 +76,50 @@ func ReadLine(path string) ([]string, error) { return lines, nil } + +func GetCurveLabel(name string) (byte, error) { + switch strings.ToUpper(name) { + case strings.ToUpper(elliptic.P224().Params().Name): + return 1, nil + case strings.ToUpper(elliptic.P256().Params().Name): + return 2, nil + case strings.ToUpper(elliptic.P384().Params().Name): + return 3, nil + case strings.ToUpper(elliptic.P521().Params().Name): + return 4, nil + case strings.ToUpper(sm2.SM2P256V1().Params().Name): + return 20, nil + case strings.ToUpper(btcec.S256().Name): + return 5, nil + default: + panic("err") + } +} + +func GetNoCompresskey(key keypair.PublicKey) []byte { + var buf bytes.Buffer + switch t := key.(type) { + case *ec.PublicKey: + switch t.Algorithm { + case ec.ECDSA: + // Take P-256 as a special case + if t.Params().Name == elliptic.P256().Params().Name { + return ec.EncodePublicKey(t.PublicKey, false) + } + buf.WriteByte(byte(0x12)) + case ec.SM2: + buf.WriteByte(byte(0x13)) + } + label, err := GetCurveLabel(t.Curve.Params().Name) + if err != nil { + panic(err) + } + buf.WriteByte(label) + buf.Write(ec.EncodePublicKey(t.PublicKey, false)) + case ed25519.PublicKey: + panic("err") + default: + panic("err") + } + return buf.Bytes() +} From 43f6cce8c719a0086c45582ff892e8de60e24960 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Fri, 22 Jan 2021 12:13:06 +0800 Subject: [PATCH 024/107] feat(polymanager): init start height --- db/db.go | 18 ++++++++++++++++++ go.mod | 1 + service/poly2zil.go | 5 +++++ service/polymanager.go | 21 ++++++++++++++++++++- 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/db/db.go b/db/db.go index 6882594..7c3aecd 100644 --- a/db/db.go +++ b/db/db.go @@ -114,3 +114,21 @@ func (w *BoltDB) UpdatePolyHeight(h uint32) error { return bkt.Put([]byte("poly_height"), raw) }) } + +func (w *BoltDB) GetPolyHeight() uint32 { + w.rwLock.RLock() + defer w.rwLock.RUnlock() + + var h uint32 + _ = w.db.View(func(tx *bolt.Tx) error { + bkt := tx.Bucket(BKTHeight) + raw := bkt.Get([]byte("poly_height")) + if len(raw) == 0 { + h = 0 + return nil + } + h = binary.LittleEndian.Uint32(raw) + return nil + }) + return h +} diff --git a/go.mod b/go.mod index 6ab23cf..f146ed6 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta github.com/magiconair/properties v1.8.1 + github.com/ontio/ontology v1.11.0 github.com/ontio/ontology-crypto v1.0.9 github.com/polynetwork/poly v0.0.0-20200715030435-4f1d1a0adb44 github.com/polynetwork/poly-go-sdk v0.0.0-20200817120957-365691ad3493 diff --git a/service/poly2zil.go b/service/poly2zil.go index f69ac4b..05ccb7d 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -17,6 +17,11 @@ import ( ) func (p *PolySyncManager) MonitorChain() { + if !p.init() { + log.Errorf("PolySyncManager MonitorChain - init error\n") + return + } + log.Infof("PolySyncManager MonitorChain - start scan block at height: %d\n", p.currentHeight) monitorTicker := time.NewTicker(time.Duration(p.cfg.PolyConfig.PolyMonitorInterval) * time.Second) var blockHandleResult bool diff --git a/service/polymanager.go b/service/polymanager.go index 6fa5d4a..047bfd5 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -7,6 +7,7 @@ import ( "github.com/Zilliqa/gozilliqa-sdk/crosschain/polynetwork" "github.com/Zilliqa/gozilliqa-sdk/crypto" "github.com/Zilliqa/gozilliqa-sdk/provider" + "github.com/ontio/ontology/common/log" "github.com/polynetwork/poly-go-sdk" "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/db" @@ -26,8 +27,26 @@ type PolySyncManager struct { senders []*ZilSender } -func (p *PolySyncManager) Run() { +func (p *PolySyncManager) init() bool { + if p.currentHeight > 0 { + log.Infof("PolySyncManager init - start height from flag: %d\n", p.currentHeight) + return true + } + + p.currentHeight = p.db.GetPolyHeight() + latestHeight := p.findLatestHeight() + if latestHeight > p.currentHeight { + p.currentHeight = latestHeight + log.Infof("PolyManager init - latest height from cross chain manager: %d\n", p.currentHeight) + return true + } + log.Infof("PolyManager init - latest height from DB: %d\n", p.currentHeight) + return true +} + +func (p *PolySyncManager) Run() { + go p.MonitorChain() } func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk *poly_go_sdk.PolySdk, boltDB *db.BoltDB, crossChainManager, crossChainManagerProxy string) (*PolySyncManager, error) { From 7c12929b057fb0cfe7dec70000eeb1b82b8ef8a6 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Fri, 22 Jan 2021 15:49:35 +0800 Subject: [PATCH 025/107] feat(zilliqamanager): init poly wallet infp --- cmd/run.go | 10 +++-- service/zilliqamanager.go | 84 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 5 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 97e7b6e..952483b 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -126,10 +126,14 @@ var runCmd = &cobra.Command{ return } - zilliqaManager := service.NewZilliqaSyncManager(cfg, zilSdk, boltDB) - polyManager, err := service.NewPolySyncManager(cfg, zilSdk, polySdk, boltDB, cfg.ZilConfig.CrossChainManagerContract, cfg.ZilConfig.CrossChainManagerProxyContract) + zilliqaManager, err := service.NewZilliqaSyncManager(cfg, zilSdk, polySdk, boltDB) if err != nil { - log.Errorf("init polymanager error: %s\n", err.Error()) + log.Errorf("init zilliqamanger error: %s\n", err.Error()) + return + } + polyManager, err1 := service.NewPolySyncManager(cfg, zilSdk, polySdk, boltDB, cfg.ZilConfig.CrossChainManagerContract, cfg.ZilConfig.CrossChainManagerProxyContract) + if err1 != nil { + log.Errorf("init polymanager error: %s\n", err1.Error()) return } diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 7ba9519..6fc1629 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -1,11 +1,18 @@ package service import ( + "encoding/binary" + "fmt" "github.com/Zilliqa/gozilliqa-sdk/account" "github.com/Zilliqa/gozilliqa-sdk/provider" poly "github.com/polynetwork/poly-go-sdk" + sdk "github.com/polynetwork/poly-go-sdk" + "github.com/polynetwork/poly/common" + scom "github.com/polynetwork/poly/native/service/header_sync/common" + autils "github.com/polynetwork/poly/native/service/utils" "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/db" + log "github.com/sirupsen/logrus" ) type ZilliqaSyncManager struct { @@ -14,6 +21,7 @@ type ZilliqaSyncManager struct { relaySyncHeight uint32 zilAccount *account.Account currentHeight uint64 + forceHeight uint64 zilSdk *provider.Provider crossChainManagerAddress string cfg *config.Config @@ -21,13 +29,51 @@ type ZilliqaSyncManager struct { exitChan chan int } -func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, boltDB *db.BoltDB) *ZilliqaSyncManager { - return &ZilliqaSyncManager{ +func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysdk *sdk.PolySdk, boltDB *db.BoltDB) (*ZilliqaSyncManager, error) { + var wallet *sdk.Wallet + var err error + if !common.FileExisted(cfg.PolyConfig.PolyWalletFile) { + wallet, err = polysdk.OpenWallet(cfg.PolyConfig.PolyWalletFile) + if err != nil { + return nil, err + } + } else { + wallet, err = polysdk.OpenWallet(cfg.PolyConfig.PolyWalletFile) + if err != nil { + log.Errorf("NewZilliqaSyncManager - wallet open error: %s", err.Error()) + return nil, err + } + } + signer, err := wallet.GetDefaultAccount([]byte(cfg.PolyConfig.PolyWalletPassword)) + if err != nil || signer == nil { + signer, err = wallet.NewDefaultSettingAccount([]byte(cfg.PolyConfig.PolyWalletPassword)) + if err != nil { + log.Errorf("NewETHManager - wallet password error") + return nil, err + } + + err = wallet.Save() + if err != nil { + return nil, err + } + } + log.Infof("NewZilliqaSyncManager - poly address: %s", signer.Address.ToBase58()) + zilliqaSyncManager := &ZilliqaSyncManager{ db: boltDB, cfg: cfg, + exitChan: make(chan int), zilSdk: zilSdk, currentHeight: uint64(cfg.ZilConfig.ZilStartHeight), crossChainManagerAddress: cfg.ZilConfig.CrossChainManagerContract, + polySigner: signer, + polySdk: polysdk, + } + + err = zilliqaSyncManager.init() + if err != nil { + return nil, err + } else { + return zilliqaSyncManager, nil } } @@ -35,3 +81,37 @@ func (s *ZilliqaSyncManager) Run() { go s.MonitorChain() go s.MonitorDeposit() } + +func (s *ZilliqaSyncManager) init() error { + // get latest height + latestHeight := s.findLatestHeight() + if latestHeight == 0 { + return fmt.Errorf("init - the genesis block has not synced!") + } + if s.forceHeight > 0 && s.forceHeight < latestHeight { + s.currentHeight = s.forceHeight + } else { + s.currentHeight = latestHeight + } + log.Infof("ZilliqaSyncManager init - start height: %d", s.currentHeight) + return nil +} + +// get latest height from polynetwork +func (s *ZilliqaSyncManager) findLatestHeight() uint64 { + // try to get key + var sideChainIdBytes [8]byte + binary.LittleEndian.PutUint64(sideChainIdBytes[:], s.cfg.ZilConfig.SideChainId) + contractAddress := autils.HeaderSyncContractAddress + key := append([]byte(scom.CURRENT_HEADER_HEIGHT), sideChainIdBytes[:]...) + // try to get storage + result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) + if err != nil { + return 0 + } + if result == nil || len(result) == 0 { + return 0 + } else { + return binary.LittleEndian.Uint64(result) + } +} From 643726057dc4ac50284d8b90ef658f288df40faa Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 17 Feb 2021 17:28:37 +0800 Subject: [PATCH 026/107] chore: update config relative --- .gitignore | 4 +++- cmd/run.go | 7 ++++--- config.yaml | 9 +++++---- config/config.go | 1 + service/polymanager.go | 6 ++++-- service/zilliqamanager.go | 9 ++++++--- wallet.dat | 2 +- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 6f06244..443b172 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ zilliqa-relayer .idea -bolt.bin \ No newline at end of file +bolt.bin +config.local.yaml +constants.xml \ No newline at end of file diff --git a/cmd/run.go b/cmd/run.go index 952483b..d2b0d3a 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -42,7 +42,7 @@ func initConfig() { viper.SetConfigFile(cfgFile) } else { viper.AddConfigPath("./") - viper.SetConfigName("config") + viper.SetConfigName("config.local") } viper.AutomaticEnv() @@ -96,6 +96,7 @@ var runCmd = &cobra.Command{ polyConfig := &config.POLYConfig{ PolyWalletFile: polyConfigMap["poly_wallet_file"].(string), PolyWalletPassword: polyConfigMap["poly_wallet_pwd"].(string), + PolyStartHeight: uint32(polyConfigMap["poly_start_height"].(int)), PolyMonitorInterval: uint32(polyConfigMap["poly_monitor_interval"].(int)), EntranceContractAddress: polyConfigMap["entrance_contract_address"].(string), RestUrl: polyConfigMap["rest_url"].(string), @@ -137,8 +138,8 @@ var runCmd = &cobra.Command{ return } - zilliqaManager.Run() - polyManager.Run() + zilliqaManager.Run(false) + polyManager.Run(true) service.WaitToExit() diff --git a/config.yaml b/config.yaml index c236a44..66d3eef 100644 --- a/config.yaml +++ b/config.yaml @@ -1,12 +1,12 @@ zil_config: - zil_api: https://polynetworkcc3dcb2-5-api.dev.z7a.xyz + zil_api: https://dev-api.zilliqa.com/ zil_chain_id: 333 zil_message_version: 1 - zil_start_height: 38 + zil_start_height: 0 zil_monitor_interval: 40 corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f cross_chain_manager_proxy_address: zil1urrkyfpww7rzhxh36m9nhksr5z73ragpar53nk - side_chain_id: 1 + side_chain_id: 2 key_store_path: keystore key_store_pwd_set: 7d48043742a1103042d327111746531ca26be9be: "xiaohuo" @@ -14,6 +14,7 @@ zil_config: poly_config: poly_wallet_file: wallet.dat poly_wallet_pwd: dummy + poly_start_height: 0 poly_monitor_interval: 40 entrance_contract_address: "0300000000000000000000000000000000000000" - rest_url: http://beta1.poly.network \ No newline at end of file + rest_url: http://localhost:20336 \ No newline at end of file diff --git a/config/config.go b/config/config.go index 89da2da..cfdeea4 100644 --- a/config/config.go +++ b/config/config.go @@ -27,6 +27,7 @@ type ZILConfig struct { type POLYConfig struct { PolyWalletFile string PolyWalletPassword string + PolyStartHeight uint32 PolyMonitorInterval uint32 EntranceContractAddress string RestUrl string diff --git a/service/polymanager.go b/service/polymanager.go index 047bfd5..9aef994 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -45,8 +45,10 @@ func (p *PolySyncManager) init() bool { return true } -func (p *PolySyncManager) Run() { - go p.MonitorChain() +func (p *PolySyncManager) Run(enable bool) { + if enable { + go p.MonitorChain() + } } func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk *poly_go_sdk.PolySdk, boltDB *db.BoltDB, crossChainManager, crossChainManagerProxy string) (*PolySyncManager, error) { diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 6fc1629..2b325a1 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -70,6 +70,7 @@ func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysd } err = zilliqaSyncManager.init() + err = nil if err != nil { return nil, err } else { @@ -77,9 +78,11 @@ func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysd } } -func (s *ZilliqaSyncManager) Run() { - go s.MonitorChain() - go s.MonitorDeposit() +func (s *ZilliqaSyncManager) Run(enable bool) { + if enable { + go s.MonitorChain() + go s.MonitorDeposit() + } } func (s *ZilliqaSyncManager) init() error { diff --git a/wallet.dat b/wallet.dat index 1646009..eaf8024 100644 --- a/wallet.dat +++ b/wallet.dat @@ -1 +1 @@ -{"name":"MyWallet","version":"1.1","scrypt":{"p":8,"n":16384,"r":8,"dkLen":64},"accounts":[{"address":"AVEHisrXBo5GUGU7HVpCWp59eyjGEyDRrT","enc-alg":"aes-256-gcm","key":"FO/fRk6Olt2598U+aqcwLGB5iMZd7346r87kjIAhMLCh8z1+JqWrZpLYf20ZP8CK","algorithm":"ECDSA","salt":"0xPZtgwpes7kEoXn9VO/gQ==","parameters":{"curve":""},"label":"","publicKey":"12050373c6373bfd436992b4de52a8bb8ef544a50fd24dd2ebb99d6acd1f52ac3d4bb8","signatureScheme":"SHA256withECDSA","isDefault":true,"lock":false}]} \ No newline at end of file +{"name":"MyWallet","version":"1.1","scrypt":{"p":8,"n":16384,"r":8,"dkLen":64},"accounts":[{"address":"AXkyV73SHLLNKPkas644821MkRBM25ceLr","enc-alg":"aes-256-gcm","key":"y8uBh/Jv1cCEAxIT3iZaKZRd114RANsbOG1fEmnoiza570z/+QESBP14JxxykqtB","algorithm":"ECDSA","salt":"f698HosIenC1QdSxXREQlA==","parameters":{"curve":""},"label":"","publicKey":"1205032bddd046875a0f4c5d7cedefbe73299cf2e4365572ea2ddb4b6a466b0913027b","signatureScheme":"SHA256withECDSA","isDefault":true,"lock":false}]} \ No newline at end of file From d90157455f355f62171be90e28676136c8b842f1 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 17 Feb 2021 18:58:03 +0800 Subject: [PATCH 027/107] feat: support target contract setting --- cmd/run.go | 20 ++++++++++++++++++-- config.yaml | 5 +++-- service/poly2zil.go | 23 +++++++++++++++++------ service/polymanager.go | 2 +- target_contracts.json | 8 ++++++++ wallet.dat | 2 +- 6 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 target_contracts.json diff --git a/cmd/run.go b/cmd/run.go index d2b0d3a..72a1f1e 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -10,6 +10,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" + "io/ioutil" "os" ) @@ -79,6 +80,19 @@ var runCmd = &cobra.Command{ Long: `Run zilliqa relayer`, Run: func(cmd *cobra.Command, args []string) { zilConfigMap := viper.GetStringMap("zil_config") + targetContractsPath := viper.GetString("target_contracts") + bytes, e := ioutil.ReadFile(targetContractsPath) + if e != nil { + log.Errorf("read target contracts error: %s, path: %s\n", e.Error(), targetContractsPath) + return + } + var targetContract []map[string]map[string][]uint64 + e2 := json.Unmarshal(bytes, &targetContract) + if e2 != nil { + log.Errorf("unmarshal target contracts error: %s\n", e2.Error()) + return + } + log.Info(targetContract) zilConfig := &config.ZILConfig{ ZilApiEndpoint: zilConfigMap["zil_api"].(string), ZilChainId: zilConfigMap["zil_chain_id"].(int), @@ -93,6 +107,7 @@ var runCmd = &cobra.Command{ } polyConfigMap := viper.GetStringMap("poly_config") + polyConfig := &config.POLYConfig{ PolyWalletFile: polyConfigMap["poly_wallet_file"].(string), PolyWalletPassword: polyConfigMap["poly_wallet_pwd"].(string), @@ -103,8 +118,9 @@ var runCmd = &cobra.Command{ } cfg := &config.Config{ - ZilConfig: zilConfig, - PolyConfig: polyConfig, + ZilConfig: zilConfig, + PolyConfig: polyConfig, + TargetContracts: targetContract, } cfgStr, _ := json.Marshal(cfg) diff --git a/config.yaml b/config.yaml index 66d3eef..7893363 100644 --- a/config.yaml +++ b/config.yaml @@ -14,7 +14,8 @@ zil_config: poly_config: poly_wallet_file: wallet.dat poly_wallet_pwd: dummy - poly_start_height: 0 + poly_start_height: 1 poly_monitor_interval: 40 entrance_contract_address: "0300000000000000000000000000000000000000" - rest_url: http://localhost:20336 \ No newline at end of file + rest_url: http://localhost:20336 + target_contracts: target_contracts.json \ No newline at end of file diff --git a/service/poly2zil.go b/service/poly2zil.go index 05ccb7d..7473dee 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -63,6 +63,10 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { log.Errorf("PolySyncManager handleBlockHeader - GetNodeHeader on height :%d failed", height) return false } + /************************* to be deleted ******************************/ + hdrs, _ := json.Marshal(hdr) + log.Infof("PolySyncManager handleBlockHeader - height: %d, header: %s", height, hdrs) + /************************* to be deleted ******************************/ isCurr := lastEpoch < height+1 info := &vconfig.VbftBlockInfo{} if err := json.Unmarshal(hdr.ConsensusPayload, info); err != nil { @@ -89,6 +93,10 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { log.Errorf("PolySyncManager handleDepositEvents - get block event at height:%d error: %s", height, err.Error()) return false } + /************************* to be deleted ******************************/ + eventss, _ := json.Marshal(events) + log.Infof("PolySyncManager handleBlockHeader - height: %d, events: %s", height, eventss) + /************************* to be deleted ******************************/ for _, event := range events { for _, notify := range event.Notify { if notify.ContractAddress == p.cfg.PolyConfig.EntranceContractAddress { @@ -232,10 +240,13 @@ func (p *PolySyncManager) findLatestHeight() uint32 { return 0 } - height, err2 := strconv.ParseUint(epochStartHeightRep.Result.CurEpochStartHeight, 10, 32) - if err2 != nil { - log.Errorf("PolySyncManager FindLatestHeight - faild to parse epoch start height: %s\n", err2.Error()) - return 0 - } - return uint32(height) + return 0 + // todo + //log.Info(epochStartHeightRep.Result.CurEpochStartHeight) + //height, err2 := strconv.ParseUint(epochStartHeightRep.Result.CurEpochStartHeight, 10, 32) + //if err2 != nil { + // log.Errorf("PolySyncManager FindLatestHeight - faild to parse epoch start height: %s\n", err2.Error()) + // return 0 + //} + //return uint32(height) } diff --git a/service/polymanager.go b/service/polymanager.go index 9aef994..4d7b27a 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -101,7 +101,7 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * } return &PolySyncManager{ - currentHeight: cfg.PolyConfig.PolyMonitorInterval, + currentHeight: cfg.PolyConfig.PolyStartHeight, polySdk: polySdk, exitChan: make(chan int), cfg: cfg, diff --git a/target_contracts.json b/target_contracts.json new file mode 100644 index 0000000..b51cb2f --- /dev/null +++ b/target_contracts.json @@ -0,0 +1,8 @@ +[ + { + "zil16munf2fc9zl4q22frjvaghe96up5r7en62s4jk": { + "inbound": [6], + "outbound": [6] + } + } +] \ No newline at end of file diff --git a/wallet.dat b/wallet.dat index eaf8024..c27ee36 100644 --- a/wallet.dat +++ b/wallet.dat @@ -1 +1 @@ -{"name":"MyWallet","version":"1.1","scrypt":{"p":8,"n":16384,"r":8,"dkLen":64},"accounts":[{"address":"AXkyV73SHLLNKPkas644821MkRBM25ceLr","enc-alg":"aes-256-gcm","key":"y8uBh/Jv1cCEAxIT3iZaKZRd114RANsbOG1fEmnoiza570z/+QESBP14JxxykqtB","algorithm":"ECDSA","salt":"f698HosIenC1QdSxXREQlA==","parameters":{"curve":""},"label":"","publicKey":"1205032bddd046875a0f4c5d7cedefbe73299cf2e4365572ea2ddb4b6a466b0913027b","signatureScheme":"SHA256withECDSA","isDefault":true,"lock":false}]} \ No newline at end of file +{"name":"MyWallet","version":"1.1","scrypt":{"p":8,"n":16384,"r":8,"dkLen":64},"accounts":[{"address":"AXkyV73SHLLNKPkas644821MkRBM25ceLr","enc-alg":"aes-256-gcm","key":"y8uBh/Jv1cCEAxIT3iZaKZRd114RANsbOG1fEmnoiza570z/+QESBP14JxxykqtB","algorithm":"ECDSA","salt":"f698HosIenC1QdSxXREQlA==","parameters":{"curve":""},"label":"","publicKey":"1205032bddd046875a0f4c5d7cedefbe73299cf2e4365572ea2ddb4b6a466b0913027b","signatureScheme":"SHA256withECDSA","isDefault":true,"lock":false},{"address":"AWezM2zWAc1L9zHp122pRKzxs19mcSrSY5","enc-alg":"aes-256-gcm","key":"9ppCSGvBURnyPgKch7wc5CXl/YvAx9LZ1QfWxDTPN52WNOgjp43swbzxlg8yuBh+","algorithm":"ECDSA","salt":"DIJGj+utyd/SUyTXOhcbiQ==","parameters":{"curve":"P-256"},"label":"","publicKey":"022fca30a394a7249a8fe380f41640d946910959f265a1416dfb290d60308acbd6","signatureScheme":"SHA256withECDSA","isDefault":false,"lock":false},{"address":"AadiWhZjzAc7VGQHjHeTTaXbEdynQ2Z3x2","enc-alg":"aes-256-gcm","key":"SF30LxS8dZhcqS8FGlK/yHlu1wYmkIq/paUsYOIkmf5XnJYZPP8prp6l/u6gW5M8","algorithm":"ECDSA","salt":"FkQCQUg/lR2IgedR/lulOQ==","parameters":{"curve":"P-256"},"label":"","publicKey":"0300fffce1c29d8246c08da3327aed0d07700ab155786b23b505be672207761317","signatureScheme":"SHA256withECDSA","isDefault":false,"lock":false},{"address":"ANBye6W1i7D5bqMJUKfyvEQjJd4nctgARk","enc-alg":"aes-256-gcm","key":"2BYoCFhw8/ET1tvrE6Q26xS0cA8HsWCjiSoT9z2dwcMLkq2MxiKaXOdpOVE3DfsD","algorithm":"ECDSA","salt":"SKYvbVxZ/J2BfODuXQzl0A==","parameters":{"curve":"P-256"},"label":"","publicKey":"026ec74fc15eb7f2d27cb606524491fc8cff18126c486416b958448f7ebbe2de71","signatureScheme":"SHA256withECDSA","isDefault":false,"lock":false},{"address":"AG9T5VUoAEttkiUv8YzKHMKMcouojSixtf","enc-alg":"aes-256-gcm","key":"FKOQsfEduP+NiPXshp5zOm7Gz6kTnIIPd1qGB9+r497Op1lk+OxBHqyetZVvL6pL","algorithm":"ECDSA","salt":"AfKCyBh1d1xhyNN+rLPrsA==","parameters":{"curve":"P-256"},"label":"","publicKey":"02dee4455378f2a41b787a93ceec9e1d26466006bd135906c406806d849e4ee17b","signatureScheme":"SHA256withECDSA","isDefault":false,"lock":false},{"address":"AV6UgAiH63eDTx1PV5JMYWFm6xnKyqnaxA","enc-alg":"aes-256-gcm","key":"KK8vjSVXBboiiaGIAZ4GYTd51vmV7+LrfNq5nm+MF0eXeozS3gqjaItNpSHCCUmg","algorithm":"ECDSA","salt":"kQcpQMLgDRDDLfxJVxqKWQ==","parameters":{"curve":"P-256"},"label":"","publicKey":"02dd1156ae4d7dc9cc65a50908c5dd1368f5b2267f47a166520cb0ec3aa2f32736","signatureScheme":"SHA256withECDSA","isDefault":false,"lock":false}]} \ No newline at end of file From 55420537d973655dda6396d559110b16b656400a Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Fri, 19 Feb 2021 22:50:54 +0800 Subject: [PATCH 028/107] feat(zilmamanger): support force height --- cmd/run.go | 5 +++-- config/config.go | 1 + service/poly2zil.go | 12 ++++++++++++ service/zilliqamanager.go | 1 + target_contracts.json | 4 ++-- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 72a1f1e..b0e1822 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -98,6 +98,7 @@ var runCmd = &cobra.Command{ ZilChainId: zilConfigMap["zil_chain_id"].(int), ZilMessageVersion: zilConfigMap["zil_message_version"].(int), ZilStartHeight: uint32(zilConfigMap["zil_start_height"].(int)), + ZilForceHeight: uint64(zilConfigMap["zil_force_height"].(int)), ZilMonitorInterval: uint32(zilConfigMap["zil_monitor_interval"].(int)), SideChainId: uint64(zilConfigMap["side_chain_id"].(int)), CrossChainManagerContract: zilConfigMap["corss_chain_manager_address"].(string), @@ -154,8 +155,8 @@ var runCmd = &cobra.Command{ return } - zilliqaManager.Run(false) - polyManager.Run(true) + zilliqaManager.Run(true) + polyManager.Run(false) service.WaitToExit() diff --git a/config/config.go b/config/config.go index cfdeea4..aa079ef 100644 --- a/config/config.go +++ b/config/config.go @@ -17,6 +17,7 @@ type ZILConfig struct { ZilMessageVersion int ZilMonitorInterval uint32 ZilStartHeight uint32 + ZilForceHeight uint64 SideChainId uint64 CrossChainManagerContract string CrossChainManagerProxyContract string diff --git a/service/poly2zil.go b/service/poly2zil.go index 7473dee..1dc8ec6 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -125,6 +125,18 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { // todo assuming ToContractAddress is not bech32 // handle error toContractStr, _ := bech32.ToBech32Address(util.EncodeHex(param.MakeTxParam.ToContractAddress)) + /************************* todo delete now ******************************/ + //log.Info("catched!") + //params,_ := json.Marshal(param) + //log.Info(string(params)) + //toAddr := util.EncodeHex(param.MakeTxParam.ToContractAddress) + //log.Info("toContract: " + toAddr) + //if strings.Contains(strings.ToLower(toAddr),"46de"){ + // os.Exit(0) + //} else { + // break + //} + /************************* todo delete now ******************************/ for _, v := range p.cfg.TargetContracts { toChainIdArr, ok := v[toContractStr] if ok { diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 2b325a1..568a9c2 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -64,6 +64,7 @@ func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysd exitChan: make(chan int), zilSdk: zilSdk, currentHeight: uint64(cfg.ZilConfig.ZilStartHeight), + forceHeight: cfg.ZilConfig.ZilForceHeight, crossChainManagerAddress: cfg.ZilConfig.CrossChainManagerContract, polySigner: signer, polySdk: polysdk, diff --git a/target_contracts.json b/target_contracts.json index b51cb2f..aa7f9c0 100644 --- a/target_contracts.json +++ b/target_contracts.json @@ -1,7 +1,7 @@ [ { - "zil16munf2fc9zl4q22frjvaghe96up5r7en62s4jk": { - "inbound": [6], + "zil1mzh88cr92t38qdqtvw5te2leyaap4tyeu8j4mg": { + "inbound": [3], "outbound": [6] } } From d337d8f629726817445f3473255cc264f4c64213 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Sat, 20 Feb 2021 00:51:07 +0800 Subject: [PATCH 029/107] feat(zilmanager): handle block header --- go.mod | 2 +- go.sum | 2 ++ service/zil2poly.go | 19 ++++++++++++++++++- service/zilliqamanager.go | 4 +++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f146ed6..eb6523d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43 + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210219095216-01f23f46ac19 github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta github.com/magiconair/properties v1.8.1 diff --git a/go.sum b/go.sum index 54c06a4..72cf063 100644 --- a/go.sum +++ b/go.sum @@ -52,6 +52,8 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.0 h1:pxINq2woI80BQkMb8dnIVsHw0pk6AkEnZ7DNE github.com/Zilliqa/gozilliqa-sdk v1.2.0/go.mod h1:eSYp2T6f0apnuW8TzhV3f6Aff2SE8Dwio++U4ha4yEM= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43 h1:m90pmiBsPC1B8CFLWMU6EMfqtVt6lZgeCAah7yuWvJA= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210219095216-01f23f46ac19 h1:aSEnsuYQU7BeoKTHIrZpEU7mM5Le5pCgD83T1H9mECs= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210219095216-01f23f46ac19/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/service/zil2poly.go b/service/zil2poly.go index 2e54e51..feea898 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -1,9 +1,13 @@ package service import ( + "bytes" "github.com/Zilliqa/gozilliqa-sdk/bech32" + "github.com/Zilliqa/gozilliqa-sdk/core" "github.com/Zilliqa/gozilliqa-sdk/util" "github.com/polynetwork/poly/common" + scom "github.com/polynetwork/poly/native/service/header_sync/common" + autils "github.com/polynetwork/poly/native/service/utils" "github.com/polynetwork/zilliqa-relayer/tools" log "github.com/sirupsen/logrus" "math/big" @@ -42,7 +46,20 @@ func (s *ZilliqaSyncManager) handleNewBlock(height uint64) bool { } func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { - // todo + log.Infof("ZilliqaSyncManager handle new block header: %d\n", height) + txBlockT, err := s.zilSdk.GetTxBlockVerbose(strconv.FormatUint(height, 10)) + if err != nil { + log.Errorf("ZilliqaSyncManager - handleBlockHeader error: %s", err) + } + hdr := core.NewTxBlockFromTxBlockT(txBlockT).BlockHeader + hdrHash := util.Sha256(hdr.Serialize()) + log.Infof("ZilliqaSyncManager handleBlockHeader - header hash: %s\n", util.EncodeHex(hdrHash)) + raw, _ := s.polySdk.GetStorage(autils.HeaderSyncContractAddress.ToHexString(), + append(append([]byte(scom.MAIN_CHAIN), autils.GetUint64Bytes(s.cfg.ZilConfig.SideChainId)...), autils.GetUint64Bytes(height)...)) + if len(raw) == 0 || bytes.Equal(raw, hdrHash) { + // todo change header4sync to []byte (json bytes), which will require sdk to export all fields + s.header4sync = append(s.header4sync, hdr) + } return true } diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 568a9c2..7ecfdbe 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "fmt" "github.com/Zilliqa/gozilliqa-sdk/account" + "github.com/Zilliqa/gozilliqa-sdk/core" "github.com/Zilliqa/gozilliqa-sdk/provider" poly "github.com/polynetwork/poly-go-sdk" sdk "github.com/polynetwork/poly-go-sdk" @@ -27,6 +28,7 @@ type ZilliqaSyncManager struct { cfg *config.Config db *db.BoltDB exitChan chan int + header4sync []*core.TxBlockHeader } func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysdk *sdk.PolySdk, boltDB *db.BoltDB) (*ZilliqaSyncManager, error) { @@ -82,7 +84,7 @@ func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysd func (s *ZilliqaSyncManager) Run(enable bool) { if enable { go s.MonitorChain() - go s.MonitorDeposit() + //go s.MonitorDeposit() } } From bb964da4e8907d25272e9c2fc3ebb65d4151b0be Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Mon, 22 Feb 2021 00:16:35 +0800 Subject: [PATCH 030/107] feat(zilmanager): commitHeader --- cmd/run.go | 1 + config/config.go | 1 + go.mod | 2 +- go.sum | 4 ++ service/zil2poly.go | 83 +++++++++++++++++++++++++++++++++++++-- service/zilliqamanager.go | 3 +- 6 files changed, 88 insertions(+), 6 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index b0e1822..a16a203 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -100,6 +100,7 @@ var runCmd = &cobra.Command{ ZilStartHeight: uint32(zilConfigMap["zil_start_height"].(int)), ZilForceHeight: uint64(zilConfigMap["zil_force_height"].(int)), ZilMonitorInterval: uint32(zilConfigMap["zil_monitor_interval"].(int)), + ZilHeadersPerBatch: uint32(zilConfigMap["zil_headers_per_batch"].(int)), SideChainId: uint64(zilConfigMap["side_chain_id"].(int)), CrossChainManagerContract: zilConfigMap["corss_chain_manager_address"].(string), CrossChainManagerProxyContract: zilConfigMap["cross_chain_manager_proxy_address"].(string), diff --git a/config/config.go b/config/config.go index aa079ef..679b516 100644 --- a/config/config.go +++ b/config/config.go @@ -16,6 +16,7 @@ type ZILConfig struct { ZilChainId int ZilMessageVersion int ZilMonitorInterval uint32 + ZilHeadersPerBatch uint32 ZilStartHeight uint32 ZilForceHeight uint64 SideChainId uint64 diff --git a/go.mod b/go.mod index eb6523d..4d6b6a5 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210219095216-01f23f46ac19 + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134949-c70ae6ea83ba github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta github.com/magiconair/properties v1.8.1 diff --git a/go.sum b/go.sum index 72cf063..f1bb953 100644 --- a/go.sum +++ b/go.sum @@ -54,6 +54,10 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43 h1:m90pmiB github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210219095216-01f23f46ac19 h1:aSEnsuYQU7BeoKTHIrZpEU7mM5Le5pCgD83T1H9mECs= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210219095216-01f23f46ac19/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134150-463aafc8ddfd h1:/bf/8Lr35tn6WZY6cV25CL9Xv2Os4L59OMa+FQu5E4w= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134150-463aafc8ddfd/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134949-c70ae6ea83ba h1:WMfTz//M7d4MyqYhsTw94lu+0pSL8uhqLAMQuaSV2iw= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134949-c70ae6ea83ba/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/service/zil2poly.go b/service/zil2poly.go index feea898..e41ebc3 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -2,6 +2,7 @@ package service import ( "bytes" + "encoding/json" "github.com/Zilliqa/gozilliqa-sdk/bech32" "github.com/Zilliqa/gozilliqa-sdk/core" "github.com/Zilliqa/gozilliqa-sdk/util" @@ -12,6 +13,7 @@ import ( log "github.com/sirupsen/logrus" "math/big" "strconv" + "strings" "time" ) @@ -51,18 +53,80 @@ func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { if err != nil { log.Errorf("ZilliqaSyncManager - handleBlockHeader error: %s", err) } - hdr := core.NewTxBlockFromTxBlockT(txBlockT).BlockHeader - hdrHash := util.Sha256(hdr.Serialize()) + blockHeader := core.NewTxBlockFromTxBlockT(txBlockT).BlockHeader + rawHdr, _ := json.Marshal(blockHeader) + hdrHash := util.Sha256(blockHeader.Serialize()) log.Infof("ZilliqaSyncManager handleBlockHeader - header hash: %s\n", util.EncodeHex(hdrHash)) raw, _ := s.polySdk.GetStorage(autils.HeaderSyncContractAddress.ToHexString(), append(append([]byte(scom.MAIN_CHAIN), autils.GetUint64Bytes(s.cfg.ZilConfig.SideChainId)...), autils.GetUint64Bytes(height)...)) if len(raw) == 0 || bytes.Equal(raw, hdrHash) { // todo change header4sync to []byte (json bytes), which will require sdk to export all fields - s.header4sync = append(s.header4sync, hdr) + s.header4sync = append(s.header4sync, rawHdr) } return true } +func (s *ZilliqaSyncManager) commitHeader() int { + tx, err := s.polySdk.Native.Hs.SyncBlockHeader( + s.cfg.ZilConfig.SideChainId, + s.polySigner.Address, + s.header4sync, + s.polySigner, + ) + + if err != nil { + errDesc := err.Error() + if strings.Contains(errDesc, "get the parent block failed") || strings.Contains(errDesc, "missing required field") { + log.Warnf("commitHeader - send transaction to poly chain err: %s", errDesc) + s.rollBackToCommAncestor() + return 0 + } else { + log.Errorf("commitHeader - send transaction to poly chain err: %s", errDesc) + return 1 + } + } + + tick := time.NewTicker(100 * time.Millisecond) + var h uint32 + for range tick.C { + h, _ = s.polySdk.GetBlockHeightByTxHash(tx.ToHexString()) + curr, _ := s.polySdk.GetCurrentBlockHeight() + if h > 0 && curr > h { + break + } + } + + log.Infof("commitHeader - send transaction %s to poly chain and confirmed on height %d", tx.ToHexString(), h) + s.header4sync = make([][]byte, 0) + return 0 +} + +func (s *ZilliqaSyncManager) rollBackToCommAncestor() { + for ; ; s.currentHeight-- { + raw, err := s.polySdk.GetStorage(autils.HeaderSyncContractAddress.ToHexString(), + append(append([]byte(scom.MAIN_CHAIN), autils.GetUint64Bytes(s.cfg.ZilConfig.SideChainId)...), autils.GetUint64Bytes(s.currentHeight)...)) + if len(raw) == 0 || err != nil { + continue + } + txBlockT, err2 := s.zilSdk.GetTxBlockVerbose(strconv.FormatUint(s.currentHeight, 10)) + if err2 != nil { + log.Errorf("rollBackToCommAncestor - failed to get header by number, so we wait for one second to retry: %v", err2) + time.Sleep(time.Second) + s.currentHeight++ + continue + } + blockHeader := core.NewTxBlockFromTxBlockT(txBlockT).BlockHeader + if bytes.Equal(util.Sha256(blockHeader.Serialize()), raw) { + bs, _ := json.Marshal(blockHeader) + log.Infof("rollBackToCommAncestor - find the common ancestor: %s(number: %d)", bs, s.currentHeight) + break + } + + s.header4sync = make([][]byte, 0) + + } +} + // the workflow is: user -> LockProxy on zilliqa -> Cross Chain Manager -> emit event // so here we need to filter out those transactions related to cross chain manager // and parse the events, store them to local db, and commit them to the polynetwork @@ -114,6 +178,7 @@ func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { func (s *ZilliqaSyncManager) MonitorChain() { log.Infof("ZilliqaSyncManager MonitorChain - start scan block at height: %d\n", s.currentHeight) fetchBlockTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) + var blockHandleResult bool for { select { case <-fetchBlockTicker.C: @@ -132,9 +197,21 @@ func (s *ZilliqaSyncManager) MonitorChain() { continue } + blockHandleResult = true for s.currentHeight < blockNumber { s.handleNewBlock(s.currentHeight + 1) s.currentHeight++ + + if uint32(len(s.header4sync)) > s.cfg.ZilConfig.ZilHeadersPerBatch { + if res := s.commitHeader(); res != 0 { + blockHandleResult = false + break + } + } + } + + if blockHandleResult && len(s.header4sync) > 0 { + s.commitHeader() } case <-s.exitChan: diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 7ecfdbe..07a3192 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -4,7 +4,6 @@ import ( "encoding/binary" "fmt" "github.com/Zilliqa/gozilliqa-sdk/account" - "github.com/Zilliqa/gozilliqa-sdk/core" "github.com/Zilliqa/gozilliqa-sdk/provider" poly "github.com/polynetwork/poly-go-sdk" sdk "github.com/polynetwork/poly-go-sdk" @@ -28,7 +27,7 @@ type ZilliqaSyncManager struct { cfg *config.Config db *db.BoltDB exitChan chan int - header4sync []*core.TxBlockHeader + header4sync [][]byte } func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysdk *sdk.PolySdk, boltDB *db.BoltDB) (*ZilliqaSyncManager, error) { From 4ffdaa9048935cb81a1370175eada49bcd40cc0e Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Mon, 22 Feb 2021 08:24:55 +0800 Subject: [PATCH 031/107] feat(zilmanager): commit txblock and ds comm --- go.mod | 2 +- go.sum | 2 ++ service/zil2poly.go | 37 +++++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 4d6b6a5..2a70f4c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134949-c70ae6ea83ba + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221223316-fa21b26136c3 github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta github.com/magiconair/properties v1.8.1 diff --git a/go.sum b/go.sum index f1bb953..004751d 100644 --- a/go.sum +++ b/go.sum @@ -58,6 +58,8 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134150-463aafc8ddfd h1:/bf/8Lr github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134150-463aafc8ddfd/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134949-c70ae6ea83ba h1:WMfTz//M7d4MyqYhsTw94lu+0pSL8uhqLAMQuaSV2iw= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134949-c70ae6ea83ba/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= +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/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/service/zil2poly.go b/service/zil2poly.go index e41ebc3..f2c2682 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -53,15 +53,16 @@ func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { if err != nil { log.Errorf("ZilliqaSyncManager - handleBlockHeader error: %s", err) } - blockHeader := core.NewTxBlockFromTxBlockT(txBlockT).BlockHeader - rawHdr, _ := json.Marshal(blockHeader) - hdrHash := util.Sha256(blockHeader.Serialize()) - log.Infof("ZilliqaSyncManager handleBlockHeader - header hash: %s\n", util.EncodeHex(hdrHash)) + block := core.NewTxBlockFromTxBlockT(txBlockT) + // todo actually here we need to commit block and its dscomm, in order to verify + rawBlock, _ := json.Marshal(block) + + blockHash := util.Sha256(block.Serialize()) + log.Infof("ZilliqaSyncManager handleBlockHeader - header hash: %s\n", util.EncodeHex(blockHash)) raw, _ := s.polySdk.GetStorage(autils.HeaderSyncContractAddress.ToHexString(), append(append([]byte(scom.MAIN_CHAIN), autils.GetUint64Bytes(s.cfg.ZilConfig.SideChainId)...), autils.GetUint64Bytes(height)...)) - if len(raw) == 0 || bytes.Equal(raw, hdrHash) { - // todo change header4sync to []byte (json bytes), which will require sdk to export all fields - s.header4sync = append(s.header4sync, rawHdr) + if len(raw) == 0 || bytes.Equal(raw, blockHash) { + s.header4sync = append(s.header4sync, rawBlock) } return true } @@ -133,8 +134,13 @@ func (s *ZilliqaSyncManager) rollBackToCommAncestor() { func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { transactions, err := s.zilSdk.GetTxnBodiesForTxBlock(strconv.FormatUint(height, 10)) if err != nil { - log.Infof("ZilliqaSyncManager get transactions for tx block %d failed: %s\n", height, err.Error()) - return false + if strings.Contains(err.Error(), "TxBlock has no transactions") { + log.Infof("ZilliqaSyncManager no transaction in block %d\n", height) + return true + } else { + log.Infof("ZilliqaSyncManager get transactions for tx block %d failed: %s\n", height, err.Error()) + return false + } } for _, transaction := range transactions { @@ -202,16 +208,19 @@ func (s *ZilliqaSyncManager) MonitorChain() { s.handleNewBlock(s.currentHeight + 1) s.currentHeight++ + // todo enable this if uint32(len(s.header4sync)) > s.cfg.ZilConfig.ZilHeadersPerBatch { - if res := s.commitHeader(); res != 0 { - blockHandleResult = false - break - } + log.Infof("ZilliqaSyncManager MonitorChain - commit header") + //if res := s.commitHeader(); res != 0 { + // blockHandleResult = false + // break + //} } } if blockHandleResult && len(s.header4sync) > 0 { - s.commitHeader() + // todo enable this + // s.commitHeader() } case <-s.exitChan: From 094ce4105fd88b8ee730949f585444d3abde0385 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 23 Feb 2021 23:14:34 +0800 Subject: [PATCH 032/107] feat: support ds block commit --- go.mod | 2 +- go.sum | 4 ++++ service/zil2poly.go | 47 ++++++++++++++++++++++++++++++++++----- service/zilliqamanager.go | 1 + 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 2a70f4c..00ee5a9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221223316-fa21b26136c3 + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222044512-f9f981909bf0 github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta github.com/magiconair/properties v1.8.1 diff --git a/go.sum b/go.sum index 004751d..5a99d18 100644 --- a/go.sum +++ b/go.sum @@ -60,6 +60,10 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134949-c70ae6ea83ba h1:WMfTz// github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134949-c70ae6ea83ba/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= 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.20210222003933-7691f5ca42a2 h1:faO7UGk2+OU/NItQMQPeJR2Pw9DkCCw3mhJVEGsodcQ= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222003933-7691f5ca42a2/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/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/service/zil2poly.go b/service/zil2poly.go index f2c2682..b632832 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -48,16 +48,39 @@ func (s *ZilliqaSyncManager) handleNewBlock(height uint64) bool { } func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { - log.Infof("ZilliqaSyncManager handle new block header: %d\n", height) + log.Infof("ZilliqaSyncManager handle new block header height is: %d\n", height) txBlockT, err := s.zilSdk.GetTxBlockVerbose(strconv.FormatUint(height, 10)) if err != nil { log.Errorf("ZilliqaSyncManager - handleBlockHeader error: %s", err) + return false + } + txBlock := core.NewTxBlockFromTxBlockT(txBlockT) + + if txBlock.BlockHeader.DSBlockNum > s.currentDsBlockNum { + dsBlock, err := s.zilSdk.GetDsBlockVerbose(strconv.FormatUint(txBlock.BlockHeader.DSBlockNum, 10)) + if err != nil { + log.Errorf("ZilliqaSyncManager - handleBlockHeader get ds block error: %s", err) + return false + } + txBlockOrDsBlock := core.TxBlockOrDsBlock{ + DsBlock: core.NewDsBlockFromDsBlockT(dsBlock), + } + rawBlock, _ := json.Marshal(txBlockOrDsBlock) + log.Infof("ZilliqaSyncManager handle new block header: %s\n", rawBlock) + s.header4sync = append(s.header4sync, rawBlock) + s.currentDsBlockNum++ } - block := core.NewTxBlockFromTxBlockT(txBlockT) - // todo actually here we need to commit block and its dscomm, in order to verify - rawBlock, _ := json.Marshal(block) - blockHash := util.Sha256(block.Serialize()) + txBlockOrDsBlock := core.TxBlockOrDsBlock{ + TxBlock: txBlock, + } + rawBlock, err2 := json.Marshal(txBlockOrDsBlock) + if err2 != nil { + log.Errorf("ZilliqaSyncManager - handleBlockHeader marshal block error: %s", err2) + return false + } + log.Debugf("ZilliqaSyncManager handle new block header: %s\n", rawBlock) + blockHash := txBlock.BlockHash[:] log.Infof("ZilliqaSyncManager handleBlockHeader - header hash: %s\n", util.EncodeHex(blockHash)) raw, _ := s.polySdk.GetStorage(autils.HeaderSyncContractAddress.ToHexString(), append(append([]byte(scom.MAIN_CHAIN), autils.GetUint64Bytes(s.cfg.ZilConfig.SideChainId)...), autils.GetUint64Bytes(height)...)) @@ -128,6 +151,20 @@ func (s *ZilliqaSyncManager) rollBackToCommAncestor() { } } + +// should be the same as relayer side +type ZILProof struct { + AccountProof []string `json:"accountProof"` + StorageProofs []StorageProof `json:"storageProof"` +} + +// key should be storage key (in zilliqa) +type StorageProof struct { + Key []byte `json:"key"` + Value []byte `json:"value"` + Proof []string `json:"proof"` +} + // the workflow is: user -> LockProxy on zilliqa -> Cross Chain Manager -> emit event // so here we need to filter out those transactions related to cross chain manager // and parse the events, store them to local db, and commit them to the polynetwork diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 07a3192..751529a 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -21,6 +21,7 @@ type ZilliqaSyncManager struct { relaySyncHeight uint32 zilAccount *account.Account currentHeight uint64 + currentDsBlockNum uint64 forceHeight uint64 zilSdk *provider.Provider crossChainManagerAddress string From bad0a21af61ea2f24ae496c6c8c931f3e547afb6 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 24 Feb 2021 00:26:05 +0800 Subject: [PATCH 033/107] feat(zilmananger): handleLockDepositEvents --- db/db.go | 34 ++++ service/zil2poly.go | 366 +++++++++++++++++++++++++++++--------------- 2 files changed, 275 insertions(+), 125 deletions(-) diff --git a/db/db.go b/db/db.go index 7c3aecd..1924d9d 100644 --- a/db/db.go +++ b/db/db.go @@ -2,6 +2,7 @@ package db import ( "encoding/binary" + "encoding/hex" "fmt" "github.com/boltdb/bolt" "path" @@ -78,6 +79,39 @@ func (w *BoltDB) PutRetry(k []byte) error { }) } +func (w *BoltDB) DeleteRetry(k []byte) error { + w.rwLock.Lock() + defer w.rwLock.Unlock() + + return w.db.Update(func(tx *bolt.Tx) error { + bucket := tx.Bucket(BKTRetry) + err := bucket.Delete(k) + if err != nil { + return err + } + return nil + }) +} + +func (w *BoltDB) PutCheck(txHash string, v []byte) error { + w.rwLock.Lock() + defer w.rwLock.Unlock() + + k, err := hex.DecodeString(txHash) + if err != nil { + return err + } + return w.db.Update(func(btx *bolt.Tx) error { + bucket := btx.Bucket(BKTCheck) + err := bucket.Put(k, v) + if err != nil { + return err + } + + return nil + }) +} + func (w *BoltDB) GetAllRetry() ([][]byte, error) { w.rwLock.Lock() defer w.rwLock.Unlock() diff --git a/service/zil2poly.go b/service/zil2poly.go index b632832..e63b1e8 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -3,6 +3,7 @@ package service import ( "bytes" "encoding/json" + "fmt" "github.com/Zilliqa/gozilliqa-sdk/bech32" "github.com/Zilliqa/gozilliqa-sdk/core" "github.com/Zilliqa/gozilliqa-sdk/util" @@ -17,20 +18,58 @@ import ( "time" ) -type CrossTransfer struct { - txIndex string - txId []byte - value []byte - toChain uint32 - height uint64 -} +/** + * handle new block: + * 1. commit tx block and ds block + * 2. filter deposit event, put into local database + * 3. from database, handle deposit event, get proof and commit to poly + */ +func (s *ZilliqaSyncManager) MonitorChain() { + log.Infof("ZilliqaSyncManager MonitorChain - start scan block at height: %d\n", s.currentHeight) + fetchBlockTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) + var blockHandleResult bool + for { + select { + case <-fetchBlockTicker.C: + txBlock, err := s.zilSdk.GetLatestTxBlock() + if err != nil { + log.Errorf("ZilliqaSyncManager MonitorChain - cannot get node hight, err: %s\n", err.Error()) + continue + } + log.Infof("ZilliqaSyncManager MonitorChain - current tx block height: %s\n", txBlock.Header.BlockNum) + blockNumber, err2 := strconv.ParseUint(txBlock.Header.BlockNum, 10, 32) + if err2 != nil { + log.Errorf("ZilliqaSyncManager MonitorChain - cannot parse block height, err: %s\n", err2.Error()) + } + if s.currentHeight >= blockNumber { + log.Infof("ZilliqaSyncManager MonitorChain - current height is not changed, skip") + continue + } -func (this *CrossTransfer) Serialization(sink *common.ZeroCopySink) { - sink.WriteString(this.txIndex) - sink.WriteVarBytes(this.txId) - sink.WriteVarBytes(this.value) - sink.WriteUint32(this.toChain) - sink.WriteUint64(this.height) + blockHandleResult = true + for s.currentHeight < blockNumber { + s.handleNewBlock(s.currentHeight + 1) + s.currentHeight++ + + // todo enable this + if uint32(len(s.header4sync)) > s.cfg.ZilConfig.ZilHeadersPerBatch { + log.Infof("ZilliqaSyncManager MonitorChain - commit header") + //if res := s.commitHeader(); res != 0 { + // blockHandleResult = false + // break + //} + } + } + + if blockHandleResult && len(s.header4sync) > 0 { + // todo enable this + // s.commitHeader() + } + + case <-s.exitChan: + return + } + } } func (s *ZilliqaSyncManager) handleNewBlock(height uint64) bool { @@ -56,6 +95,8 @@ func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { } txBlock := core.NewTxBlockFromTxBlockT(txBlockT) + // todo consider very special case + // tx block revert to last ds epoch, but ds block don't if txBlock.BlockHeader.DSBlockNum > s.currentDsBlockNum { dsBlock, err := s.zilSdk.GetDsBlockVerbose(strconv.FormatUint(txBlock.BlockHeader.DSBlockNum, 10)) if err != nil { @@ -90,81 +131,6 @@ func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { return true } -func (s *ZilliqaSyncManager) commitHeader() int { - tx, err := s.polySdk.Native.Hs.SyncBlockHeader( - s.cfg.ZilConfig.SideChainId, - s.polySigner.Address, - s.header4sync, - s.polySigner, - ) - - if err != nil { - errDesc := err.Error() - if strings.Contains(errDesc, "get the parent block failed") || strings.Contains(errDesc, "missing required field") { - log.Warnf("commitHeader - send transaction to poly chain err: %s", errDesc) - s.rollBackToCommAncestor() - return 0 - } else { - log.Errorf("commitHeader - send transaction to poly chain err: %s", errDesc) - return 1 - } - } - - tick := time.NewTicker(100 * time.Millisecond) - var h uint32 - for range tick.C { - h, _ = s.polySdk.GetBlockHeightByTxHash(tx.ToHexString()) - curr, _ := s.polySdk.GetCurrentBlockHeight() - if h > 0 && curr > h { - break - } - } - - log.Infof("commitHeader - send transaction %s to poly chain and confirmed on height %d", tx.ToHexString(), h) - s.header4sync = make([][]byte, 0) - return 0 -} - -func (s *ZilliqaSyncManager) rollBackToCommAncestor() { - for ; ; s.currentHeight-- { - raw, err := s.polySdk.GetStorage(autils.HeaderSyncContractAddress.ToHexString(), - append(append([]byte(scom.MAIN_CHAIN), autils.GetUint64Bytes(s.cfg.ZilConfig.SideChainId)...), autils.GetUint64Bytes(s.currentHeight)...)) - if len(raw) == 0 || err != nil { - continue - } - txBlockT, err2 := s.zilSdk.GetTxBlockVerbose(strconv.FormatUint(s.currentHeight, 10)) - if err2 != nil { - log.Errorf("rollBackToCommAncestor - failed to get header by number, so we wait for one second to retry: %v", err2) - time.Sleep(time.Second) - s.currentHeight++ - continue - } - blockHeader := core.NewTxBlockFromTxBlockT(txBlockT).BlockHeader - if bytes.Equal(util.Sha256(blockHeader.Serialize()), raw) { - bs, _ := json.Marshal(blockHeader) - log.Infof("rollBackToCommAncestor - find the common ancestor: %s(number: %d)", bs, s.currentHeight) - break - } - - s.header4sync = make([][]byte, 0) - - } -} - - -// should be the same as relayer side -type ZILProof struct { - AccountProof []string `json:"accountProof"` - StorageProofs []StorageProof `json:"storageProof"` -} - -// key should be storage key (in zilliqa) -type StorageProof struct { - Key []byte `json:"key"` - Value []byte `json:"value"` - Proof []string `json:"proof"` -} - // the workflow is: user -> LockProxy on zilliqa -> Cross Chain Manager -> emit event // so here we need to filter out those transactions related to cross chain manager // and parse the events, store them to local db, and commit them to the polynetwork @@ -198,7 +164,7 @@ func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { toChainId, _ := strconv.ParseUint(param.Value.(string), 10, 32) crossTx.toChain = uint32(toChainId) case "rawData": - crossTx.value = []byte(param.Value.(string)) + crossTx.value = util.DecodeHex(param.Value.(string)) } } crossTx.height = height @@ -218,54 +184,204 @@ func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { return true } -func (s *ZilliqaSyncManager) MonitorChain() { - log.Infof("ZilliqaSyncManager MonitorChain - start scan block at height: %d\n", s.currentHeight) - fetchBlockTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) - var blockHandleResult bool - for { - select { - case <-fetchBlockTicker.C: - txBlock, err := s.zilSdk.GetLatestTxBlock() - if err != nil { - log.Errorf("ZilliqaSyncManager MonitorChain - cannot get node hight, err: %s\n", err.Error()) +func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { + retryList, err := s.db.GetAllRetry() + if err != nil { + return fmt.Errorf("ZilliqaSyncManager - handleLockDepositEvents - this.db.GetAllRetry error: %s", err) + } + for _, v := range retryList { + time.Sleep(time.Second * 1) + crosstx := new(CrossTransfer) + err := crosstx.Deserialization(common.NewZeroCopySource(v)) + if err != nil { + log.Errorf("ZilliqaSyncManager - handleLockDepositEvents - retry.Deserialization error: %s", err) + continue + } + heightString := new(string) + *heightString = strconv.FormatUint(height, 10) + proof, err := s.zilSdk.GetStateProof(s.cfg.ZilConfig.CrossChainManagerContract, "zilToPolyTxHashMap", []string{crosstx.txIndex}, heightString) + if err != nil { + return fmt.Errorf("ZilliqaSyncManager - handleLockDepositEvents - get proof from api error: %s", err) + } + + zilProof := &ZILProof{ + AccountProof: proof.AccountProof, + } + + storageProof := StorageProof{ + Key: core.GenerateStorageKey("zilToPolyTxHashMap", []string{crosstx.txIndex}), + Value: crosstx.value, + Proof: proof.StateProof, + } + + zilProof.StorageProofs = []StorageProof{storageProof} + proofRaw, _ := json.Marshal(zilProof) + + // commit proof + proofString, _ := json.Marshal(proof) + log.Debugf("ZilliqaSyncManager - handleLockDepositEvents commit proof, height: %d, proof: %s, value: %s, txhash: %s", height, proofString, util.EncodeHex(crosstx.value), util.EncodeHex(crosstx.txId)) + tx, err := s.polySdk.Native.Ccm.ImportOuterTransfer( + s.cfg.ZilConfig.SideChainId, + crosstx.value, + uint32(height), + proofRaw, + util.DecodeHex(s.polySigner.Address.ToHexString()), + []byte{}, + s.polySigner) + + if err != nil { + if strings.Contains(err.Error(), "ZilliqaSyncManager - handleLockDepositEvents chooseUtxos, current utxo is not enough") { + log.Infof("ZilliqaSyncManager - handleLockDepositEvents handleLockDepositEvents - invokeNativeContract error: %s", err) + continue + } else { + if err := s.db.DeleteRetry(v); err != nil { + log.Errorf("ZilliqaSyncManager - handleLockDepositEvents handleLockDepositEvents handleLockDepositEvents - this.db.DeleteRetry error: %s", err) + } + if strings.Contains(err.Error(), "tx already done") { + log.Debugf("ZilliqaSyncManager - handleLockDepositEvents handleLockDepositEvents handleLockDepositEvents - eth_tx %s already on poly", util.EncodeHex(crosstx.txId)) + } else { + log.Errorf("ZilliqaSyncManager handleLockDepositEvents invokeNativeContract error for eth_tx %s: %s", util.EncodeHex(crosstx.txId), err) + } continue } - log.Infof("ZilliqaSyncManager MonitorChain - current tx block height: %s\n", txBlock.Header.BlockNum) - blockNumber, err2 := strconv.ParseUint(txBlock.Header.BlockNum, 10, 32) - if err2 != nil { - log.Errorf("ZilliqaSyncManager MonitorChain - cannot parse block height, err: %s\n", err2.Error()) + } else { + log.Infof("ZilliqaSyncManager - handleLockDepositEvents commitProof - send transaction to poly chain: ( poly_txhash: %s, eth_txhash: %s, height: %d )", + tx.ToHexString(), util.EncodeHex(crosstx.txId), height) + txHash := tx.ToHexString() + err = s.db.PutCheck(txHash, v) + err = s.db.PutCheck(txHash, v) + if err != nil { + log.Errorf("ZilliqaSyncManager handleLockDepositEvents - this.db.PutCheck error: %s", err) } - if s.currentHeight >= blockNumber { - log.Infof("ZilliqaSyncManager MonitorChain - current height is not changed, skip") - continue + err = s.db.DeleteRetry(v) + if err != nil { + log.Errorf("ZilliqaSyncManager handleLockDepositEvents - this.db.PutCheck error: %s", err) } + log.Infof("ZilliqaSyncManager handleLockDepositEvents - syncProofToAlia txHash is %s", txHash) + } + } - blockHandleResult = true - for s.currentHeight < blockNumber { - s.handleNewBlock(s.currentHeight + 1) - s.currentHeight++ + return nil +} - // todo enable this - if uint32(len(s.header4sync)) > s.cfg.ZilConfig.ZilHeadersPerBatch { - log.Infof("ZilliqaSyncManager MonitorChain - commit header") - //if res := s.commitHeader(); res != 0 { - // blockHandleResult = false - // break - //} - } - } +// should be the same as relayer side +type ZILProof struct { + AccountProof []string `json:"accountProof"` + StorageProofs []StorageProof `json:"storageProof"` +} - if blockHandleResult && len(s.header4sync) > 0 { - // todo enable this - // s.commitHeader() - } +// key should be storage key (in zilliqa) +type StorageProof struct { + Key []byte `json:"key"` + Value []byte `json:"value"` + Proof []string `json:"proof"` +} - case <-s.exitChan: - return +type CrossTransfer struct { + txIndex string + txId []byte + value []byte + toChain uint32 + height uint64 +} + +func (this *CrossTransfer) Serialization(sink *common.ZeroCopySink) { + sink.WriteString(this.txIndex) + sink.WriteVarBytes(this.txId) + sink.WriteVarBytes(this.value) + sink.WriteUint32(this.toChain) + sink.WriteUint64(this.height) +} + +func (this *CrossTransfer) Deserialization(source *common.ZeroCopySource) error { + txIndex, eof := source.NextString() + if eof { + return fmt.Errorf("Waiting deserialize txIndex error") + } + txId, eof := source.NextVarBytes() + if eof { + return fmt.Errorf("Waiting deserialize txId error") + } + value, eof := source.NextVarBytes() + if eof { + return fmt.Errorf("Waiting deserialize value error") + } + toChain, eof := source.NextUint32() + if eof { + return fmt.Errorf("Waiting deserialize toChain error") + } + height, eof := source.NextUint64() + if eof { + return fmt.Errorf("Waiting deserialize height error") + } + this.txIndex = txIndex + this.txId = txId + this.value = value + this.toChain = toChain + this.height = height + return nil +} + +func (s *ZilliqaSyncManager) commitHeader() int { + tx, err := s.polySdk.Native.Hs.SyncBlockHeader( + s.cfg.ZilConfig.SideChainId, + s.polySigner.Address, + s.header4sync, + s.polySigner, + ) + + if err != nil { + errDesc := err.Error() + if strings.Contains(errDesc, "get the parent block failed") || strings.Contains(errDesc, "missing required field") { + log.Warnf("commitHeader - send transaction to poly chain err: %s", errDesc) + s.rollBackToCommAncestor() + return 0 + } else { + log.Errorf("commitHeader - send transaction to poly chain err: %s", errDesc) + return 1 + } + } + + tick := time.NewTicker(100 * time.Millisecond) + var h uint32 + for range tick.C { + h, _ = s.polySdk.GetBlockHeightByTxHash(tx.ToHexString()) + curr, _ := s.polySdk.GetCurrentBlockHeight() + if h > 0 && curr > h { + break } } + + log.Infof("commitHeader - send transaction %s to poly chain and confirmed on height %d", tx.ToHexString(), h) + s.header4sync = make([][]byte, 0) + return 0 } +func (s *ZilliqaSyncManager) rollBackToCommAncestor() { + for ; ; s.currentHeight-- { + raw, err := s.polySdk.GetStorage(autils.HeaderSyncContractAddress.ToHexString(), + append(append([]byte(scom.MAIN_CHAIN), autils.GetUint64Bytes(s.cfg.ZilConfig.SideChainId)...), autils.GetUint64Bytes(s.currentHeight)...)) + if len(raw) == 0 || err != nil { + continue + } + txBlockT, err2 := s.zilSdk.GetTxBlockVerbose(strconv.FormatUint(s.currentHeight, 10)) + if err2 != nil { + log.Errorf("rollBackToCommAncestor - failed to get header by number, so we wait for one second to retry: %v", err2) + time.Sleep(time.Second) + s.currentHeight++ + continue + } + blockHeader := core.NewTxBlockFromTxBlockT(txBlockT).BlockHeader + if bytes.Equal(util.Sha256(blockHeader.Serialize()), raw) { + bs, _ := json.Marshal(blockHeader) + log.Infof("rollBackToCommAncestor - find the common ancestor: %s(number: %d)", bs, s.currentHeight) + break + } + + s.header4sync = make([][]byte, 0) + + } +} func (s *ZilliqaSyncManager) MonitorDeposit() { log.Infof("ZilliqaSyncManager MonitorDeposit - start monitor deposit\n") monitorTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) From e1b4b3f37a095a677eb6c22153a11b08d0bcb8db Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 24 Feb 2021 00:29:06 +0800 Subject: [PATCH 034/107] feat(zilmananger): handleLockDepositEvents --- service/zil2poly.go | 17 ----------------- service/zilliqamanager.go | 1 - 2 files changed, 18 deletions(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index e63b1e8..333e1bc 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -382,20 +382,3 @@ func (s *ZilliqaSyncManager) rollBackToCommAncestor() { } } -func (s *ZilliqaSyncManager) MonitorDeposit() { - log.Infof("ZilliqaSyncManager MonitorDeposit - start monitor deposit\n") - monitorTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) - for { - select { - case <-monitorTicker.C: - txBlock, err := s.zilSdk.GetLatestTxBlock() - if err != nil { - log.Infof("ZilliqaSyncManager MonitorDeposit - cannot get node hight, err: %s\n", err.Error()) - continue - } - log.Infof("ZilliqaSyncManager MonitorDeposit - current tx block height: %s\n", txBlock.Header.BlockNum) - case <-s.exitChan: - return - } - } -} diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 751529a..0d6cbc5 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -84,7 +84,6 @@ func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysd func (s *ZilliqaSyncManager) Run(enable bool) { if enable { go s.MonitorChain() - //go s.MonitorDeposit() } } From 979a2fc4936caf6e58bfde7521b19b012e37c1be Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 24 Feb 2021 00:35:25 +0800 Subject: [PATCH 035/107] feat: rollback ds block num if needed --- service/zil2poly.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index 333e1bc..85df840 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -54,16 +54,15 @@ func (s *ZilliqaSyncManager) MonitorChain() { // todo enable this if uint32(len(s.header4sync)) > s.cfg.ZilConfig.ZilHeadersPerBatch { log.Infof("ZilliqaSyncManager MonitorChain - commit header") - //if res := s.commitHeader(); res != 0 { - // blockHandleResult = false - // break - //} + if res := s.commitHeader(); res != 0 { + blockHandleResult = false + break + } } } if blockHandleResult && len(s.header4sync) > 0 { - // todo enable this - // s.commitHeader() + s.commitHeader() } case <-s.exitChan: @@ -95,8 +94,6 @@ func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { } txBlock := core.NewTxBlockFromTxBlockT(txBlockT) - // todo consider very special case - // tx block revert to last ds epoch, but ds block don't if txBlock.BlockHeader.DSBlockNum > s.currentDsBlockNum { dsBlock, err := s.zilSdk.GetDsBlockVerbose(strconv.FormatUint(txBlock.BlockHeader.DSBlockNum, 10)) if err != nil { @@ -377,8 +374,19 @@ func (s *ZilliqaSyncManager) rollBackToCommAncestor() { log.Infof("rollBackToCommAncestor - find the common ancestor: %s(number: %d)", bs, s.currentHeight) break } + } - s.header4sync = make([][]byte, 0) + s.header4sync = make([][]byte, 0) + txBlock, err := s.zilSdk.GetTxBlock(strconv.FormatUint(s.currentHeight, 10)) + if err != nil { + log.Warnf("rollBackToCommAncestor, fail to get tx block, err: %s\n", err) + } + dsNum, err2 := strconv.ParseUint(txBlock.Header.DSBlockNum, 64, 10) + if err2 != nil { + log.Warnf("rollBackToCommAncestor, fail to parse ds num, err: %s\n", err2) } + + s.currentDsBlockNum = dsNum + } From 2e9867a863b0ca9ed255dec8e6f842bf2acfea0e Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 3 Mar 2021 10:42:11 +0800 Subject: [PATCH 036/107] fix: update zilliqa manager init process --- cmd/run.go | 30 +++++++++++++++--------------- service/poly2zil.go | 20 -------------------- service/zil2poly.go | 1 - service/zilliqamanager.go | 21 ++++++++++++++++----- 4 files changed, 31 insertions(+), 41 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index a16a203..ebc7b0b 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -20,19 +20,19 @@ func init() { cobra.OnInitialize(initConfig) RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)") - runCmd.Flags().String("api", "https://api.zilliqa.com", "zilliqa api endpoint") - if err := viper.BindPFlag("api", runCmd.Flags().Lookup("api")); err != nil { - log.Fatal("Unable to bind flag:", err) - } - runCmd.Flags().String("zil_start_height", "1", "the from block number will be syncing to poly network") - if err := viper.BindPFlag("api", runCmd.Flags().Lookup("zil_start_height")); err != nil { - log.Fatal("Unable to bind flag:", err) - } - - runCmd.Flags().String("zil_scan_interval", "2", "the interval scanning zilliqa block") - if err := viper.BindPFlag("zil_scan_interval", runCmd.Flags().Lookup("zil_scan_interval")); err != nil { - log.Fatal("Unable to bind flag:", err) - } + //runCmd.Flags().String("api", "https://api.zilliqa.com", "zilliqa api endpoint") + //if err := viper.BindPFlag("api", runCmd.Flags().Lookup("api")); err != nil { + // log.Fatal("Unable to bind flag:", err) + //} + //runCmd.Flags().String("zil_start_height", "1", "the from block number will be syncing to poly network") + //if err := viper.BindPFlag("api", runCmd.Flags().Lookup("zil_start_height")); err != nil { + // log.Fatal("Unable to bind flag:", err) + //} + // + //runCmd.Flags().String("zil_scan_interval", "2", "the interval scanning zilliqa block") + //if err := viper.BindPFlag("zil_scan_interval", runCmd.Flags().Lookup("zil_scan_interval")); err != nil { + // log.Fatal("Unable to bind flag:", err) + //} RootCmd.AddCommand(runCmd) } @@ -156,8 +156,8 @@ var runCmd = &cobra.Command{ return } - zilliqaManager.Run(true) - polyManager.Run(false) + zilliqaManager.Run(false) + polyManager.Run(true) service.WaitToExit() diff --git a/service/poly2zil.go b/service/poly2zil.go index 1dc8ec6..b2edf67 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -63,10 +63,6 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { log.Errorf("PolySyncManager handleBlockHeader - GetNodeHeader on height :%d failed", height) return false } - /************************* to be deleted ******************************/ - hdrs, _ := json.Marshal(hdr) - log.Infof("PolySyncManager handleBlockHeader - height: %d, header: %s", height, hdrs) - /************************* to be deleted ******************************/ isCurr := lastEpoch < height+1 info := &vconfig.VbftBlockInfo{} if err := json.Unmarshal(hdr.ConsensusPayload, info); err != nil { @@ -93,10 +89,6 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { log.Errorf("PolySyncManager handleDepositEvents - get block event at height:%d error: %s", height, err.Error()) return false } - /************************* to be deleted ******************************/ - eventss, _ := json.Marshal(events) - log.Infof("PolySyncManager handleBlockHeader - height: %d, events: %s", height, eventss) - /************************* to be deleted ******************************/ for _, event := range events { for _, notify := range event.Notify { if notify.ContractAddress == p.cfg.PolyConfig.EntranceContractAddress { @@ -125,18 +117,6 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { // todo assuming ToContractAddress is not bech32 // handle error toContractStr, _ := bech32.ToBech32Address(util.EncodeHex(param.MakeTxParam.ToContractAddress)) - /************************* todo delete now ******************************/ - //log.Info("catched!") - //params,_ := json.Marshal(param) - //log.Info(string(params)) - //toAddr := util.EncodeHex(param.MakeTxParam.ToContractAddress) - //log.Info("toContract: " + toAddr) - //if strings.Contains(strings.ToLower(toAddr),"46de"){ - // os.Exit(0) - //} else { - // break - //} - /************************* todo delete now ******************************/ for _, v := range p.cfg.TargetContracts { toChainIdArr, ok := v[toContractStr] if ok { diff --git a/service/zil2poly.go b/service/zil2poly.go index 85df840..e7a037f 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -51,7 +51,6 @@ func (s *ZilliqaSyncManager) MonitorChain() { s.handleNewBlock(s.currentHeight + 1) s.currentHeight++ - // todo enable this if uint32(len(s.header4sync)) > s.cfg.ZilConfig.ZilHeadersPerBatch { log.Infof("ZilliqaSyncManager MonitorChain - commit header") if res := s.commitHeader(); res != 0 { diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 0d6cbc5..563059c 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -13,8 +13,12 @@ import ( "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/db" log "github.com/sirupsen/logrus" + "strconv" ) +/** + * currentHeight's source is either from poly remote storage or forceHeight + */ type ZilliqaSyncManager struct { polySigner *poly.Account polySdk *poly.PolySdk @@ -73,7 +77,6 @@ func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysd } err = zilliqaSyncManager.init() - err = nil if err != nil { return nil, err } else { @@ -88,8 +91,8 @@ func (s *ZilliqaSyncManager) Run(enable bool) { } func (s *ZilliqaSyncManager) init() error { - // get latest height - latestHeight := s.findLatestHeight() + // get latest tx block from remote poly storage, thus we can know current tx block num and ds block num + latestHeight := s.findLatestTxBlockHeight() if latestHeight == 0 { return fmt.Errorf("init - the genesis block has not synced!") } @@ -99,11 +102,18 @@ func (s *ZilliqaSyncManager) init() error { s.currentHeight = latestHeight } log.Infof("ZilliqaSyncManager init - start height: %d", s.currentHeight) + + txBlockHeight := strconv.FormatUint(s.currentHeight, 10) + txBlockT, err := s.zilSdk.GetTxBlockVerbose(txBlockHeight) + if err != nil { + return fmt.Errorf("init - get tx block error: %s", err.Error()) + } + dsBlockNum, _ := strconv.ParseUint(txBlockT.Header.DSBlockNum, 10, 64) + s.currentDsBlockNum = dsBlockNum return nil } -// get latest height from polynetwork -func (s *ZilliqaSyncManager) findLatestHeight() uint64 { +func (s *ZilliqaSyncManager) findLatestTxBlockHeight() uint64 { // try to get key var sideChainIdBytes [8]byte binary.LittleEndian.PutUint64(sideChainIdBytes[:], s.cfg.ZilConfig.SideChainId) @@ -112,6 +122,7 @@ func (s *ZilliqaSyncManager) findLatestHeight() uint64 { // try to get storage result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) if err != nil { + log.Printf("get latest tx block from poly failed,err: %s\n",err.Error()) return 0 } if result == nil || len(result) == 0 { From 94253f277fbdaf1215ff7b3b657be6ec98ab1285 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 4 Mar 2021 11:30:12 +0800 Subject: [PATCH 037/107] fix: init zilliqa manager, block commit --- .gitignore | 3 ++- cmd/run.go | 5 ++--- config/config.go | 1 - go.mod | 3 ++- go.sum | 4 ++++ service/zil2poly.go | 30 +++++++++++++++++++++++++++--- service/zilliqamanager.go | 14 ++++++++------ 7 files changed, 45 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 443b172..bcb5c7b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ zilliqa-relayer .idea bolt.bin config.local.yaml -constants.xml \ No newline at end of file +constants.xml +cross_chain_manager_admin.json \ No newline at end of file diff --git a/cmd/run.go b/cmd/run.go index ebc7b0b..0406b41 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -97,7 +97,6 @@ var runCmd = &cobra.Command{ ZilApiEndpoint: zilConfigMap["zil_api"].(string), ZilChainId: zilConfigMap["zil_chain_id"].(int), ZilMessageVersion: zilConfigMap["zil_message_version"].(int), - ZilStartHeight: uint32(zilConfigMap["zil_start_height"].(int)), ZilForceHeight: uint64(zilConfigMap["zil_force_height"].(int)), ZilMonitorInterval: uint32(zilConfigMap["zil_monitor_interval"].(int)), ZilHeadersPerBatch: uint32(zilConfigMap["zil_headers_per_batch"].(int)), @@ -156,8 +155,8 @@ var runCmd = &cobra.Command{ return } - zilliqaManager.Run(false) - polyManager.Run(true) + zilliqaManager.Run(true) + polyManager.Run(false) service.WaitToExit() diff --git a/config/config.go b/config/config.go index 679b516..5b3a591 100644 --- a/config/config.go +++ b/config/config.go @@ -17,7 +17,6 @@ type ZILConfig struct { ZilMessageVersion int ZilMonitorInterval uint32 ZilHeadersPerBatch uint32 - ZilStartHeight uint32 ZilForceHeight uint64 SideChainId uint64 CrossChainManagerContract string diff --git a/go.mod b/go.mod index 00ee5a9..86924df 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,10 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222044512-f9f981909bf0 + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210303111409-fe5756ee1456 github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta + github.com/ethereum/go-ethereum v1.9.24 // indirect github.com/magiconair/properties v1.8.1 github.com/ontio/ontology v1.11.0 github.com/ontio/ontology-crypto v1.0.9 diff --git a/go.sum b/go.sum index 5a99d18..93903fb 100644 --- a/go.sum +++ b/go.sum @@ -64,6 +64,10 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222003933-7691f5ca42a2 h1:faO7UGk github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222003933-7691f5ca42a2/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.20210303070214-e9f060dd9677 h1:BczNHdGYMiLdVgENX9cNkza+b24gIHUx6iNygpxtG4c= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210303070214-e9f060dd9677/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= +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/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/service/zil2poly.go b/service/zil2poly.go index e7a037f..4cb241a 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -25,6 +25,17 @@ import ( * 3. from database, handle deposit event, get proof and commit to poly */ func (s *ZilliqaSyncManager) MonitorChain() { + // todo delete me + //temp solution to commit miss block + //a,_ := s.zilSdk.GetDsBlockVerbose("4") + //b := core.NewDsBlockFromDsBlockT(a) + //txBlockOrDsBlock := core.TxBlockOrDsBlock{ + // DsBlock: b, + //} + //rawBlock, _ := json.Marshal(txBlockOrDsBlock) + //s.header4sync = append(s.header4sync,rawBlock) + // todo delete me + log.Infof("ZilliqaSyncManager MonitorChain - start scan block at height: %d\n", s.currentHeight) fetchBlockTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) var blockHandleResult bool @@ -319,6 +330,19 @@ func (this *CrossTransfer) Deserialization(source *common.ZeroCopySource) error } func (s *ZilliqaSyncManager) commitHeader() int { + // maybe delete this after it is stable + for _, raw := range s.header4sync { + var block core.TxBlockOrDsBlock + _ = json.Unmarshal(raw, &block) + if block.TxBlock != nil { + log.Infof("ZilliqaSyncManager commitHeader - about to commit tx block: %d\n", block.TxBlock.BlockHeader.BlockNum) + } + + if block.DsBlock != nil { + log.Infof("ZilliqaSyncManager commitHeader - about to commit ds block: %d\n", block.DsBlock.BlockHeader.BlockNum) + } + } + tx, err := s.polySdk.Native.Hs.SyncBlockHeader( s.cfg.ZilConfig.SideChainId, s.polySigner.Address, @@ -329,11 +353,11 @@ func (s *ZilliqaSyncManager) commitHeader() int { if err != nil { errDesc := err.Error() if strings.Contains(errDesc, "get the parent block failed") || strings.Contains(errDesc, "missing required field") { - log.Warnf("commitHeader - send transaction to poly chain err: %s", errDesc) + log.Warnf("ZilliqaSyncManager commitHeader - send transaction to poly chain err: %s", errDesc) s.rollBackToCommAncestor() return 0 } else { - log.Errorf("commitHeader - send transaction to poly chain err: %s", errDesc) + log.Errorf("ZilliqaSyncManager commitHeader - send transaction to poly chain err: %s", errDesc) return 1 } } @@ -348,7 +372,7 @@ func (s *ZilliqaSyncManager) commitHeader() int { } } - log.Infof("commitHeader - send transaction %s to poly chain and confirmed on height %d", tx.ToHexString(), h) + log.Infof("ZilliqaSyncManager commitHeader - send transaction %s to poly chain and confirmed on height %d", tx.ToHexString(), h) s.header4sync = make([][]byte, 0) return 0 } diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 563059c..96f765e 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -69,7 +69,6 @@ func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysd cfg: cfg, exitChan: make(chan int), zilSdk: zilSdk, - currentHeight: uint64(cfg.ZilConfig.ZilStartHeight), forceHeight: cfg.ZilConfig.ZilForceHeight, crossChainManagerAddress: cfg.ZilConfig.CrossChainManagerContract, polySigner: signer, @@ -93,9 +92,12 @@ func (s *ZilliqaSyncManager) Run(enable bool) { func (s *ZilliqaSyncManager) init() error { // get latest tx block from remote poly storage, thus we can know current tx block num and ds block num latestHeight := s.findLatestTxBlockHeight() + log.Infof("ZilliqaSyncManager init - get latest tx block from poly, tx block height is: %d\n", latestHeight) + if latestHeight == 0 { - return fmt.Errorf("init - the genesis block has not synced!") + return fmt.Errorf("ZilliqaSyncManager init - the genesis block has not synced!") } + if s.forceHeight > 0 && s.forceHeight < latestHeight { s.currentHeight = s.forceHeight } else { @@ -103,13 +105,13 @@ func (s *ZilliqaSyncManager) init() error { } log.Infof("ZilliqaSyncManager init - start height: %d", s.currentHeight) - txBlockHeight := strconv.FormatUint(s.currentHeight, 10) - txBlockT, err := s.zilSdk.GetTxBlockVerbose(txBlockHeight) + txBlockT, err := s.zilSdk.GetTxBlockVerbose(strconv.FormatUint(s.currentHeight, 10)) if err != nil { - return fmt.Errorf("init - get tx block error: %s", err.Error()) + return fmt.Errorf("ZilliqaSyncManager init - get tx block error: %s", err.Error()) } dsBlockNum, _ := strconv.ParseUint(txBlockT.Header.DSBlockNum, 10, 64) s.currentDsBlockNum = dsBlockNum + log.Infof("ZilliqaSyncManager init - current ds block height is: %d\n", s.currentDsBlockNum) return nil } @@ -122,7 +124,7 @@ func (s *ZilliqaSyncManager) findLatestTxBlockHeight() uint64 { // try to get storage result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) if err != nil { - log.Printf("get latest tx block from poly failed,err: %s\n",err.Error()) + log.Printf("get latest tx block from poly failed,err: %s\n", err.Error()) return 0 } if result == nil || len(result) == 0 { From ea8562e769fa3b7bc9a9385c4a19d01b530a8854 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Sat, 6 Mar 2021 18:34:25 +0800 Subject: [PATCH 038/107] feat: complete cross chain transaction commit --- go.mod | 2 +- go.sum | 2 ++ service/zil2poly.go | 50 ++++++++++++++++++++++++++++++--------------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 86924df..41cea43 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210303111409-fe5756ee1456 + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210304105042-c4327211a4ba github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta github.com/ethereum/go-ethereum v1.9.24 // indirect diff --git a/go.sum b/go.sum index 93903fb..8d98988 100644 --- a/go.sum +++ b/go.sum @@ -68,6 +68,8 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210303070214-e9f060dd9677 h1:BczNHdG github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210303070214-e9f060dd9677/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= 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/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/service/zil2poly.go b/service/zil2poly.go index 4cb241a..4fdd181 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -25,17 +25,6 @@ import ( * 3. from database, handle deposit event, get proof and commit to poly */ func (s *ZilliqaSyncManager) MonitorChain() { - // todo delete me - //temp solution to commit miss block - //a,_ := s.zilSdk.GetDsBlockVerbose("4") - //b := core.NewDsBlockFromDsBlockT(a) - //txBlockOrDsBlock := core.TxBlockOrDsBlock{ - // DsBlock: b, - //} - //rawBlock, _ := json.Marshal(txBlockOrDsBlock) - //s.header4sync = append(s.header4sync,rawBlock) - // todo delete me - log.Infof("ZilliqaSyncManager MonitorChain - start scan block at height: %d\n", s.currentHeight) fetchBlockTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) var blockHandleResult bool @@ -154,10 +143,18 @@ func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { } for _, transaction := range transactions { + if !transaction.Receipt.Success { + continue + } events := transaction.Receipt.EventLogs for _, event := range events { + // 1. contract address should be cross chain manager + // 2. event name should be CrossChainEvent toAddr, _ := bech32.ToBech32Address(event.Address) if toAddr == s.crossChainManagerAddress { + if event.EventName != "CrossChainEvent" { + continue + } log.Infof("ZilliqaSyncManager found event on cross chain manager: %+v\n", event) // todo parse event to struct CrossTransfer crossTx := &CrossTransfer{} @@ -170,7 +167,7 @@ func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { case "toChainId": toChainId, _ := strconv.ParseUint(param.Value.(string), 10, 32) crossTx.toChain = uint32(toChainId) - case "rawData": + case "rawdata": crossTx.value = util.DecodeHex(param.Value.(string)) } } @@ -184,6 +181,8 @@ func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { log.Errorf("ZilliqaSyncManager fetchLockDepositEvents - this.db.PutRetry error: %s", err) } log.Infof("ZilliqaSyncManager fetchLockDepositEvent - height: %d", height) + } else { + log.Infof("ZilliqaSyncManager found event but not on cross chain manager, ignore: %+v\n", event) } } } @@ -192,6 +191,7 @@ func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { } func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { + log.Infof("ZilliqaSyncManager handleLockDepositEvents - height is %s", height) retryList, err := s.db.GetAllRetry() if err != nil { return fmt.Errorf("ZilliqaSyncManager - handleLockDepositEvents - this.db.GetAllRetry error: %s", err) @@ -206,17 +206,23 @@ func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { } heightString := new(string) *heightString = strconv.FormatUint(height, 10) - proof, err := s.zilSdk.GetStateProof(s.cfg.ZilConfig.CrossChainManagerContract, "zilToPolyTxHashMap", []string{crosstx.txIndex}, heightString) + ccmc,_ := bech32.FromBech32Addr(s.cfg.ZilConfig.CrossChainManagerContract) + txIndexBigInt,_ := new(big.Int).SetString(crosstx.txIndex,16) + txIndexDecimal := txIndexBigInt.String() + proof, err := s.zilSdk.GetStateProof(ccmc, "zilToPolyTxHashMap", []string{txIndexDecimal}, heightString) if err != nil { return fmt.Errorf("ZilliqaSyncManager - handleLockDepositEvents - get proof from api error: %s", err) } + log.Infof("ZilliqaSyncManager - handleLockDepositEvents get proof from zilliqa api endpoint: %+v, height is: %d\n", proof,height) zilProof := &ZILProof{ AccountProof: proof.AccountProof, } + skey := core.GenerateStorageKey("zilToPolyTxHashMap", []string{txIndexDecimal}) + hexskey := util.EncodeHex(skey) storageProof := StorageProof{ - Key: core.GenerateStorageKey("zilToPolyTxHashMap", []string{crosstx.txIndex}), + Key: []byte(hexskey), Value: crosstx.value, Proof: proof.StateProof, } @@ -247,7 +253,7 @@ func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { if strings.Contains(err.Error(), "tx already done") { log.Debugf("ZilliqaSyncManager - handleLockDepositEvents handleLockDepositEvents handleLockDepositEvents - eth_tx %s already on poly", util.EncodeHex(crosstx.txId)) } else { - log.Errorf("ZilliqaSyncManager handleLockDepositEvents invokeNativeContract error for eth_tx %s: %s", util.EncodeHex(crosstx.txId), err) + log.Errorf("ZilliqaSyncManager handleLockDepositEvents invokeNativeContract error for zil_tx %s: %s", util.EncodeHex(crosstx.txId), err) } continue } @@ -374,6 +380,9 @@ func (s *ZilliqaSyncManager) commitHeader() int { log.Infof("ZilliqaSyncManager commitHeader - send transaction %s to poly chain and confirmed on height %d", tx.ToHexString(), h) s.header4sync = make([][]byte, 0) + + // todo + s.handleLockDepositEvents(s.currentHeight) return 0 } @@ -394,7 +403,7 @@ func (s *ZilliqaSyncManager) rollBackToCommAncestor() { blockHeader := core.NewTxBlockFromTxBlockT(txBlockT).BlockHeader if bytes.Equal(util.Sha256(blockHeader.Serialize()), raw) { bs, _ := json.Marshal(blockHeader) - log.Infof("rollBackToCommAncestor - find the common ancestor: %s(number: %d)", bs, s.currentHeight) + log.Infof("ZilliqaSyncManager rollBackToCommAncestor - find the common ancestor: %s(number: %d)", bs, s.currentHeight) break } } @@ -405,11 +414,18 @@ func (s *ZilliqaSyncManager) rollBackToCommAncestor() { log.Warnf("rollBackToCommAncestor, fail to get tx block, err: %s\n", err) } - dsNum, err2 := strconv.ParseUint(txBlock.Header.DSBlockNum, 64, 10) + dsNum, err2 := strconv.ParseUint(txBlock.Header.DSBlockNum, 10, 64) if err2 != nil { log.Warnf("rollBackToCommAncestor, fail to parse ds num, err: %s\n", err2) } + a,_ := s.zilSdk.GetDsBlockVerbose(txBlock.Header.DSBlockNum) + b := core.NewDsBlockFromDsBlockT(a) + txBlockOrDsBlock := core.TxBlockOrDsBlock{ + DsBlock: b, + } + rawBlock, _ := json.Marshal(txBlockOrDsBlock) + s.header4sync = append(s.header4sync,rawBlock) s.currentDsBlockNum = dsNum } From 820058050dd2e0f8238c79acb8530fea8e10296e Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Mon, 8 Mar 2021 11:53:03 +0800 Subject: [PATCH 039/107] feat: support timestamp in log, update sdk version --- README.md | 2 +- admin.keystore | 1 + cmd/run.go | 5 ++++- config.yaml | 2 +- go.mod | 2 +- go.sum | 2 ++ keystore | 2 -- service/poly2zil.go | 9 +-------- service/polymanager.go | 4 ++-- 9 files changed, 13 insertions(+), 16 deletions(-) create mode 100644 admin.keystore delete mode 100644 keystore diff --git a/README.md b/README.md index 6e3fb53..9ab4273 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ zil_config: zil_monitor_interval: 40 corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f side_chain_id: 1 - key_store_path: ./keystore + key_store_path: ./admin.keystore key_store_pwd_set: 7d48043742a1103042d327111746531ca26be9be: "pwd1" de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7: "pwd2" diff --git a/admin.keystore b/admin.keystore new file mode 100644 index 0000000..9c77fa8 --- /dev/null +++ b/admin.keystore @@ -0,0 +1 @@ +{"address":"6c89b62d65dc632e259b96f7ae2f1d68a27e3383","id":"e4716195-8342-4d37-9dac-49340ac8468c","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"76828f408c3abdbe39a5221cb601de45a3af9ce1352a9d01a7211c719a482f14","kdf":"pbkdf2","mac":"8b361a8ac463f2eac9625361d66aa6157b1b0fd8ee1db4649f528eff5728f632","cipherparams":{"iv":"b7ca9f85fbb2574e6bafe82a110fbea2"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"37c830e060703f320a1756f2fd49ce74bfbdfaf45b111b2e1d5342e6e52705e6"}}} diff --git a/cmd/run.go b/cmd/run.go index 0406b41..aa23ab3 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -35,6 +35,9 @@ func init() { //} RootCmd.AddCommand(runCmd) + log.SetFormatter(&log.TextFormatter{ + FullTimestamp: true, + }) } func initConfig() { @@ -156,7 +159,7 @@ var runCmd = &cobra.Command{ } zilliqaManager.Run(true) - polyManager.Run(false) + polyManager.Run(true) service.WaitToExit() diff --git a/config.yaml b/config.yaml index 7893363..5bf3a99 100644 --- a/config.yaml +++ b/config.yaml @@ -7,7 +7,7 @@ zil_config: corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f cross_chain_manager_proxy_address: zil1urrkyfpww7rzhxh36m9nhksr5z73ragpar53nk side_chain_id: 2 - key_store_path: keystore + key_store_path: admin.keystore key_store_pwd_set: 7d48043742a1103042d327111746531ca26be9be: "xiaohuo" de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7: "xiaohuo" diff --git a/go.mod b/go.mod index 41cea43..054e008 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210304105042-c4327211a4ba + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210308032016-7002414861d8 github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta github.com/ethereum/go-ethereum v1.9.24 // indirect diff --git a/go.sum b/go.sum index 8d98988..b3912f4 100644 --- a/go.sum +++ b/go.sum @@ -70,6 +70,8 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210303111409-fe5756ee1456 h1:XrMAFNS 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.20210308032016-7002414861d8 h1:6JJXeTfBSavuY2YlTbMuzLm6RGDEutPcqcs37AMO84c= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210308032016-7002414861d8/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/keystore b/keystore deleted file mode 100644 index 97830b5..0000000 --- a/keystore +++ /dev/null @@ -1,2 +0,0 @@ -{"address":"7d48043742a1103042d327111746531ca26be9be","id":"6cd445ed-8f5f-4565-af2a-cc2306a82b73","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"d136660a4e5664709031ebc162616556e8c812ab37d0157ea3276aa08d0a6c2d","kdf":"pbkdf2","mac":"b30dd459f1fd9d99c0b2f3452ccd2bf11414ad92d32ac70d1d7b52f17281b4e5","cipherparams":{"iv":"6a14f95c8cbafe7d1f317bec88e9d1b8"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"c4939e7cead32935d1972a2cd06d249dd501181e6ad2d1872fa0eb397d7fea20"}}} -{"address":"de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7","id":"e6ed9aba-7be3-40ca-8fab-7f9438fdf7cf","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"b96b59ea5861c7048f62cf15c219faa9e1494495030f42f021b6277622ab819f","kdf":"pbkdf2","mac":"ad06d0f0f5df29ad0947a62954ed08b084c2fc11aec66a36ab2c79eb1398768c","cipherparams":{"iv":"ef08dc8dbca886b1141e13fb7e988817"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"26bc16e8bc0dc2749c1cde2e62aa5c9990898c5c4d3f78c822fed2988c0ab682"}}} \ No newline at end of file diff --git a/service/poly2zil.go b/service/poly2zil.go index b2edf67..1e6572f 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -57,6 +57,7 @@ func (p *PolySyncManager) MonitorChain() { } func (p *PolySyncManager) handleDepositEvents(height uint32) bool { + log.Infof("PolySyncManager handleDepositEvents at height %d\n", height) lastEpoch := p.findLatestHeight() hdr, err := p.polySdk.GetHeaderByHeight(height + 1) if err != nil { @@ -233,12 +234,4 @@ func (p *PolySyncManager) findLatestHeight() uint32 { } return 0 - // todo - //log.Info(epochStartHeightRep.Result.CurEpochStartHeight) - //height, err2 := strconv.ParseUint(epochStartHeightRep.Result.CurEpochStartHeight, 10, 32) - //if err2 != nil { - // log.Errorf("PolySyncManager FindLatestHeight - faild to parse epoch start height: %s\n", err2.Error()) - // return 0 - //} - //return uint32(height) } diff --git a/service/polymanager.go b/service/polymanager.go index 4d7b27a..1ba90a0 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -69,11 +69,11 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * } pwd := keystorepwdset[ks.Address] if pwd == nil { - return nil, errors.New("NewPolySyncManager - there is no password for keystore: " + ks.Address) + return nil, errors.New("NewPolySyncManager - there is no password for admin.keystore: " + ks.Address) } privateKey, err2 := descryptor.DecryptPrivateKey(keystore, pwd.(string)) if err2 != nil { - return nil, errors.New("NewPolySyncManager - descrypt keystore error: " + err2.Error()) + return nil, errors.New("NewPolySyncManager - descrypt admin.keystore error: " + err2.Error()) } // init cross chain smart contract proxy From 83a149ef129c90c84aa481c2531a277ac79aee1a Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Mon, 8 Mar 2021 23:53:33 +0800 Subject: [PATCH 040/107] fix(polymanager): add 0x prefix while calling zilliqa contract --- db/db.go | 11 +++++++++++ service/poly2zil.go | 1 + service/zil2poly.go | 2 +- service/zil_sender.go | 4 ++-- target_contracts.json | 6 +++--- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/db/db.go b/db/db.go index 1924d9d..7bbb223 100644 --- a/db/db.go +++ b/db/db.go @@ -61,6 +61,17 @@ func NewBoltDB(filePath string) (*BoltDB, error) { return nil, err } + // poly check + if err = db.Update(func(btx *bolt.Tx) error { + _, err := btx.CreateBucketIfNotExists(BKTHeight) + if err != nil { + return err + } + return nil + }); err != nil { + return nil, err + } + return w, nil } diff --git a/service/poly2zil.go b/service/poly2zil.go index 1e6572f..b59dcda 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -92,6 +92,7 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { } for _, event := range events { for _, notify := range event.Notify { + log.Infof("PolySyncManager handleDepositEvents get notify address: %s\n", notify.ContractAddress) if notify.ContractAddress == p.cfg.PolyConfig.EntranceContractAddress { states := notify.States.([]interface{}) method, _ := states[0].(string) diff --git a/service/zil2poly.go b/service/zil2poly.go index 4fdd181..970f8ba 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -191,7 +191,7 @@ func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { } func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { - log.Infof("ZilliqaSyncManager handleLockDepositEvents - height is %s", height) + log.Infof("ZilliqaSyncManager handleLockDepositEvents - height is %d", height) retryList, err := s.db.GetAllRetry() if err != nil { return fmt.Errorf("ZilliqaSyncManager - handleLockDepositEvents - this.db.GetAllRetry error: %s", err) diff --git a/service/zil_sender.go b/service/zil_sender.go index e8aeeaa..eac8adf 100644 --- a/service/zil_sender.go +++ b/service/zil_sender.go @@ -64,9 +64,9 @@ func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, // todo carefully test this pe := polynetwork.DeserializeProof(util.EncodeHex(rawAuditPath), 0) - rawHeader := util.EncodeHex(headerData) + rawHeader := "0x" + util.EncodeHex(headerData) hpe := polynetwork.DeserializeProof(headerProof, 0) - curRawHeader := util.EncodeHex(rawAnchor) + curRawHeader := "0x" + util.EncodeHex(rawAnchor) signatures, _ := polynetwork.SplitSignature(util.EncodeHex(sigs)) // todo use chan to handle result diff --git a/target_contracts.json b/target_contracts.json index aa7f9c0..72d567d 100644 --- a/target_contracts.json +++ b/target_contracts.json @@ -1,8 +1,8 @@ [ { - "zil1mzh88cr92t38qdqtvw5te2leyaap4tyeu8j4mg": { - "inbound": [3], - "outbound": [6] + "zil1v4v858qjqd5s88vvsj3qsn89nndeldkpwd9l2c": { + "inbound": [82], + "outbound": [82] } } ] \ No newline at end of file From 4fa85b3c3787f2f52fcea499abab8bf0d9ea2c45 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 10 Mar 2021 13:25:50 +0800 Subject: [PATCH 041/107] fix: handle the situation where proof is nil even no error happens --- service/poly2zil.go | 4 ++-- service/zil2poly.go | 4 ++++ target_contracts.json | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/service/poly2zil.go b/service/poly2zil.go index b59dcda..173ab3b 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -116,8 +116,8 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { } var isTarget bool if len(p.cfg.TargetContracts) > 0 { - // todo assuming ToContractAddress is not bech32 - // handle error + // target address configuration should include those contracts are allowed to be triggered by + // cross chain transactions. e.g LockProxy toContractStr, _ := bech32.ToBech32Address(util.EncodeHex(param.MakeTxParam.ToContractAddress)) for _, v := range p.cfg.TargetContracts { toChainIdArr, ok := v[toContractStr] diff --git a/service/zil2poly.go b/service/zil2poly.go index 970f8ba..d9b48f2 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -215,6 +215,10 @@ func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { } log.Infof("ZilliqaSyncManager - handleLockDepositEvents get proof from zilliqa api endpoint: %+v, height is: %d\n", proof,height) + if proof == nil { + return fmt.Errorf("ZilliqaSyncManager - handleLockDepositEvents - get proof from api error: %s", "proof is nil") + } + zilProof := &ZILProof{ AccountProof: proof.AccountProof, } diff --git a/target_contracts.json b/target_contracts.json index 72d567d..5c8663f 100644 --- a/target_contracts.json +++ b/target_contracts.json @@ -1,8 +1,8 @@ [ { - "zil1v4v858qjqd5s88vvsj3qsn89nndeldkpwd9l2c": { - "inbound": [82], - "outbound": [82] + "zil1cfu4tpwqdf5zj9rdl7f6lmfn24q2x9kcnhjs8n": { + "inbound": [85], + "outbound": [85] } } ] \ No newline at end of file From a21bdff558e81f5650783ac65d2b8c2301c759b7 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 11 Mar 2021 11:45:10 +0800 Subject: [PATCH 042/107] fix: carefully handle poly current height --- service/poly2zil.go | 1 + service/polymanager.go | 8 ++++---- service/zil2poly.go | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/service/poly2zil.go b/service/poly2zil.go index 173ab3b..c2fe7d5 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -35,6 +35,7 @@ func (p *PolySyncManager) MonitorChain() { } latestHeight-- if latestHeight-p.currentHeight < config.OntUsefulBlockNum { + log.Infof("PolySyncManager MonitorChain - poly chain skip current height: %d", latestHeight) continue } log.Infof("PolySyncManager MonitorChain - poly chain current height: %d", latestHeight) diff --git a/service/polymanager.go b/service/polymanager.go index 1ba90a0..c789d6c 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -29,19 +29,19 @@ type PolySyncManager struct { func (p *PolySyncManager) init() bool { if p.currentHeight > 0 { - log.Infof("PolySyncManager init - start height from flag: %d\n", p.currentHeight) + log.Infof("PolySyncManager init - start height from flag: %d", p.currentHeight) return true } p.currentHeight = p.db.GetPolyHeight() + log.Infof("PolySyncManager init - get poly height from local storage: %d", p.currentHeight) latestHeight := p.findLatestHeight() + log.Infof("PolySyncManager init - get poly height from cross chain manager contract: %d", latestHeight) if latestHeight > p.currentHeight { p.currentHeight = latestHeight - log.Infof("PolyManager init - latest height from cross chain manager: %d\n", p.currentHeight) return true } - - log.Infof("PolyManager init - latest height from DB: %d\n", p.currentHeight) + log.Infof("PolySyncManager init - start height from flag: %d", p.currentHeight) return true } diff --git a/service/zil2poly.go b/service/zil2poly.go index d9b48f2..f0cf3af 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -206,14 +206,14 @@ func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { } heightString := new(string) *heightString = strconv.FormatUint(height, 10) - ccmc,_ := bech32.FromBech32Addr(s.cfg.ZilConfig.CrossChainManagerContract) - txIndexBigInt,_ := new(big.Int).SetString(crosstx.txIndex,16) + ccmc, _ := bech32.FromBech32Addr(s.cfg.ZilConfig.CrossChainManagerContract) + txIndexBigInt, _ := new(big.Int).SetString(crosstx.txIndex, 16) txIndexDecimal := txIndexBigInt.String() proof, err := s.zilSdk.GetStateProof(ccmc, "zilToPolyTxHashMap", []string{txIndexDecimal}, heightString) if err != nil { return fmt.Errorf("ZilliqaSyncManager - handleLockDepositEvents - get proof from api error: %s", err) } - log.Infof("ZilliqaSyncManager - handleLockDepositEvents get proof from zilliqa api endpoint: %+v, height is: %d\n", proof,height) + log.Infof("ZilliqaSyncManager - handleLockDepositEvents get proof from zilliqa api endpoint: %+v, height is: %d\n", proof, height) if proof == nil { return fmt.Errorf("ZilliqaSyncManager - handleLockDepositEvents - get proof from api error: %s", "proof is nil") @@ -423,13 +423,13 @@ func (s *ZilliqaSyncManager) rollBackToCommAncestor() { log.Warnf("rollBackToCommAncestor, fail to parse ds num, err: %s\n", err2) } - a,_ := s.zilSdk.GetDsBlockVerbose(txBlock.Header.DSBlockNum) + a, _ := s.zilSdk.GetDsBlockVerbose(txBlock.Header.DSBlockNum) b := core.NewDsBlockFromDsBlockT(a) txBlockOrDsBlock := core.TxBlockOrDsBlock{ DsBlock: b, } rawBlock, _ := json.Marshal(txBlockOrDsBlock) - s.header4sync = append(s.header4sync,rawBlock) + s.header4sync = append(s.header4sync, rawBlock) s.currentDsBlockNum = dsNum } From 616b0b878e9e95ab4be009e0eda93fc8552fcd1a Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 11 Mar 2021 12:22:57 +0800 Subject: [PATCH 043/107] doc: update readme --- README.md | 28 +++++++++++++++------------- config.yaml | 28 ++++++++++++++-------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 9ab4273..3664e76 100644 --- a/README.md +++ b/README.md @@ -42,30 +42,32 @@ Before running, you need feed the configuration file `config.yaml`. ```yaml zil_config: - zil_api: https://polynetworkcc3dcb2-5-api.dev.z7a.xyz - zil_chain_id: 333 + zil_api: https://api.ziiliqa.com + zil_chain_id: 111 zil_message_version: 1 - zil_start_height: 38 - zil_monitor_interval: 40 - corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f - side_chain_id: 1 - key_store_path: ./admin.keystore + zil_force_height: 0 + zil_monitor_interval: 10 + zil_headers_per_batch: 2 + corss_chain_manager_address: zil1tjru7m5zdn3x6k0t72nzmmpz62e5qds62nte9t + cross_chain_manager_proxy_address: zil1n7wkwr0xxslwsrhnqtjrwlus80dp5ncnlpaw93 + side_chain_id: 85 + key_store_path: admin.keystore key_store_pwd_set: - 7d48043742a1103042d327111746531ca26be9be: "pwd1" - de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7: "pwd2" + 6c89b62d65dc632e259b96f7ae2f1d68a27e3383: "" poly_config: poly_wallet_file: wallet.dat - poly_wallet_pwd: dummy - poly_monitor_interval: 40 + poly_wallet_pwd: + poly_start_height: 0 + poly_monitor_interval: 2 entrance_contract_address: "0300000000000000000000000000000000000000" - rest_url: http://beta1.poly.network + rest_url: http://poly.com +target_contracts: target_contracts.json ``` A sample keystore file could be: ```text {"address":"7d48043742a1103042d327111746531ca26be9be","id":"6cd445ed-8f5f-4565-af2a-cc2306a82b73","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"d136660a4e5664709031ebc162616556e8c812ab37d0157ea3276aa08d0a6c2d","kdf":"pbkdf2","mac":"b30dd459f1fd9d99c0b2f3452ccd2bf11414ad92d32ac70d1d7b52f17281b4e5","cipherparams":{"iv":"6a14f95c8cbafe7d1f317bec88e9d1b8"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"c4939e7cead32935d1972a2cd06d249dd501181e6ad2d1872fa0eb397d7fea20"}}} -{"address":"de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7","id":"e6ed9aba-7be3-40ca-8fab-7f9438fdf7cf","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"b96b59ea5861c7048f62cf15c219faa9e1494495030f42f021b6277622ab819f","kdf":"pbkdf2","mac":"ad06d0f0f5df29ad0947a62954ed08b084c2fc11aec66a36ab2c79eb1398768c","cipherparams":{"iv":"ef08dc8dbca886b1141e13fb7e988817"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"26bc16e8bc0dc2749c1cde2e62aa5c9990898c5c4d3f78c822fed2988c0ab682"}}} ``` ## Other Resources diff --git a/config.yaml b/config.yaml index 5bf3a99..3b4d84c 100644 --- a/config.yaml +++ b/config.yaml @@ -1,21 +1,21 @@ zil_config: - zil_api: https://dev-api.zilliqa.com/ - zil_chain_id: 333 + zil_api: https://api.ziiliqa.com + zil_chain_id: 111 zil_message_version: 1 - zil_start_height: 0 - zil_monitor_interval: 40 - corss_chain_manager_address: zil16vxy2u59sct5nupryxm3wfgteuhve9p0hp605f - cross_chain_manager_proxy_address: zil1urrkyfpww7rzhxh36m9nhksr5z73ragpar53nk - side_chain_id: 2 + zil_force_height: 0 + zil_monitor_interval: 10 + zil_headers_per_batch: 2 + corss_chain_manager_address: zil1tjru7m5zdn3x6k0t72nzmmpz62e5qds62nte9t + cross_chain_manager_proxy_address: zil1n7wkwr0xxslwsrhnqtjrwlus80dp5ncnlpaw93 + side_chain_id: 85 key_store_path: admin.keystore key_store_pwd_set: - 7d48043742a1103042d327111746531ca26be9be: "xiaohuo" - de0a0fbe9042aa165fb21e7b5e648162bcf1e8e7: "xiaohuo" + 6c89b62d65dc632e259b96f7ae2f1d68a27e3383: "" poly_config: poly_wallet_file: wallet.dat - poly_wallet_pwd: dummy - poly_start_height: 1 - poly_monitor_interval: 40 + poly_wallet_pwd: + poly_start_height: 0 + poly_monitor_interval: 2 entrance_contract_address: "0300000000000000000000000000000000000000" - rest_url: http://localhost:20336 - target_contracts: target_contracts.json \ No newline at end of file + rest_url: http://poly.com +target_contracts: target_contracts.json From 12f0f5c65fd5f2514f9ce07551f7bae3ddccbc89 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 11 Mar 2021 12:24:19 +0800 Subject: [PATCH 044/107] chore: typo --- README.md | 2 +- config.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3664e76..8029007 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Before running, you need feed the configuration file `config.yaml`. ```yaml zil_config: - zil_api: https://api.ziiliqa.com + zil_api: https://api.ziliqa.com zil_chain_id: 111 zil_message_version: 1 zil_force_height: 0 diff --git a/config.yaml b/config.yaml index 3b4d84c..a5ef07f 100644 --- a/config.yaml +++ b/config.yaml @@ -1,5 +1,5 @@ zil_config: - zil_api: https://api.ziiliqa.com + zil_api: https://api.zilliqa.com zil_chain_id: 111 zil_message_version: 1 zil_force_height: 0 From 3fcbc27a7895f2faa3b5712d7788a221c3957ce7 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 11 Mar 2021 12:27:22 +0800 Subject: [PATCH 045/107] chore: rename two wallets --- Dockerfile | 2 +- README.md | 6 +++--- config.yaml | 4 ++-- wallet.dat => poly.wallet | 0 service/polymanager.go | 4 ++-- admin.keystore => zilliqa.wallet | 0 6 files changed, 8 insertions(+), 8 deletions(-) rename wallet.dat => poly.wallet (100%) rename admin.keystore => zilliqa.wallet (100%) diff --git a/Dockerfile b/Dockerfile index 8f820ed..da63824 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN git clone https://github.com/Zilliqa/zilliqa-relayer.git && \ FROM ubuntu:18.04 WORKDIR /app COPY config.yaml config.yaml -COPY wallet.dat wallet.dat +COPY poly.wallet wallet.dat COPY run.sh run.sh COPY --from=build /app/zilliqa-relayer/zilliqa-relayer zilliqa-relayer CMD ["/bin/bash"] \ No newline at end of file diff --git a/README.md b/README.md index 8029007..cd7cb61 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Before running, you need feed the configuration file `config.yaml`. ```yaml zil_config: - zil_api: https://api.ziliqa.com + zil_api: https://api.zilliqa.com zil_chain_id: 111 zil_message_version: 1 zil_force_height: 0 @@ -51,11 +51,11 @@ zil_config: corss_chain_manager_address: zil1tjru7m5zdn3x6k0t72nzmmpz62e5qds62nte9t cross_chain_manager_proxy_address: zil1n7wkwr0xxslwsrhnqtjrwlus80dp5ncnlpaw93 side_chain_id: 85 - key_store_path: admin.keystore + key_store_path: zilliqa.wallet key_store_pwd_set: 6c89b62d65dc632e259b96f7ae2f1d68a27e3383: "" poly_config: - poly_wallet_file: wallet.dat + poly_wallet_file: poly.wallet poly_wallet_pwd: poly_start_height: 0 poly_monitor_interval: 2 diff --git a/config.yaml b/config.yaml index a5ef07f..a20781f 100644 --- a/config.yaml +++ b/config.yaml @@ -8,11 +8,11 @@ zil_config: corss_chain_manager_address: zil1tjru7m5zdn3x6k0t72nzmmpz62e5qds62nte9t cross_chain_manager_proxy_address: zil1n7wkwr0xxslwsrhnqtjrwlus80dp5ncnlpaw93 side_chain_id: 85 - key_store_path: admin.keystore + key_store_path: zilliqa.wallet key_store_pwd_set: 6c89b62d65dc632e259b96f7ae2f1d68a27e3383: "" poly_config: - poly_wallet_file: wallet.dat + poly_wallet_file: poly.wallet poly_wallet_pwd: poly_start_height: 0 poly_monitor_interval: 2 diff --git a/wallet.dat b/poly.wallet similarity index 100% rename from wallet.dat rename to poly.wallet diff --git a/service/polymanager.go b/service/polymanager.go index c789d6c..1cd693f 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -69,11 +69,11 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * } pwd := keystorepwdset[ks.Address] if pwd == nil { - return nil, errors.New("NewPolySyncManager - there is no password for admin.keystore: " + ks.Address) + return nil, errors.New("NewPolySyncManager - there is no password for zilliqa.wallet: " + ks.Address) } privateKey, err2 := descryptor.DecryptPrivateKey(keystore, pwd.(string)) if err2 != nil { - return nil, errors.New("NewPolySyncManager - descrypt admin.keystore error: " + err2.Error()) + return nil, errors.New("NewPolySyncManager - descrypt zilliqa.wallet error: " + err2.Error()) } // init cross chain smart contract proxy diff --git a/admin.keystore b/zilliqa.wallet similarity index 100% rename from admin.keystore rename to zilliqa.wallet From 70a7803d166f8feab4413a7491cfb95668b5e74f Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 16 Mar 2021 13:09:18 +0800 Subject: [PATCH 046/107] feat: select sender --- service/nonce_manager.go | 5 ----- service/poly2zil.go | 22 ++++++++++++++++++++-- service/zil_sender.go | 18 +++++++++++++----- 3 files changed, 33 insertions(+), 12 deletions(-) delete mode 100644 service/nonce_manager.go diff --git a/service/nonce_manager.go b/service/nonce_manager.go deleted file mode 100644 index 73b34ed..0000000 --- a/service/nonce_manager.go +++ /dev/null @@ -1,5 +0,0 @@ -package service - -// todo we don't consider nonce manager for now as mongo service is not completely exposed to public -type NonceManager struct { -} diff --git a/service/poly2zil.go b/service/poly2zil.go index c2fe7d5..1bf35c0 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -161,8 +161,26 @@ func (p *PolySyncManager) handleDepositEvents(height uint32) bool { } func (p *PolySyncManager) selectSender() *ZilSender { - // todo considering now we only have one admin which can control the contract - return p.senders[0] +S: + for _, sender := range p.senders { + s := p.isFreeSender(sender) + if s != nil { + return sender + } + } + log.Warn("Current no zilliqa sender can use, sleep 10 seconds and reselect") + time.Sleep(time.Second * 10) + goto S +} + +func (p *PolySyncManager) isFreeSender(sender *ZilSender) *ZilSender { + sender.mu.Lock() + defer sender.mu.Unlock() + if !sender.inUse { + sender.inUse = true + return sender + } + return nil } type EpochStartHeight struct { diff --git a/service/zil_sender.go b/service/zil_sender.go index eac8adf..faa35fd 100644 --- a/service/zil_sender.go +++ b/service/zil_sender.go @@ -15,16 +15,20 @@ import ( "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/tools" log "github.com/sirupsen/logrus" + "sync" ) type ZilSender struct { - cfg *config.Config - zilSdk *provider.Provider - address string //non-bech32 address + cfg *config.Config + zilSdk *provider.Provider + //non-bech32 address + address string privateKey string polySdk *poly_go_sdk.PolySdk crossChainProxy *polynetwork.Proxy + inUse bool + mu sync.Mutex } func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { @@ -49,7 +53,6 @@ func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, } } - // todo ensure that TxHash is bytes of hash, not utf8 bytes exist := sender.checkIfFromChainTxExist(param.FromChainID, util.EncodeHex(param.TxHash)) if exist { log.Infof("ZilSender commitDepositEventsWithHeader - already relayed to zil: (from_chain_id: %d, from_txhash: %x, param.TxHash: %x\n)", param.FromChainID, param.TxHash, param.MakeTxParam.TxHash) @@ -62,7 +65,6 @@ func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, } headerData = header.GetMessage() - // todo carefully test this pe := polynetwork.DeserializeProof(util.EncodeHex(rawAuditPath), 0) rawHeader := "0x" + util.EncodeHex(headerData) hpe := polynetwork.DeserializeProof(headerProof, 0) @@ -77,6 +79,9 @@ func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, } log.Infof("ZilSender commitDepositEventsWithHeader - confirmed transaction: %s\n", transaction.ID) + sender.mu.Lock() + sender.inUse = false + sender.mu.Unlock() return true } @@ -124,6 +129,9 @@ func (sender *ZilSender) commitHeader(hdr *polytypes.Header) bool { } log.Infof("ZilSender commitHeader - confirmed transaction: %s\n", transaction.ID) + sender.mu.Lock() + sender.inUse = false + sender.mu.Unlock() return true } From 54e404a41ae5529c9938e62984912da409e438d5 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 16 Mar 2021 13:31:19 +0800 Subject: [PATCH 047/107] fix: init sender --- service/polymanager.go | 1 + 1 file changed, 1 insertion(+) diff --git a/service/polymanager.go b/service/polymanager.go index 1cd693f..d321a75 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -95,6 +95,7 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * privateKey: privateKey, polySdk: polySdk, crossChainProxy: proxy, + inUse: false, } senders = append(senders, sender) From 1b40f14420a6b335ddd8e69a1e984a58088e7235 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 16 Mar 2021 13:41:06 +0800 Subject: [PATCH 048/107] chore: one more log --- service/polymanager.go | 1 + 1 file changed, 1 insertion(+) diff --git a/service/polymanager.go b/service/polymanager.go index d321a75..fbe1ed0 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -79,6 +79,7 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * // init cross chain smart contract proxy wallet := account.NewWallet() wallet.AddByPrivateKey(privateKey) + log.Infof("NewPolySyncManager get zilliqa wallet: %s", wallet.DefaultAccount.Address) proxy := &polynetwork.Proxy{ ProxyAddr: crossChainManagerProxy, ImplAddr: crossChainManager, From c9bc96a1c577bf8edd1df5f0a31ee3267ce25c32 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 17 Mar 2021 20:06:05 +0800 Subject: [PATCH 049/107] chore: update poly height --- service/poly2zil.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/service/poly2zil.go b/service/poly2zil.go index 1bf35c0..69c7afa 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -41,15 +41,16 @@ func (p *PolySyncManager) MonitorChain() { log.Infof("PolySyncManager MonitorChain - poly chain current height: %d", latestHeight) blockHandleResult = true for p.currentHeight <= latestHeight-config.OntUsefulBlockNum { - blockHandleResult = p.handleDepositEvents(p.currentHeight) + blockHandleResult = p.handleDepositEvents(p.currentHeight,latestHeight) if blockHandleResult == false { break } p.currentHeight++ + if err = p.db.UpdatePolyHeight(p.currentHeight - 1); err != nil { + log.Errorf("PolySyncManager MonitorChain - failed to save height of poly: %v", err) + } } - if err = p.db.UpdatePolyHeight(p.currentHeight - 1); err != nil { - log.Errorf("PolySyncManager MonitorChain - failed to save height of poly: %v", err) - } + case <-p.exitChan: return @@ -57,8 +58,8 @@ func (p *PolySyncManager) MonitorChain() { } } -func (p *PolySyncManager) handleDepositEvents(height uint32) bool { - log.Infof("PolySyncManager handleDepositEvents at height %d\n", height) +func (p *PolySyncManager) handleDepositEvents(height,latest uint32) bool { + log.Infof("PolySyncManager handleDepositEvents at height %d, latest height %d\n", height,latest) lastEpoch := p.findLatestHeight() hdr, err := p.polySdk.GetHeaderByHeight(height + 1) if err != nil { From dcb9243299984b34e07c7b3cfc660ec71b56a577 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 18 Mar 2021 08:04:31 +0800 Subject: [PATCH 050/107] fix: change keeper 0x issue --- service/poly2zil.go | 22 +++++++--------------- service/zil_sender.go | 17 ++++++++--------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/service/poly2zil.go b/service/poly2zil.go index 69c7afa..5a5b67c 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -41,7 +41,7 @@ func (p *PolySyncManager) MonitorChain() { log.Infof("PolySyncManager MonitorChain - poly chain current height: %d", latestHeight) blockHandleResult = true for p.currentHeight <= latestHeight-config.OntUsefulBlockNum { - blockHandleResult = p.handleDepositEvents(p.currentHeight,latestHeight) + blockHandleResult = p.handleDepositEvents(p.currentHeight, latestHeight) if blockHandleResult == false { break } @@ -58,8 +58,8 @@ func (p *PolySyncManager) MonitorChain() { } } -func (p *PolySyncManager) handleDepositEvents(height,latest uint32) bool { - log.Infof("PolySyncManager handleDepositEvents at height %d, latest height %d\n", height,latest) +func (p *PolySyncManager) handleDepositEvents(height, latest uint32) bool { + log.Infof("PolySyncManager handleDepositEvents at height %d, latest height %d\n", height, latest) lastEpoch := p.findLatestHeight() hdr, err := p.polySdk.GetHeaderByHeight(height + 1) if err != nil { @@ -164,26 +164,18 @@ func (p *PolySyncManager) handleDepositEvents(height,latest uint32) bool { func (p *PolySyncManager) selectSender() *ZilSender { S: for _, sender := range p.senders { - s := p.isFreeSender(sender) - if s != nil { + sender.mu.Lock() + if !sender.inUse { + sender.inUse = true return sender } + sender.mu.Unlock() } log.Warn("Current no zilliqa sender can use, sleep 10 seconds and reselect") time.Sleep(time.Second * 10) goto S } -func (p *PolySyncManager) isFreeSender(sender *ZilSender) *ZilSender { - sender.mu.Lock() - defer sender.mu.Unlock() - if !sender.inUse { - sender.inUse = true - return sender - } - return nil -} - type EpochStartHeight struct { CurEpochStartHeight string `json:"curEpochStartHeight"` } diff --git a/service/zil_sender.go b/service/zil_sender.go index faa35fd..834fbfc 100644 --- a/service/zil_sender.go +++ b/service/zil_sender.go @@ -32,6 +32,8 @@ type ZilSender struct { } func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { + sender.mu.Lock() + defer sender.mu.Unlock() // verifyHeaderAndExecuteTx var ( sigs []byte @@ -71,22 +73,21 @@ func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, curRawHeader := "0x" + util.EncodeHex(rawAnchor) signatures, _ := polynetwork.SplitSignature(util.EncodeHex(sigs)) - // todo use chan to handle result transaction, err := sender.crossChainProxy.VerifyHeaderAndExecuteTx(pe, rawHeader, hpe, curRawHeader, signatures) + sender.inUse = false if err != nil { log.Errorf("ZilSender commitDepositEventsWithHeader - failed to call VerifyHeaderAndExecuteTx: %s\n", err.Error()) return false } log.Infof("ZilSender commitDepositEventsWithHeader - confirmed transaction: %s\n", transaction.ID) - sender.mu.Lock() - sender.inUse = false - sender.mu.Unlock() return true } func (sender *ZilSender) commitHeader(hdr *polytypes.Header) bool { + sender.mu.Lock() + defer sender.mu.Unlock() headerdata := hdr.GetMessage() var ( bookkeepers []keypair.PublicKey @@ -118,20 +119,18 @@ func (sender *ZilSender) commitHeader(hdr *polytypes.Header) bool { publickeys = append(publickeys, tools.GetNoCompresskey(key)...) } - // todo carefully test this, add more useful logs - rawHeader := util.EncodeHex(headerdata) + rawHeader := "0x" + util.EncodeHex(headerdata) PubKeys, _ := polynetwork.SplitPubKeys(util.EncodeHex(publickeys)) signatures, _ := polynetwork.SplitSignature(util.EncodeHex(sigs)) transaction, err := sender.crossChainProxy.ChangeBookKeeper(rawHeader, PubKeys, signatures) + sender.inUse = false if err != nil { log.Errorf("ZilSender commitHeader - failed to call VerifyHeaderAndExecuteTx: %s\n", err.Error()) return false } log.Infof("ZilSender commitHeader - confirmed transaction: %s\n", transaction.ID) - sender.mu.Lock() - sender.inUse = false - sender.mu.Unlock() + return true } From 316c42adecf34a98c485b56740940d049305a175 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 18 Mar 2021 08:29:33 +0800 Subject: [PATCH 051/107] fix: mutex issue of selecting sender --- service/poly2zil.go | 10 +++++++++- service/zil_sender.go | 5 +---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/service/poly2zil.go b/service/poly2zil.go index 5a5b67c..91d8c8d 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -148,14 +148,19 @@ func (p *PolySyncManager) handleDepositEvents(height, latest uint32) bool { log.Infof("sender %s is handling poly tx ( hash: %s, height: %d )", sender.address, event.TxHash, height) // temporarily ignore the error for tx + sender.mu.Lock() sender.commitDepositEventsWithHeader(hdr, param, hp, anchor, event.TxHash, auditpath) + sender.mu.Unlock() } } } if cnt == 0 && isEpoch && isCurr { sender := p.selectSender() - return sender.commitHeader(hdr) + sender.mu.Lock() + res := sender.commitHeader(hdr) + sender.mu.Unlock() + return res } return true @@ -163,10 +168,13 @@ func (p *PolySyncManager) handleDepositEvents(height, latest uint32) bool { func (p *PolySyncManager) selectSender() *ZilSender { S: + log.Info("start select sender") for _, sender := range p.senders { sender.mu.Lock() if !sender.inUse { sender.inUse = true + sender.mu.Unlock() + log.Infof("sender %s selected",sender.address) return sender } sender.mu.Unlock() diff --git a/service/zil_sender.go b/service/zil_sender.go index 834fbfc..88e0305 100644 --- a/service/zil_sender.go +++ b/service/zil_sender.go @@ -32,8 +32,6 @@ type ZilSender struct { } func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { - sender.mu.Lock() - defer sender.mu.Unlock() // verifyHeaderAndExecuteTx var ( sigs []byte @@ -86,8 +84,7 @@ func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, } func (sender *ZilSender) commitHeader(hdr *polytypes.Header) bool { - sender.mu.Lock() - defer sender.mu.Unlock() + log.Infof("ZilSender commitHeader - height: %d\n", hdr.Height) headerdata := hdr.GetMessage() var ( bookkeepers []keypair.PublicKey From 4cd70db962fa0ac2c198e1974199aa16f3f9a5b0 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 24 Mar 2021 15:44:58 +0800 Subject: [PATCH 052/107] feat: nonce manager --- .gitignore | 5 +- go.mod | 2 +- go.sum | 4 + poly.wallet | 1 - service/nonce_manager.go | 256 ++++++++++++++++++++++++++++++++++ service/nonce_manager_test.go | 67 +++++++++ service/poly2zil.go | 31 ++-- service/polymanager.go | 30 ++++ service/zil_sender.go | 45 ++++++ target_contracts.json | 6 +- zilliqa.wallet | 1 - 11 files changed, 426 insertions(+), 22 deletions(-) delete mode 100644 poly.wallet create mode 100644 service/nonce_manager.go create mode 100644 service/nonce_manager_test.go delete mode 100644 zilliqa.wallet diff --git a/.gitignore b/.gitignore index bcb5c7b..bbd2dce 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ zilliqa-relayer bolt.bin config.local.yaml constants.xml -cross_chain_manager_admin.json \ No newline at end of file +cross_chain_manager_admin.json +xiaohuo.wallet +zilliqa.wallet +poly.wallet \ No newline at end of file diff --git a/go.mod b/go.mod index 054e008..fadb13b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210308032016-7002414861d8 + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210322040052-2d1a2d35fded github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta github.com/ethereum/go-ethereum v1.9.24 // indirect diff --git a/go.sum b/go.sum index b3912f4..7b164dd 100644 --- a/go.sum +++ b/go.sum @@ -72,6 +72,10 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210304105042-c4327211a4ba h1:o5WzAWq 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.20210308032016-7002414861d8 h1:6JJXeTfBSavuY2YlTbMuzLm6RGDEutPcqcs37AMO84c= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210308032016-7002414861d8/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210319095817-ba48ea16964d h1:YCdnGqR2hKpcr1+6/F9l6hhkqEmHlxrURKJsjOqu388= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210319095817-ba48ea16964d/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/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/poly.wallet b/poly.wallet deleted file mode 100644 index c27ee36..0000000 --- a/poly.wallet +++ /dev/null @@ -1 +0,0 @@ -{"name":"MyWallet","version":"1.1","scrypt":{"p":8,"n":16384,"r":8,"dkLen":64},"accounts":[{"address":"AXkyV73SHLLNKPkas644821MkRBM25ceLr","enc-alg":"aes-256-gcm","key":"y8uBh/Jv1cCEAxIT3iZaKZRd114RANsbOG1fEmnoiza570z/+QESBP14JxxykqtB","algorithm":"ECDSA","salt":"f698HosIenC1QdSxXREQlA==","parameters":{"curve":""},"label":"","publicKey":"1205032bddd046875a0f4c5d7cedefbe73299cf2e4365572ea2ddb4b6a466b0913027b","signatureScheme":"SHA256withECDSA","isDefault":true,"lock":false},{"address":"AWezM2zWAc1L9zHp122pRKzxs19mcSrSY5","enc-alg":"aes-256-gcm","key":"9ppCSGvBURnyPgKch7wc5CXl/YvAx9LZ1QfWxDTPN52WNOgjp43swbzxlg8yuBh+","algorithm":"ECDSA","salt":"DIJGj+utyd/SUyTXOhcbiQ==","parameters":{"curve":"P-256"},"label":"","publicKey":"022fca30a394a7249a8fe380f41640d946910959f265a1416dfb290d60308acbd6","signatureScheme":"SHA256withECDSA","isDefault":false,"lock":false},{"address":"AadiWhZjzAc7VGQHjHeTTaXbEdynQ2Z3x2","enc-alg":"aes-256-gcm","key":"SF30LxS8dZhcqS8FGlK/yHlu1wYmkIq/paUsYOIkmf5XnJYZPP8prp6l/u6gW5M8","algorithm":"ECDSA","salt":"FkQCQUg/lR2IgedR/lulOQ==","parameters":{"curve":"P-256"},"label":"","publicKey":"0300fffce1c29d8246c08da3327aed0d07700ab155786b23b505be672207761317","signatureScheme":"SHA256withECDSA","isDefault":false,"lock":false},{"address":"ANBye6W1i7D5bqMJUKfyvEQjJd4nctgARk","enc-alg":"aes-256-gcm","key":"2BYoCFhw8/ET1tvrE6Q26xS0cA8HsWCjiSoT9z2dwcMLkq2MxiKaXOdpOVE3DfsD","algorithm":"ECDSA","salt":"SKYvbVxZ/J2BfODuXQzl0A==","parameters":{"curve":"P-256"},"label":"","publicKey":"026ec74fc15eb7f2d27cb606524491fc8cff18126c486416b958448f7ebbe2de71","signatureScheme":"SHA256withECDSA","isDefault":false,"lock":false},{"address":"AG9T5VUoAEttkiUv8YzKHMKMcouojSixtf","enc-alg":"aes-256-gcm","key":"FKOQsfEduP+NiPXshp5zOm7Gz6kTnIIPd1qGB9+r497Op1lk+OxBHqyetZVvL6pL","algorithm":"ECDSA","salt":"AfKCyBh1d1xhyNN+rLPrsA==","parameters":{"curve":"P-256"},"label":"","publicKey":"02dee4455378f2a41b787a93ceec9e1d26466006bd135906c406806d849e4ee17b","signatureScheme":"SHA256withECDSA","isDefault":false,"lock":false},{"address":"AV6UgAiH63eDTx1PV5JMYWFm6xnKyqnaxA","enc-alg":"aes-256-gcm","key":"KK8vjSVXBboiiaGIAZ4GYTd51vmV7+LrfNq5nm+MF0eXeozS3gqjaItNpSHCCUmg","algorithm":"ECDSA","salt":"kQcpQMLgDRDDLfxJVxqKWQ==","parameters":{"curve":"P-256"},"label":"","publicKey":"02dd1156ae4d7dc9cc65a50908c5dd1368f5b2267f47a166520cb0ec3aa2f32736","signatureScheme":"SHA256withECDSA","isDefault":false,"lock":false}]} \ No newline at end of file diff --git a/service/nonce_manager.go b/service/nonce_manager.go new file mode 100644 index 0000000..65a6756 --- /dev/null +++ b/service/nonce_manager.go @@ -0,0 +1,256 @@ +package service + +import ( + "github.com/Zilliqa/gozilliqa-sdk/account" + "github.com/Zilliqa/gozilliqa-sdk/keytools" + "github.com/Zilliqa/gozilliqa-sdk/provider" + "github.com/Zilliqa/gozilliqa-sdk/transaction" + "github.com/Zilliqa/gozilliqa-sdk/util" + polytypes "github.com/polynetwork/poly/core/types" + common2 "github.com/polynetwork/poly/native/service/cross_chain_manager/common" + log "github.com/sirupsen/logrus" + "math" + "strconv" + "sync" + "time" +) + +const MaxExistTxEpoch = 200 + +type NonceAndSender struct { + Sender *ZilSender + LocalNonce int64 +} + +type TransactionWithAge struct { + Txn *transaction.Transaction + StartTxBlock uint64 + Age int +} + +type NonceManager struct { + UpdateInterval int64 + ZilClient *provider.Provider + // address => hash => transaction + SentTransactions map[string]map[string]TransactionWithAge + LockSentTransaction sync.Mutex + // address => list of transaction hash + ConfirmedTransactions map[string][]string + // private key => nonce and sender + ZilSenderMap map[string]*NonceAndSender + SenderPrivateKeys []string + CurrentIndex int +} + +func (nm *NonceManager) Run() { + log.Infof("starting nonce manager...") + for { + time.Sleep(time.Second * time.Duration(nm.UpdateInterval)) + nm.stat() + } +} + +func (nm *NonceManager) send(txn *transaction.Transaction) bool { + currentSenderPrivateKey := nm.SenderPrivateKeys[nm.CurrentIndex] + nm.CurrentIndex++ + if nm.CurrentIndex > len(nm.SenderPrivateKeys)-1 { + nm.CurrentIndex = 0 + } + + currentSender := nm.ZilSenderMap[currentSenderPrivateKey].Sender + log.Infof("NonceManager - send use sender %s", currentSender.address) + nonce := strconv.FormatUint(uint64(nm.ZilSenderMap[currentSenderPrivateKey].LocalNonce+1), 10) + + txn.Nonce = nonce + txn.SenderPubKey = util.EncodeHex(keytools.GetPublicKeyFromPrivateKey(util.DecodeHex(currentSender.privateKey), true)) + txn.Priority = true + + wallet := account.NewWallet() + wallet.AddByPrivateKey(currentSender.privateKey) + _ = wallet.Sign(txn, *currentSender.zilSdk) + nm.LockSentTransaction.Lock() + resp, err := currentSender.zilSdk.CreateTransaction(txn.ToTransactionPayload()) + + if err != nil || resp.Error != nil { + if err != nil { + log.Warnf("NonceManager - send error %s", err.Error()) + return false + } + log.Warnf("NonceManager - send error %s", resp.Error) + return false + } + + log.Infof("NonceManager - transaction response is: %+v", resp) + + hash, _ := txn.Hash() + + // handle nonce + nm.ZilSenderMap[currentSenderPrivateKey] = &NonceAndSender{ + Sender: nm.ZilSenderMap[currentSenderPrivateKey].Sender, + LocalNonce: nm.ZilSenderMap[currentSenderPrivateKey].LocalNonce + 1, + } + + outerMap := nm.SentTransactions[currentSender.address] + if outerMap == nil { + outerMap = make(map[string]TransactionWithAge) + } + outerMap[util.EncodeHex(hash)] = TransactionWithAge{ + Txn: txn, + Age: 0, + } + nm.SentTransactions[currentSender.address] = outerMap + nm.LockSentTransaction.Unlock() + + return true +} + +func (nm *NonceManager) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { + nm.LockSentTransaction.Lock() + currentSenderPrivateKey := nm.SenderPrivateKeys[nm.CurrentIndex] + nm.CurrentIndex++ + if nm.CurrentIndex > len(nm.SenderPrivateKeys)-1 { + nm.CurrentIndex = 0 + } + + currentSender := nm.ZilSenderMap[currentSenderPrivateKey].Sender + log.Infof("NonceManager - commitDepositEventsWithHeader use sender %s", currentSender.address) + nonce := strconv.FormatUint(uint64(nm.ZilSenderMap[currentSenderPrivateKey].LocalNonce+1), 10) + txn, err := currentSender.commitDepositEventsWithHeaderWithNonce(header, param, headerProof, anchorHeader, polyTxHash, rawAuditPath, nonce) + if err != nil { + log.Warnf("NonceManager - commitDepositEventsWithHeaderWithNonce error %s", err.Error()) + return false + } + + hash, _ := txn.Hash() + + // handle nonce + nm.ZilSenderMap[currentSenderPrivateKey] = &NonceAndSender{ + Sender: nm.ZilSenderMap[currentSenderPrivateKey].Sender, + LocalNonce: nm.ZilSenderMap[currentSenderPrivateKey].LocalNonce + 1, + } + + outerMap := nm.SentTransactions[currentSender.address] + if outerMap == nil { + outerMap = make(map[string]TransactionWithAge) + } + outerMap[util.EncodeHex(hash)] = TransactionWithAge{ + Txn: txn, + Age: 0, + } + nm.SentTransactions[currentSender.address] = outerMap + nm.LockSentTransaction.Unlock() + return true +} + +func (nm *NonceManager) stat() { + txBlock, err := nm.ZilClient.GetLatestTxBlock() + if err != nil { + log.Warnf("NonceManager - get current tx block number error: %s", err.Error()) + return + } + currentTxEpoch, _ := strconv.ParseUint(txBlock.Header.BlockNum, 10, 64) + log.Infof("NonceManager - current tx block number is: %s", txBlock.Header.BlockNum) + for _, key := range nm.SenderPrivateKeys { + addr := keytools.GetAddressFromPrivateKey(util.DecodeHex(key)) + balAndNonce, err := nm.ZilClient.GetBalance(addr) + if err != nil { + log.Warnf("NonceManager - get nonce for address %s error %s", addr, err.Error()) + continue + } + + // print some stat info about this address + log.Infof("NonceManager - address %s, local nonce = %d, remote nonce = %d", addr, nm.ZilSenderMap[key].LocalNonce, balAndNonce.Nonce) + log.Infof("NonceManager - sent transactions: %+v", nm.SentTransactions[addr]) + log.Infof("NonceManager - confimred transactions: %+v", len(nm.ConfirmedTransactions[addr])) + + // check sent transactions + log.Infof("NonceManager - check sent transactions") + nm.LockSentTransaction.Lock() + var confirmedTxn []string + + sentTransactionMap := nm.SentTransactions[addr] + for hash, txn := range sentTransactionMap { + log.Infof("NonceManager - check transaction %s", hash) + _, err := nm.ZilClient.GetTransaction(hash) + + if err == nil { + log.Infof("NonceManager - transaction %s confirmed", hash) + confirmedTxn = append(confirmedTxn, hash) + } else { + // if start block is 0, try to give it a number first + if sentTransactionMap[hash].StartTxBlock == 0 { + log.Infof("NonceManager - stat try to determine start tx block for hash: %s", hash) + transactionStatus, err := nm.ZilClient.GetTransactionStatus(hash) + if err != nil { + log.Warnf("NonceManager - get transaction status error, hash is %s, err is %s", hash, err.Error()) + } else { + age := 0 + epoch, _ := strconv.ParseUint(transactionStatus.EpochInserted, 10, 64) + if currentTxEpoch > epoch { + age = int(currentTxEpoch - epoch) + } + + sentTransactionMap[hash] = TransactionWithAge{ + Txn: txn.Txn, + StartTxBlock: epoch, + Age: age, + } + } + } else { + log.Warnf("NonceManager - stat already has inserted epoch, update age, hash is %s", hash) + age := 0 + if currentTxEpoch > sentTransactionMap[hash].StartTxBlock { + age = int(currentTxEpoch - sentTransactionMap[hash].StartTxBlock) + } + sentTransactionMap[hash] = TransactionWithAge{ + Txn: txn.Txn, + StartTxBlock: txn.StartTxBlock, + Age: age, + } + } + } + + } + + for _, hash := range confirmedTxn { + delete(sentTransactionMap, hash) + nm.ConfirmedTransactions[addr] = append(nm.ConfirmedTransactions[addr], hash) + } + nm.SentTransactions[addr] = sentTransactionMap + + // print some stat info about this address again + log.Infof("NonceManager - sent transactions: %+v", nm.SentTransactions[addr]) + log.Infof("NonceManager - confimred transactions: %+v", len(nm.ConfirmedTransactions[addr])) + + // detect dead transactions + log.Infof("NonceManager - stat start to detect dead transactions") + currentNonce := uint64(math.MaxUint64) + for hash, txn := range nm.SentTransactions[addr] { + if txn.Age > MaxExistTxEpoch { + log.Warnf("NonceManager - stat found dead transaction, hash: %s, nonce is %s", hash, txn.Txn.Nonce) + log.Warnf("NonceManager - stat current nonce is: %d", currentNonce) + nonce, _ := strconv.ParseUint(txn.Txn.Nonce, 10, 64) + if currentNonce > nonce { + log.Warnf("NonceManager - stat replace current nonce with it") + currentNonce = nonce + } + } + } + + if currentNonce == math.MaxUint64 { + log.Infof("NonceManager - stat no dead found") + } else { + log.Infof("NonceManager - stat dead transaction, bad nonce is: %d, start to resend transactions", currentNonce) + for hash, txn := range nm.SentTransactions[addr] { + nonce, _ := strconv.ParseUint(txn.Txn.Nonce, 10, 64) + if nonce >= currentNonce { + log.Infof("NonceManager - stat start to resend transaction %s, nonce %d", hash, nonce) + // todo handle error + nm.ZilClient.CreateTransaction(txn.Txn.ToTransactionPayload()) + } + } + + } + nm.LockSentTransaction.Unlock() + } +} diff --git a/service/nonce_manager_test.go b/service/nonce_manager_test.go new file mode 100644 index 0000000..17637d5 --- /dev/null +++ b/service/nonce_manager_test.go @@ -0,0 +1,67 @@ +package service + +import ( + "github.com/Zilliqa/gozilliqa-sdk/keytools" + "github.com/Zilliqa/gozilliqa-sdk/provider" + "github.com/Zilliqa/gozilliqa-sdk/transaction" + "github.com/Zilliqa/gozilliqa-sdk/util" + "strconv" + "testing" + "time" +) + +func TestNonceManager_Run(t *testing.T) { + zilClient := provider.NewProvider("https://dev-api.zilliqa.com/") + privateKey := "e53d1c3edaffc7a7bab5418eb836cf75819a82872b4a1a0f1c7fcf5c3e020b89" + addr := keytools.GetAddressFromPrivateKey(util.DecodeHex(privateKey)) + zilSender := &ZilSender{ + zilSdk: zilClient, + address: addr, + privateKey: privateKey, + } + balAndNonce, _ := zilClient.GetBalance(zilSender.address) + nonceAndSender := &NonceAndSender{ + Sender: zilSender, + LocalNonce: balAndNonce.Nonce, + } + + zilSenderMap := make(map[string]*NonceAndSender) + zilSenderMap[privateKey] = nonceAndSender + + senderPrivateKeys := []string{privateKey} + + nm := NonceManager{ + UpdateInterval: 30, + ZilClient: zilClient, + SentTransactions: make(map[string]map[string]TransactionWithAge), + ConfirmedTransactions: make(map[string][]string), + ZilSenderMap: zilSenderMap, + SenderPrivateKeys: senderPrivateKeys, + CurrentIndex: 0, + } + + go nm.Run() + + txn := &transaction.Transaction{ + Version: strconv.FormatInt(int64(util.Pack(333, 1)), 10), + ToAddr: "4BAF5faDA8e5Db92C3d3242618c5B47133AE003C", + Amount: "10000000", + GasPrice: "2000000000", + GasLimit: "1", + Code: "", + Data: "", + Priority: false, + } + + for i := 0; i < 10; i++ { + nm.send(txn) + } + + time.Sleep(time.Second * 5) + + for i := 0; i < 20; i++ { + nm.send(txn) + } + + WaitToExit() +} diff --git a/service/poly2zil.go b/service/poly2zil.go index 91d8c8d..fa098e2 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -144,24 +144,25 @@ func (p *PolySyncManager) handleDepositEvents(height, latest uint32) bool { } } cnt++ - sender := p.selectSender() - log.Infof("sender %s is handling poly tx ( hash: %s, height: %d )", - sender.address, event.TxHash, height) - // temporarily ignore the error for tx - sender.mu.Lock() - sender.commitDepositEventsWithHeader(hdr, param, hp, anchor, event.TxHash, auditpath) - sender.mu.Unlock() + p.nonceManager.commitDepositEventsWithHeader(hdr, param, hp, anchor, event.TxHash, auditpath) + //sender := p.selectSender() + //log.Infof("sender %s is handling poly tx ( hash: %s, height: %d )", + // sender.address, event.TxHash, height) + //// temporarily ignore the error for tx + //sender.mu.Lock() + //sender.commitDepositEventsWithHeader(hdr, param, hp, anchor, event.TxHash, auditpath) + //sender.mu.Unlock() } } } - if cnt == 0 && isEpoch && isCurr { - sender := p.selectSender() - sender.mu.Lock() - res := sender.commitHeader(hdr) - sender.mu.Unlock() - return res - } + //if cnt == 0 && isEpoch && isCurr { + // sender := p.selectSender() + // sender.mu.Lock() + // res := sender.commitHeader(hdr) + // sender.mu.Unlock() + // return res + //} return true } @@ -174,7 +175,7 @@ S: if !sender.inUse { sender.inUse = true sender.mu.Unlock() - log.Infof("sender %s selected",sender.address) + log.Infof("sender %s selected", sender.address) return sender } sender.mu.Unlock() diff --git a/service/polymanager.go b/service/polymanager.go index fbe1ed0..aab042a 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -25,6 +25,7 @@ type PolySyncManager struct { crossChainManager string crossChainManagerProxy string senders []*ZilSender + nonceManager *NonceManager } func (p *PolySyncManager) init() bool { @@ -48,6 +49,7 @@ func (p *PolySyncManager) init() bool { func (p *PolySyncManager) Run(enable bool) { if enable { go p.MonitorChain() + go p.nonceManager.Run() } } @@ -60,6 +62,8 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * descryptor := crypto.NewDefaultKeystore() var senders []*ZilSender + var privateKeys []string + zilSenderMap := make(map[string]*NonceAndSender, 0) for _, keystore := range keystores { var ks crypto.KeystoreV3 @@ -100,6 +104,31 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * } senders = append(senders, sender) + + balAndNonce, err3 := zilSdk.GetBalance(ks.Address) + if err3 != nil { + log.Infof("NewPolySyncManager get address %s nonce error %s", ks.Address, err3.Error()) + continue + } + + privateKeyAndNonce := &NonceAndSender{ + Sender: sender, + LocalNonce: balAndNonce.Nonce, + } + + privateKeys = append(privateKeys, privateKey) + zilSenderMap[privateKey] = privateKeyAndNonce + + } + + nonceManager := &NonceManager{ + UpdateInterval: 30, + ZilClient: zilSdk, + SentTransactions: make(map[string]map[string]TransactionWithAge), + ConfirmedTransactions: make(map[string][]string), + SenderPrivateKeys: privateKeys, + ZilSenderMap: zilSenderMap, + CurrentIndex: 0, } return &PolySyncManager{ @@ -112,5 +141,6 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * crossChainManager: crossChainManager, crossChainManagerProxy: crossChainManagerProxy, senders: senders, + nonceManager: nonceManager, }, nil } diff --git a/service/zil_sender.go b/service/zil_sender.go index 88e0305..d359f65 100644 --- a/service/zil_sender.go +++ b/service/zil_sender.go @@ -3,8 +3,10 @@ package service import ( "encoding/hex" "encoding/json" + "errors" "github.com/Zilliqa/gozilliqa-sdk/crosschain/polynetwork" "github.com/Zilliqa/gozilliqa-sdk/provider" + "github.com/Zilliqa/gozilliqa-sdk/transaction" "github.com/Zilliqa/gozilliqa-sdk/util" "github.com/ontio/ontology-crypto/keypair" "github.com/ontio/ontology-crypto/signature" @@ -31,6 +33,49 @@ type ZilSender struct { mu sync.Mutex } +func (sender *ZilSender) commitDepositEventsWithHeaderWithNonce(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte, nonce string) (*transaction.Transaction, error) { + // verifyHeaderAndExecuteTx + var ( + sigs []byte + headerData []byte + ) + if anchorHeader != nil && headerProof != "" { + for _, sig := range anchorHeader.SigData { + temp := make([]byte, len(sig)) + copy(temp, sig) + newsig, _ := signature.ConvertToEthCompatible(temp) + sigs = append(sigs, newsig...) + } + } else { + for _, sig := range header.SigData { + temp := make([]byte, len(sig)) + copy(temp, sig) + newsig, _ := signature.ConvertToEthCompatible(temp) + sigs = append(sigs, newsig...) + } + } + + exist := sender.checkIfFromChainTxExist(param.FromChainID, util.EncodeHex(param.TxHash)) + if exist { + log.Infof("ZilSender commitDepositEventsWithHeader - already relayed to zil: (from_chain_id: %d, from_txhash: %x, param.TxHash: %x\n)", param.FromChainID, param.TxHash, param.MakeTxParam.TxHash) + return nil, errors.New("ZilSender commitDepositEventsWithHeader - already relayed to zil") + } + + var rawAnchor []byte + if anchorHeader != nil { + rawAnchor = anchorHeader.GetMessage() + } + headerData = header.GetMessage() + + pe := polynetwork.DeserializeProof(util.EncodeHex(rawAuditPath), 0) + rawHeader := "0x" + util.EncodeHex(headerData) + hpe := polynetwork.DeserializeProof(headerProof, 0) + curRawHeader := "0x" + util.EncodeHex(rawAnchor) + signatures, _ := polynetwork.SplitSignature(util.EncodeHex(sigs)) + + return sender.crossChainProxy.VerifyHeaderAndExecuteTxWithNonce(pe, rawHeader, hpe, curRawHeader, signatures, nonce) +} + func (sender *ZilSender) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { // verifyHeaderAndExecuteTx var ( diff --git a/target_contracts.json b/target_contracts.json index 5c8663f..f755f41 100644 --- a/target_contracts.json +++ b/target_contracts.json @@ -1,8 +1,8 @@ [ { - "zil1cfu4tpwqdf5zj9rdl7f6lmfn24q2x9kcnhjs8n": { - "inbound": [85], - "outbound": [85] + "zil1v4v858qjqd5s88vvsj3qsn89nndeldkpwd9l2c": { + "inbound": [202], + "outbound": [202] } } ] \ No newline at end of file diff --git a/zilliqa.wallet b/zilliqa.wallet deleted file mode 100644 index 9c77fa8..0000000 --- a/zilliqa.wallet +++ /dev/null @@ -1 +0,0 @@ -{"address":"6c89b62d65dc632e259b96f7ae2f1d68a27e3383","id":"e4716195-8342-4d37-9dac-49340ac8468c","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"76828f408c3abdbe39a5221cb601de45a3af9ce1352a9d01a7211c719a482f14","kdf":"pbkdf2","mac":"8b361a8ac463f2eac9625361d66aa6157b1b0fd8ee1db4649f528eff5728f632","cipherparams":{"iv":"b7ca9f85fbb2574e6bafe82a110fbea2"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"37c830e060703f320a1756f2fd49ce74bfbdfaf45b111b2e1d5342e6e52705e6"}}} From df1eace6f932f96ca9386dea328f5425c7fe758f Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 24 Mar 2021 15:46:17 +0800 Subject: [PATCH 053/107] chore: update gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bbd2dce..d255c1a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ constants.xml cross_chain_manager_admin.json xiaohuo.wallet zilliqa.wallet -poly.wallet \ No newline at end of file +poly.wallet +relayer.wallet \ No newline at end of file From 6718e14f8bcb1698b95391063bb6ad4fb5c40394 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Fri, 26 Mar 2021 11:39:31 +0800 Subject: [PATCH 054/107] feat: commit header without blocking --- go.mod | 2 +- go.sum | 2 ++ service/nonce_manager.go | 38 ++++++++++++++++++++++++++++++++++++++ service/poly2zil.go | 15 ++++++++------- service/zil_sender.go | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index fadb13b..71d6dd2 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210322040052-2d1a2d35fded + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210324082803-7bad2d49a99e github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta github.com/ethereum/go-ethereum v1.9.24 // indirect diff --git a/go.sum b/go.sum index 7b164dd..343a820 100644 --- a/go.sum +++ b/go.sum @@ -76,6 +76,8 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210319095817-ba48ea16964d h1:YCdnGqR github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210319095817-ba48ea16964d/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.20210324082803-7bad2d49a99e h1:ltcsP84eL0lEni4lMRo+4s0squQgkkoTfRE/r8IyyuU= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210324082803-7bad2d49a99e/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/service/nonce_manager.go b/service/nonce_manager.go index 65a6756..bba5429 100644 --- a/service/nonce_manager.go +++ b/service/nonce_manager.go @@ -50,6 +50,7 @@ func (nm *NonceManager) Run() { } } +// only for test purpose func (nm *NonceManager) send(txn *transaction.Transaction) bool { currentSenderPrivateKey := nm.SenderPrivateKeys[nm.CurrentIndex] nm.CurrentIndex++ @@ -104,6 +105,43 @@ func (nm *NonceManager) send(txn *transaction.Transaction) bool { return true } +func (nm *NonceManager) commitHeader(hdr *polytypes.Header) bool { + nm.LockSentTransaction.Lock() + currentSenderPrivateKey := nm.SenderPrivateKeys[nm.CurrentIndex] + nm.CurrentIndex++ + if nm.CurrentIndex > len(nm.SenderPrivateKeys)-1 { + nm.CurrentIndex = 0 + } + currentSender := nm.ZilSenderMap[currentSenderPrivateKey].Sender + log.Infof("NonceManager - commitHeader use sender %s", currentSender.address) + nonce := strconv.FormatUint(uint64(nm.ZilSenderMap[currentSenderPrivateKey].LocalNonce+1), 10) + txn, err := currentSender.commitHeaderWithNonce(hdr, nonce) + if err != nil { + log.Warnf("NonceManager - commitHeader error %s", err.Error()) + return false + } + + hash, _ := txn.Hash() + + // handle nonce + nm.ZilSenderMap[currentSenderPrivateKey] = &NonceAndSender{ + Sender: nm.ZilSenderMap[currentSenderPrivateKey].Sender, + LocalNonce: nm.ZilSenderMap[currentSenderPrivateKey].LocalNonce + 1, + } + + outerMap := nm.SentTransactions[currentSender.address] + if outerMap == nil { + outerMap = make(map[string]TransactionWithAge) + } + outerMap[util.EncodeHex(hash)] = TransactionWithAge{ + Txn: txn, + Age: 0, + } + nm.SentTransactions[currentSender.address] = outerMap + nm.LockSentTransaction.Unlock() + return true +} + func (nm *NonceManager) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { nm.LockSentTransaction.Lock() currentSenderPrivateKey := nm.SenderPrivateKeys[nm.CurrentIndex] diff --git a/service/poly2zil.go b/service/poly2zil.go index fa098e2..e7f2aa1 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -156,13 +156,14 @@ func (p *PolySyncManager) handleDepositEvents(height, latest uint32) bool { } } - //if cnt == 0 && isEpoch && isCurr { - // sender := p.selectSender() - // sender.mu.Lock() - // res := sender.commitHeader(hdr) - // sender.mu.Unlock() - // return res - //} + if cnt == 0 && isEpoch && isCurr { + return p.nonceManager.commitHeader(hdr) + //sender := p.selectSender() + //sender.mu.Lock() + //res := sender.commitHeader(hdr) + //sender.mu.Unlock() + //return res + } return true } diff --git a/service/zil_sender.go b/service/zil_sender.go index d359f65..b0d3abb 100644 --- a/service/zil_sender.go +++ b/service/zil_sender.go @@ -176,3 +176,41 @@ func (sender *ZilSender) commitHeader(hdr *polytypes.Header) bool { return true } + +func (sender *ZilSender) commitHeaderWithNonce(hdr *polytypes.Header, nonce string) (*transaction.Transaction, error) { + log.Infof("ZilSender commitHeader - height: %d\n", hdr.Height) + headerdata := hdr.GetMessage() + var ( + bookkeepers []keypair.PublicKey + sigs []byte + ) + + for _, sig := range hdr.SigData { + temp := make([]byte, len(sig)) + copy(temp, sig) + newsig, _ := signature.ConvertToEthCompatible(temp) + sigs = append(sigs, newsig...) + } + + blkInfo := &vconfig.VbftBlockInfo{} + if err := json.Unmarshal(hdr.ConsensusPayload, blkInfo); err != nil { + return nil, err + } + + for _, peer := range blkInfo.NewChainConfig.Peers { + keystr, _ := hex.DecodeString(peer.ID) + key, _ := keypair.DeserializePublicKey(keystr) + bookkeepers = append(bookkeepers, key) + } + + bookkeepers = keypair.SortPublicKeys(bookkeepers) + publickeys := make([]byte, 0) + for _, key := range bookkeepers { + publickeys = append(publickeys, tools.GetNoCompresskey(key)...) + } + + rawHeader := "0x" + util.EncodeHex(headerdata) + PubKeys, _ := polynetwork.SplitPubKeys(util.EncodeHex(publickeys)) + signatures, _ := polynetwork.SplitSignature(util.EncodeHex(sigs)) + return sender.crossChainProxy.ChangeBookKeeperWithNonce(rawHeader, PubKeys, signatures, nonce) +} From c58e826cb2cc3465a8234459f1ed9903ff09ce9b Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Mon, 29 Mar 2021 17:45:01 +0800 Subject: [PATCH 055/107] feat: support hashed storage key --- go.mod | 2 +- go.sum | 4 ++++ service/zil2poly.go | 7 ++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 71d6dd2..39d576a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210324082803-7bad2d49a99e + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210329093354-1b8e0a7a2e25 github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta github.com/ethereum/go-ethereum v1.9.24 // indirect diff --git a/go.sum b/go.sum index 343a820..c1ce33a 100644 --- a/go.sum +++ b/go.sum @@ -78,6 +78,10 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210322040052-2d1a2d35fded h1:FqdR17d 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.20210324082803-7bad2d49a99e h1:ltcsP84eL0lEni4lMRo+4s0squQgkkoTfRE/r8IyyuU= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210324082803-7bad2d49a99e/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210329090957-47fa84b98939 h1:AvHW2baBlvOyni0yC7/TesgYQIu2GMcc4U9oMGZn65A= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210329090957-47fa84b98939/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= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/service/zil2poly.go b/service/zil2poly.go index f0cf3af..1ae0e77 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -209,7 +209,9 @@ func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { ccmc, _ := bech32.FromBech32Addr(s.cfg.ZilConfig.CrossChainManagerContract) txIndexBigInt, _ := new(big.Int).SetString(crosstx.txIndex, 16) txIndexDecimal := txIndexBigInt.String() - proof, err := s.zilSdk.GetStateProof(ccmc, "zilToPolyTxHashMap", []string{txIndexDecimal}, heightString) + storageKey := core.GenerateStorageKey(ccmc, "zilToPolyTxHashMap", []string{txIndexDecimal}) + hashedStorageKey := util.Sha256(storageKey) + proof, err := s.zilSdk.GetStateProof(ccmc, util.EncodeHex(hashedStorageKey), heightString) if err != nil { return fmt.Errorf("ZilliqaSyncManager - handleLockDepositEvents - get proof from api error: %s", err) } @@ -223,8 +225,7 @@ func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { AccountProof: proof.AccountProof, } - skey := core.GenerateStorageKey("zilToPolyTxHashMap", []string{txIndexDecimal}) - hexskey := util.EncodeHex(skey) + hexskey := util.EncodeHex(storageKey) storageProof := StorageProof{ Key: []byte(hexskey), Value: crosstx.value, From fe9c704113549315d1f66b88fc8411360375f399 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 31 Mar 2021 11:16:06 +0800 Subject: [PATCH 056/107] fix: lowercase cmcc, in order to geneate correct storage key --- service/zil2poly.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index 1ae0e77..acd7be6 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -54,6 +54,7 @@ func (s *ZilliqaSyncManager) MonitorChain() { if uint32(len(s.header4sync)) > s.cfg.ZilConfig.ZilHeadersPerBatch { log.Infof("ZilliqaSyncManager MonitorChain - commit header") if res := s.commitHeader(); res != 0 { + log.Errorf("ZilliqaSyncManager MonitorChain -- commit header error, result %d",res) blockHandleResult = false break } @@ -207,6 +208,7 @@ func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { heightString := new(string) *heightString = strconv.FormatUint(height, 10) ccmc, _ := bech32.FromBech32Addr(s.cfg.ZilConfig.CrossChainManagerContract) + ccmc = strings.ToLower(ccmc) txIndexBigInt, _ := new(big.Int).SetString(crosstx.txIndex, 16) txIndexDecimal := txIndexBigInt.String() storageKey := core.GenerateStorageKey(ccmc, "zilToPolyTxHashMap", []string{txIndexDecimal}) @@ -376,8 +378,14 @@ func (s *ZilliqaSyncManager) commitHeader() int { tick := time.NewTicker(100 * time.Millisecond) var h uint32 for range tick.C { - h, _ = s.polySdk.GetBlockHeightByTxHash(tx.ToHexString()) - curr, _ := s.polySdk.GetCurrentBlockHeight() + h, err = s.polySdk.GetBlockHeightByTxHash(tx.ToHexString()) + if err != nil { + log.Warnf("ZilliqaSyncManager commitHeader get block height by hash, hash: %s error: %s",tx.ToHexString(),err.Error()) + } + curr, err2 := s.polySdk.GetCurrentBlockHeight() + if err2 != nil { + log.Warnf("ZilliqaSyncManager commitHeader get current block height error: %s",err2.Error()) + } if h > 0 && curr > h { break } From d6a6e60bd10c1c635b8078b17474ae300df2bcf6 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 8 Apr 2021 21:51:11 +0800 Subject: [PATCH 057/107] feat: enhance nonce manager --- cmd/run.go | 1 + config.yaml | 1 + config/config.go | 1 + service/nonce_manager.go | 46 ++++++++++++++++++++++++---------------- service/polymanager.go | 1 + service/zil2poly.go | 12 ++++++----- 6 files changed, 39 insertions(+), 23 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index aa23ab3..1553e05 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -106,6 +106,7 @@ var runCmd = &cobra.Command{ SideChainId: uint64(zilConfigMap["side_chain_id"].(int)), CrossChainManagerContract: zilConfigMap["corss_chain_manager_address"].(string), CrossChainManagerProxyContract: zilConfigMap["cross_chain_manager_proxy_address"].(string), + MaxExistTxEpoch: zilConfigMap["max_exist_tx_epoch"].(int), KeyStorePath: zilConfigMap["key_store_path"].(string), KeyStorePwdSet: zilConfigMap["key_store_pwd_set"].(map[string]interface{}), } diff --git a/config.yaml b/config.yaml index a20781f..4d72def 100644 --- a/config.yaml +++ b/config.yaml @@ -9,6 +9,7 @@ zil_config: cross_chain_manager_proxy_address: zil1n7wkwr0xxslwsrhnqtjrwlus80dp5ncnlpaw93 side_chain_id: 85 key_store_path: zilliqa.wallet + max_exist_tx_epoch: 5 key_store_pwd_set: 6c89b62d65dc632e259b96f7ae2f1d68a27e3383: "" poly_config: diff --git a/config/config.go b/config/config.go index 5b3a591..eabcb29 100644 --- a/config/config.go +++ b/config/config.go @@ -21,6 +21,7 @@ type ZILConfig struct { SideChainId uint64 CrossChainManagerContract string CrossChainManagerProxyContract string + MaxExistTxEpoch int KeyStorePath string KeyStorePwdSet map[string]interface{} } diff --git a/service/nonce_manager.go b/service/nonce_manager.go index bba5429..5b84a43 100644 --- a/service/nonce_manager.go +++ b/service/nonce_manager.go @@ -8,6 +8,7 @@ import ( "github.com/Zilliqa/gozilliqa-sdk/util" polytypes "github.com/polynetwork/poly/core/types" common2 "github.com/polynetwork/poly/native/service/cross_chain_manager/common" + "github.com/polynetwork/zilliqa-relayer/config" log "github.com/sirupsen/logrus" "math" "strconv" @@ -15,8 +16,6 @@ import ( "time" ) -const MaxExistTxEpoch = 200 - type NonceAndSender struct { Sender *ZilSender LocalNonce int64 @@ -40,6 +39,7 @@ type NonceManager struct { ZilSenderMap map[string]*NonceAndSender SenderPrivateKeys []string CurrentIndex int + Cfg *config.Config } func (nm *NonceManager) Run() { @@ -218,22 +218,27 @@ func (nm *NonceManager) stat() { // if start block is 0, try to give it a number first if sentTransactionMap[hash].StartTxBlock == 0 { log.Infof("NonceManager - stat try to determine start tx block for hash: %s", hash) - transactionStatus, err := nm.ZilClient.GetTransactionStatus(hash) - if err != nil { - log.Warnf("NonceManager - get transaction status error, hash is %s, err is %s", hash, err.Error()) - } else { - age := 0 - epoch, _ := strconv.ParseUint(transactionStatus.EpochInserted, 10, 64) - if currentTxEpoch > epoch { - age = int(currentTxEpoch - epoch) - } - - sentTransactionMap[hash] = TransactionWithAge{ - Txn: txn.Txn, - StartTxBlock: epoch, - Age: age, - } + sentTransactionMap[hash] = TransactionWithAge{ + Txn: txn.Txn, + StartTxBlock: currentTxEpoch, + Age: 0, } + //transactionStatus, err := nm.ZilClient.GetTransactionStatus(hash) + //if err != nil { + // log.Warnf("NonceManager - get transaction status error, hash is %s, err is %s", hash, err.Error()) + //} else { + // age := 0 + // epoch, _ := strconv.ParseUint(transactionStatus.EpochInserted, 10, 64) + // if currentTxEpoch > epoch { + // age = int(currentTxEpoch - epoch) + // } + // + // sentTransactionMap[hash] = TransactionWithAge{ + // Txn: txn.Txn, + // StartTxBlock: epoch, + // Age: age, + // } + //} } else { log.Warnf("NonceManager - stat already has inserted epoch, update age, hash is %s", hash) age := 0 @@ -264,7 +269,7 @@ func (nm *NonceManager) stat() { log.Infof("NonceManager - stat start to detect dead transactions") currentNonce := uint64(math.MaxUint64) for hash, txn := range nm.SentTransactions[addr] { - if txn.Age > MaxExistTxEpoch { + if txn.Age > nm.Cfg.ZilConfig.MaxExistTxEpoch { log.Warnf("NonceManager - stat found dead transaction, hash: %s, nonce is %s", hash, txn.Txn.Nonce) log.Warnf("NonceManager - stat current nonce is: %d", currentNonce) nonce, _ := strconv.ParseUint(txn.Txn.Nonce, 10, 64) @@ -285,6 +290,11 @@ func (nm *NonceManager) stat() { log.Infof("NonceManager - stat start to resend transaction %s, nonce %d", hash, nonce) // todo handle error nm.ZilClient.CreateTransaction(txn.Txn.ToTransactionPayload()) + nm.SentTransactions[addr][hash] = TransactionWithAge{ + Txn: txn.Txn, + StartTxBlock: currentTxEpoch, + Age: 0, + } } } diff --git a/service/polymanager.go b/service/polymanager.go index aab042a..9f670b3 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -129,6 +129,7 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * SenderPrivateKeys: privateKeys, ZilSenderMap: zilSenderMap, CurrentIndex: 0, + Cfg: cfg, } return &PolySyncManager{ diff --git a/service/zil2poly.go b/service/zil2poly.go index acd7be6..061e7e5 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -54,7 +54,7 @@ func (s *ZilliqaSyncManager) MonitorChain() { if uint32(len(s.header4sync)) > s.cfg.ZilConfig.ZilHeadersPerBatch { log.Infof("ZilliqaSyncManager MonitorChain - commit header") if res := s.commitHeader(); res != 0 { - log.Errorf("ZilliqaSyncManager MonitorChain -- commit header error, result %d",res) + log.Errorf("ZilliqaSyncManager MonitorChain -- commit header error, result %d", res) blockHandleResult = false break } @@ -213,16 +213,19 @@ func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { txIndexDecimal := txIndexBigInt.String() storageKey := core.GenerateStorageKey(ccmc, "zilToPolyTxHashMap", []string{txIndexDecimal}) hashedStorageKey := util.Sha256(storageKey) + log.Infof("ZilliqaSyncManager - handleLockDepositEvents start get proof on address %s, hashed key is: %s, height is %s", ccmc, util.EncodeHex(hashedStorageKey), *heightString) proof, err := s.zilSdk.GetStateProof(ccmc, util.EncodeHex(hashedStorageKey), heightString) if err != nil { return fmt.Errorf("ZilliqaSyncManager - handleLockDepositEvents - get proof from api error: %s", err) } - log.Infof("ZilliqaSyncManager - handleLockDepositEvents get proof from zilliqa api endpoint: %+v, height is: %d\n", proof, height) if proof == nil { + log.Warnf("ZilliqaSyncManager - handleLockDepositEvents - get proof from api error: %s", "proof is nil") return fmt.Errorf("ZilliqaSyncManager - handleLockDepositEvents - get proof from api error: %s", "proof is nil") } + log.Infof("ZilliqaSyncManager - handleLockDepositEvents get proof from zilliqa api endpoint: %+v, height is: %d\n", proof, height) + zilProof := &ZILProof{ AccountProof: proof.AccountProof, } @@ -380,11 +383,11 @@ func (s *ZilliqaSyncManager) commitHeader() int { for range tick.C { h, err = s.polySdk.GetBlockHeightByTxHash(tx.ToHexString()) if err != nil { - log.Warnf("ZilliqaSyncManager commitHeader get block height by hash, hash: %s error: %s",tx.ToHexString(),err.Error()) + log.Warnf("ZilliqaSyncManager commitHeader get block height by hash, hash: %s error: %s", tx.ToHexString(), err.Error()) } curr, err2 := s.polySdk.GetCurrentBlockHeight() if err2 != nil { - log.Warnf("ZilliqaSyncManager commitHeader get current block height error: %s",err2.Error()) + log.Warnf("ZilliqaSyncManager commitHeader get current block height error: %s", err2.Error()) } if h > 0 && curr > h { break @@ -394,7 +397,6 @@ func (s *ZilliqaSyncManager) commitHeader() int { log.Infof("ZilliqaSyncManager commitHeader - send transaction %s to poly chain and confirmed on height %d", tx.ToHexString(), h) s.header4sync = make([][]byte, 0) - // todo s.handleLockDepositEvents(s.currentHeight) return 0 } From 8d72826064def9f1eccc79335c082476dbc5ad70 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Sat, 10 Apr 2021 10:57:47 +0800 Subject: [PATCH 058/107] fix: use R/W lock --- service/nonce_manager.go | 4 +++- service/zil2poly.go | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/service/nonce_manager.go b/service/nonce_manager.go index 5b84a43..cc362ab 100644 --- a/service/nonce_manager.go +++ b/service/nonce_manager.go @@ -32,7 +32,7 @@ type NonceManager struct { ZilClient *provider.Provider // address => hash => transaction SentTransactions map[string]map[string]TransactionWithAge - LockSentTransaction sync.Mutex + LockSentTransaction sync.RWMutex // address => list of transaction hash ConfirmedTransactions map[string][]string // private key => nonce and sender @@ -197,9 +197,11 @@ func (nm *NonceManager) stat() { } // print some stat info about this address + nm.LockSentTransaction.RLock() log.Infof("NonceManager - address %s, local nonce = %d, remote nonce = %d", addr, nm.ZilSenderMap[key].LocalNonce, balAndNonce.Nonce) log.Infof("NonceManager - sent transactions: %+v", nm.SentTransactions[addr]) log.Infof("NonceManager - confimred transactions: %+v", len(nm.ConfirmedTransactions[addr])) + nm.LockSentTransaction.RUnlock() // check sent transactions log.Infof("NonceManager - check sent transactions") diff --git a/service/zil2poly.go b/service/zil2poly.go index 061e7e5..1b6f7c1 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -382,8 +382,13 @@ func (s *ZilliqaSyncManager) commitHeader() int { var h uint32 for range tick.C { h, err = s.polySdk.GetBlockHeightByTxHash(tx.ToHexString()) + if err != nil { - log.Warnf("ZilliqaSyncManager commitHeader get block height by hash, hash: %s error: %s", tx.ToHexString(), err.Error()) + if strings.Contains(err.Error(), "JsonRpcResponse error code:42002 desc:INVALID PARAMS") { + log.Infof("ZilliqaSyncManager commitHeader - wait for confirmation") + } else { + log.Warnf("ZilliqaSyncManager commitHeader get block height by hash, hash: %s error: %s", tx.ToHexString(), err.Error()) + } } curr, err2 := s.polySdk.GetCurrentBlockHeight() if err2 != nil { From 33b103a128a3c52b6bb09a258ef1d0131a54b48a Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Sat, 10 Apr 2021 12:09:18 +0800 Subject: [PATCH 059/107] chore: remove unnecessary code --- service/nonce_manager.go | 61 ++----------------------------- service/nonce_manager_test.go | 67 ----------------------------------- 2 files changed, 2 insertions(+), 126 deletions(-) delete mode 100644 service/nonce_manager_test.go diff --git a/service/nonce_manager.go b/service/nonce_manager.go index cc362ab..12fd8ff 100644 --- a/service/nonce_manager.go +++ b/service/nonce_manager.go @@ -32,7 +32,7 @@ type NonceManager struct { ZilClient *provider.Provider // address => hash => transaction SentTransactions map[string]map[string]TransactionWithAge - LockSentTransaction sync.RWMutex + LockSentTransaction sync.Mutex // address => list of transaction hash ConfirmedTransactions map[string][]string // private key => nonce and sender @@ -50,61 +50,6 @@ func (nm *NonceManager) Run() { } } -// only for test purpose -func (nm *NonceManager) send(txn *transaction.Transaction) bool { - currentSenderPrivateKey := nm.SenderPrivateKeys[nm.CurrentIndex] - nm.CurrentIndex++ - if nm.CurrentIndex > len(nm.SenderPrivateKeys)-1 { - nm.CurrentIndex = 0 - } - - currentSender := nm.ZilSenderMap[currentSenderPrivateKey].Sender - log.Infof("NonceManager - send use sender %s", currentSender.address) - nonce := strconv.FormatUint(uint64(nm.ZilSenderMap[currentSenderPrivateKey].LocalNonce+1), 10) - - txn.Nonce = nonce - txn.SenderPubKey = util.EncodeHex(keytools.GetPublicKeyFromPrivateKey(util.DecodeHex(currentSender.privateKey), true)) - txn.Priority = true - - wallet := account.NewWallet() - wallet.AddByPrivateKey(currentSender.privateKey) - _ = wallet.Sign(txn, *currentSender.zilSdk) - nm.LockSentTransaction.Lock() - resp, err := currentSender.zilSdk.CreateTransaction(txn.ToTransactionPayload()) - - if err != nil || resp.Error != nil { - if err != nil { - log.Warnf("NonceManager - send error %s", err.Error()) - return false - } - log.Warnf("NonceManager - send error %s", resp.Error) - return false - } - - log.Infof("NonceManager - transaction response is: %+v", resp) - - hash, _ := txn.Hash() - - // handle nonce - nm.ZilSenderMap[currentSenderPrivateKey] = &NonceAndSender{ - Sender: nm.ZilSenderMap[currentSenderPrivateKey].Sender, - LocalNonce: nm.ZilSenderMap[currentSenderPrivateKey].LocalNonce + 1, - } - - outerMap := nm.SentTransactions[currentSender.address] - if outerMap == nil { - outerMap = make(map[string]TransactionWithAge) - } - outerMap[util.EncodeHex(hash)] = TransactionWithAge{ - Txn: txn, - Age: 0, - } - nm.SentTransactions[currentSender.address] = outerMap - nm.LockSentTransaction.Unlock() - - return true -} - func (nm *NonceManager) commitHeader(hdr *polytypes.Header) bool { nm.LockSentTransaction.Lock() currentSenderPrivateKey := nm.SenderPrivateKeys[nm.CurrentIndex] @@ -197,15 +142,13 @@ func (nm *NonceManager) stat() { } // print some stat info about this address - nm.LockSentTransaction.RLock() + nm.LockSentTransaction.Lock() log.Infof("NonceManager - address %s, local nonce = %d, remote nonce = %d", addr, nm.ZilSenderMap[key].LocalNonce, balAndNonce.Nonce) log.Infof("NonceManager - sent transactions: %+v", nm.SentTransactions[addr]) log.Infof("NonceManager - confimred transactions: %+v", len(nm.ConfirmedTransactions[addr])) - nm.LockSentTransaction.RUnlock() // check sent transactions log.Infof("NonceManager - check sent transactions") - nm.LockSentTransaction.Lock() var confirmedTxn []string sentTransactionMap := nm.SentTransactions[addr] diff --git a/service/nonce_manager_test.go b/service/nonce_manager_test.go deleted file mode 100644 index 17637d5..0000000 --- a/service/nonce_manager_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package service - -import ( - "github.com/Zilliqa/gozilliqa-sdk/keytools" - "github.com/Zilliqa/gozilliqa-sdk/provider" - "github.com/Zilliqa/gozilliqa-sdk/transaction" - "github.com/Zilliqa/gozilliqa-sdk/util" - "strconv" - "testing" - "time" -) - -func TestNonceManager_Run(t *testing.T) { - zilClient := provider.NewProvider("https://dev-api.zilliqa.com/") - privateKey := "e53d1c3edaffc7a7bab5418eb836cf75819a82872b4a1a0f1c7fcf5c3e020b89" - addr := keytools.GetAddressFromPrivateKey(util.DecodeHex(privateKey)) - zilSender := &ZilSender{ - zilSdk: zilClient, - address: addr, - privateKey: privateKey, - } - balAndNonce, _ := zilClient.GetBalance(zilSender.address) - nonceAndSender := &NonceAndSender{ - Sender: zilSender, - LocalNonce: balAndNonce.Nonce, - } - - zilSenderMap := make(map[string]*NonceAndSender) - zilSenderMap[privateKey] = nonceAndSender - - senderPrivateKeys := []string{privateKey} - - nm := NonceManager{ - UpdateInterval: 30, - ZilClient: zilClient, - SentTransactions: make(map[string]map[string]TransactionWithAge), - ConfirmedTransactions: make(map[string][]string), - ZilSenderMap: zilSenderMap, - SenderPrivateKeys: senderPrivateKeys, - CurrentIndex: 0, - } - - go nm.Run() - - txn := &transaction.Transaction{ - Version: strconv.FormatInt(int64(util.Pack(333, 1)), 10), - ToAddr: "4BAF5faDA8e5Db92C3d3242618c5B47133AE003C", - Amount: "10000000", - GasPrice: "2000000000", - GasLimit: "1", - Code: "", - Data: "", - Priority: false, - } - - for i := 0; i < 10; i++ { - nm.send(txn) - } - - time.Sleep(time.Second * 5) - - for i := 0; i < 20; i++ { - nm.send(txn) - } - - WaitToExit() -} From 63f895c44f9f83defba0467a1992afbf325a26a9 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Sat, 10 Apr 2021 23:33:59 +0800 Subject: [PATCH 060/107] fix: use defer fix deadlock issue --- service/nonce_manager.go | 9 ++++----- service/poly2zil.go | 15 +++++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/service/nonce_manager.go b/service/nonce_manager.go index 12fd8ff..9ecf794 100644 --- a/service/nonce_manager.go +++ b/service/nonce_manager.go @@ -1,7 +1,6 @@ package service import ( - "github.com/Zilliqa/gozilliqa-sdk/account" "github.com/Zilliqa/gozilliqa-sdk/keytools" "github.com/Zilliqa/gozilliqa-sdk/provider" "github.com/Zilliqa/gozilliqa-sdk/transaction" @@ -52,6 +51,7 @@ func (nm *NonceManager) Run() { func (nm *NonceManager) commitHeader(hdr *polytypes.Header) bool { nm.LockSentTransaction.Lock() + defer nm.LockSentTransaction.Unlock() currentSenderPrivateKey := nm.SenderPrivateKeys[nm.CurrentIndex] nm.CurrentIndex++ if nm.CurrentIndex > len(nm.SenderPrivateKeys)-1 { @@ -83,12 +83,12 @@ func (nm *NonceManager) commitHeader(hdr *polytypes.Header) bool { Age: 0, } nm.SentTransactions[currentSender.address] = outerMap - nm.LockSentTransaction.Unlock() return true } func (nm *NonceManager) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { nm.LockSentTransaction.Lock() + defer nm.LockSentTransaction.Unlock() currentSenderPrivateKey := nm.SenderPrivateKeys[nm.CurrentIndex] nm.CurrentIndex++ if nm.CurrentIndex > len(nm.SenderPrivateKeys)-1 { @@ -121,7 +121,6 @@ func (nm *NonceManager) commitDepositEventsWithHeader(header *polytypes.Header, Age: 0, } nm.SentTransactions[currentSender.address] = outerMap - nm.LockSentTransaction.Unlock() return true } @@ -133,6 +132,8 @@ func (nm *NonceManager) stat() { } currentTxEpoch, _ := strconv.ParseUint(txBlock.Header.BlockNum, 10, 64) log.Infof("NonceManager - current tx block number is: %s", txBlock.Header.BlockNum) + nm.LockSentTransaction.Lock() + defer nm.LockSentTransaction.Unlock() for _, key := range nm.SenderPrivateKeys { addr := keytools.GetAddressFromPrivateKey(util.DecodeHex(key)) balAndNonce, err := nm.ZilClient.GetBalance(addr) @@ -142,7 +143,6 @@ func (nm *NonceManager) stat() { } // print some stat info about this address - nm.LockSentTransaction.Lock() log.Infof("NonceManager - address %s, local nonce = %d, remote nonce = %d", addr, nm.ZilSenderMap[key].LocalNonce, balAndNonce.Nonce) log.Infof("NonceManager - sent transactions: %+v", nm.SentTransactions[addr]) log.Infof("NonceManager - confimred transactions: %+v", len(nm.ConfirmedTransactions[addr])) @@ -244,6 +244,5 @@ func (nm *NonceManager) stat() { } } - nm.LockSentTransaction.Unlock() } } diff --git a/service/poly2zil.go b/service/poly2zil.go index e7f2aa1..c7e685b 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -26,6 +26,8 @@ func (p *PolySyncManager) MonitorChain() { monitorTicker := time.NewTicker(time.Duration(p.cfg.PolyConfig.PolyMonitorInterval) * time.Second) var blockHandleResult bool for { + start: + log.Infof("PolySyncManager MonitorChain - current height: %d\n", p.currentHeight) select { case <-monitorTicker.C: latestHeight, err := p.polySdk.GetCurrentBlockHeight() @@ -42,12 +44,13 @@ func (p *PolySyncManager) MonitorChain() { blockHandleResult = true for p.currentHeight <= latestHeight-config.OntUsefulBlockNum { blockHandleResult = p.handleDepositEvents(p.currentHeight, latestHeight) - if blockHandleResult == false { - break - } - p.currentHeight++ - if err = p.db.UpdatePolyHeight(p.currentHeight - 1); err != nil { - log.Errorf("PolySyncManager MonitorChain - failed to save height of poly: %v", err) + if blockHandleResult { + p.currentHeight++ + if err = p.db.UpdatePolyHeight(p.currentHeight - 1); err != nil { + log.Errorf("PolySyncManager MonitorChain - failed to save height of poly: %v", err) + } + } else { + goto start } } From 9bd13f7282610ea9adfb2abcfbb62a0a8fb83ca0 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Fri, 16 Apr 2021 14:28:28 +0800 Subject: [PATCH 061/107] chore: expose somme useful log --- service/zil2poly.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index 1b6f7c1..3167dc2 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -242,7 +242,7 @@ func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { // commit proof proofString, _ := json.Marshal(proof) - log.Debugf("ZilliqaSyncManager - handleLockDepositEvents commit proof, height: %d, proof: %s, value: %s, txhash: %s", height, proofString, util.EncodeHex(crosstx.value), util.EncodeHex(crosstx.txId)) + log.Infof("ZilliqaSyncManager - handleLockDepositEvents commit proof, height: %d, proof: %s, value: %s, txhash: %s\n", height, proofString, util.EncodeHex(crosstx.value), util.EncodeHex(crosstx.txId)) tx, err := s.polySdk.Native.Ccm.ImportOuterTransfer( s.cfg.ZilConfig.SideChainId, crosstx.value, @@ -268,7 +268,7 @@ func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { continue } } else { - log.Infof("ZilliqaSyncManager - handleLockDepositEvents commitProof - send transaction to poly chain: ( poly_txhash: %s, eth_txhash: %s, height: %d )", + log.Infof("ZilliqaSyncManager - handleLockDepositEvents commitProof - send transaction to poly chain: ( poly_txhash: %s, zil_txhash: %s, height: %d )", tx.ToHexString(), util.EncodeHex(crosstx.txId), height) txHash := tx.ToHexString() err = s.db.PutCheck(txHash, v) From a36f6f514094839350bd3130ec5c8ccb7e826381 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 20 Apr 2021 11:05:06 +0800 Subject: [PATCH 062/107] chore: remove some annotation code --- service/poly2zil.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/service/poly2zil.go b/service/poly2zil.go index c7e685b..0c0c724 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -148,24 +148,12 @@ func (p *PolySyncManager) handleDepositEvents(height, latest uint32) bool { } cnt++ p.nonceManager.commitDepositEventsWithHeader(hdr, param, hp, anchor, event.TxHash, auditpath) - //sender := p.selectSender() - //log.Infof("sender %s is handling poly tx ( hash: %s, height: %d )", - // sender.address, event.TxHash, height) - //// temporarily ignore the error for tx - //sender.mu.Lock() - //sender.commitDepositEventsWithHeader(hdr, param, hp, anchor, event.TxHash, auditpath) - //sender.mu.Unlock() } } } if cnt == 0 && isEpoch && isCurr { return p.nonceManager.commitHeader(hdr) - //sender := p.selectSender() - //sender.mu.Lock() - //res := sender.commitHeader(hdr) - //sender.mu.Unlock() - //return res } return true From 83240c918493b858c9f024e4cc4a65ad5731529b Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 20 Apr 2021 11:10:04 +0800 Subject: [PATCH 063/107] chore: update gitignore --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d255c1a..7ad2a82 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,7 @@ cross_chain_manager_admin.json xiaohuo.wallet zilliqa.wallet poly.wallet -relayer.wallet \ No newline at end of file +relayer.wallet +config.devnet.yaml +config.testnet.yaml +target_contracts_devnet.json \ No newline at end of file From ac50ba9e05950900d95f227dad3bebae18b90d08 Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 03:53:49 +0000 Subject: [PATCH 064/107] Added db path for persistence location. --- .gitignore | 3 ++- cmd/run.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d255c1a..f96a49c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ cross_chain_manager_admin.json xiaohuo.wallet zilliqa.wallet poly.wallet -relayer.wallet \ No newline at end of file +relayer.wallet +secrets diff --git a/cmd/run.go b/cmd/run.go index 1553e05..b9fa0ea 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -84,6 +84,7 @@ var runCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { zilConfigMap := viper.GetStringMap("zil_config") targetContractsPath := viper.GetString("target_contracts") + dbPath := viper.GetString("db_path") bytes, e := ioutil.ReadFile(targetContractsPath) if e != nil { log.Errorf("read target contracts error: %s, path: %s\n", e.Error(), targetContractsPath) @@ -126,6 +127,7 @@ var runCmd = &cobra.Command{ ZilConfig: zilConfig, PolyConfig: polyConfig, TargetContracts: targetContract, + Path: db_path, } cfgStr, _ := json.Marshal(cfg) From daa2eda6c6ac17c39b23d5a9c860726e2a915724 Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 03:58:17 +0000 Subject: [PATCH 065/107] Fixed variable typo. --- cmd/run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/run.go b/cmd/run.go index b9fa0ea..a412312 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -127,7 +127,7 @@ var runCmd = &cobra.Command{ ZilConfig: zilConfig, PolyConfig: polyConfig, TargetContracts: targetContract, - Path: db_path, + Path: dbPath, } cfgStr, _ := json.Marshal(cfg) From 8220c037210d863c809ba2f954ae662fec873d1b Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 04:02:02 +0000 Subject: [PATCH 066/107] Added docker-compose. --- docker-compose.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8d1aaa5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: "3.9" +services: + zilliqa-relayer: + build: . + volumes: + - ./persistence:/app/persistence + - ./secrets/config.yaml:/app/config.yaml + - ./secrets/target_contracts.json:/app/target_contracts.json From 8fe2da6ff759defa376849273cbc75a5edb60d71 Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 04:10:15 +0000 Subject: [PATCH 067/107] Updated Dockerfile run command. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index da63824..4070d12 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ COPY config.yaml config.yaml COPY poly.wallet wallet.dat COPY run.sh run.sh COPY --from=build /app/zilliqa-relayer/zilliqa-relayer zilliqa-relayer -CMD ["/bin/bash"] \ No newline at end of file +ENTRYPOINT ["/bin/bash", "run.sh"] From 64d4693f4f4c18a914b3350ba018ee353b2ed6e4 Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 04:57:56 +0000 Subject: [PATCH 068/107] Updated dockerfile and added all configs to docker compose. --- Dockerfile | 13 +++++++------ docker-compose.yml | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4070d12..038b8bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,14 @@ FROM golang:1.15 AS build -WORKDIR /app -RUN git clone https://github.com/Zilliqa/zilliqa-relayer.git && \ - cd zilliqa-relayer && \ - go build +WORKDIR /app/zilliqa-relayer +COPY . ./ +RUN go build +#RUN git clone https://github.com/Zilliqa/zilliqa-relayer.git && \ +# cd zilliqa-relayer && \ +# go build FROM ubuntu:18.04 +RUN apt-get update && apt-get install -y ca-certificates WORKDIR /app -COPY config.yaml config.yaml -COPY poly.wallet wallet.dat COPY run.sh run.sh COPY --from=build /app/zilliqa-relayer/zilliqa-relayer zilliqa-relayer ENTRYPOINT ["/bin/bash", "run.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 8d1aaa5..6ecd655 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,5 +4,7 @@ services: build: . volumes: - ./persistence:/app/persistence - - ./secrets/config.yaml:/app/config.yaml + - ./secrets/config.local.yaml:/app/config.local.yaml - ./secrets/target_contracts.json:/app/target_contracts.json + - ./secrets/poly.wallet:/app/poly.wallet + - ./secrets/zilliqa.wallet:/app/zilliqa.wallet From a3e2a033fac042ff93cc506262ec6efdcb694c5c Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 05:11:56 +0000 Subject: [PATCH 069/107] Updated run-docker.sh --- run-docker.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/run-docker.sh b/run-docker.sh index cd05573..c24168e 100755 --- a/run-docker.sh +++ b/run-docker.sh @@ -1,2 +1,8 @@ #!/bin/sh -docker run polynetwork/zilliqa-relayer /app/run.sh \ No newline at end of file +docker run -d \ +-v $(pwd)/persistence:/app/persistence \ +-v $(pwd)/secrets/config.local.yaml:/app/config.local.yaml \ +-v $(pwd)/secrets/target_contracts.json:/app/target_contracts.json \ +-v $(pwd)/secrets/poly.wallet:/app/poly.wallet \ +-v $(pwd)/secrets/zilliqa.wallet:/app/zilliqa.wallet \ +polynetwork/zilliqa-relayer From f06a01738e8c828e3fce75ac0a731d9f8aaa93a1 Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 05:13:12 +0000 Subject: [PATCH 070/107] Updated build-docker.sh --- build-docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-docker.sh b/build-docker.sh index da9dae9..deab546 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -1,2 +1,2 @@ #!/bin/sh -docker build -t polynetwork/zilliqa-relayer -f Dockerfile ./ \ No newline at end of file +docker build -t polynetwork/zilliqa-relayer . From 02d09cfeb111b4397adf3dfbe8fbabe97ac11c3e Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 05:18:04 +0000 Subject: [PATCH 071/107] Added container name to docker run. --- run-docker.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/run-docker.sh b/run-docker.sh index c24168e..9a53340 100755 --- a/run-docker.sh +++ b/run-docker.sh @@ -1,8 +1,11 @@ #!/bin/sh +docker stop zilliqa-relayer +docker rm zilliqa-relayer + docker run -d \ -v $(pwd)/persistence:/app/persistence \ -v $(pwd)/secrets/config.local.yaml:/app/config.local.yaml \ -v $(pwd)/secrets/target_contracts.json:/app/target_contracts.json \ -v $(pwd)/secrets/poly.wallet:/app/poly.wallet \ -v $(pwd)/secrets/zilliqa.wallet:/app/zilliqa.wallet \ -polynetwork/zilliqa-relayer +--name zilliqa-relayer polynetwork/zilliqa-relayer From 11be2f606a855d265347adb30219a404abeff5b8 Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 05:31:24 +0000 Subject: [PATCH 072/107] Set docker-compose container name. --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index 6ecd655..157d6e4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,7 @@ version: "3.9" services: zilliqa-relayer: + container_name: zilliqa-relayer build: . volumes: - ./persistence:/app/persistence From 10395dc57b4e347e7815d3ed1f8d1a058340ca05 Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 05:34:42 +0000 Subject: [PATCH 073/107] Updated Readme. --- README.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cd7cb61..bbf457d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ After building the source code successfully, you should see the executable prog ### Build Docker Image ``` -docker build -t polynetwork/zilliqa-relayer -f Dockerfile ./ +docker build -t polynetwork/zilliqa-relayer . ``` This command will copy config.yaml to /app/config.yaml in the image. So you need to prepare config.yaml before running this command and you should start the zilliqa-relayer in container basing on the configuration in /app/config.yaml. @@ -62,6 +62,7 @@ poly_config: entrance_contract_address: "0300000000000000000000000000000000000000" rest_url: http://poly.com target_contracts: target_contracts.json +db_path: persistence ``` A sample keystore file could be: @@ -69,6 +70,53 @@ A sample keystore file could be: ```text {"address":"7d48043742a1103042d327111746531ca26be9be","id":"6cd445ed-8f5f-4565-af2a-cc2306a82b73","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"d136660a4e5664709031ebc162616556e8c812ab37d0157ea3276aa08d0a6c2d","kdf":"pbkdf2","mac":"b30dd459f1fd9d99c0b2f3452ccd2bf11414ad92d32ac70d1d7b52f17281b4e5","cipherparams":{"iv":"6a14f95c8cbafe7d1f317bec88e9d1b8"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"c4939e7cead32935d1972a2cd06d249dd501181e6ad2d1872fa0eb397d7fea20"}}} ``` +# Relayer Container Administration +## Running the Relayer Container +### Prerequisites: +If you are running via docker-compose, you'll need to install docker-compose first via the following guide: +``` +https://docs.docker.com/compose/install/ +``` + +You need the following files and folders created: +If persistence is already created: +``` +./persistence/bolt.bin +``` +If persistence folder is not created: +``` +create a folder named 'persistence'. +``` +Configuration Files: +``` +secrets/config.local.yaml +secrets/target_contracts.json +secrets/poly.wallet +secrets/zilliqa.wallet +``` +### Running Relayer via Docker Container +``` +./docker-run +``` + +### Running Relayer via Docker Compose +``` +docker-compose up -d +``` +## Stopping the Relayer +### Stopping Relayer via Docker Container +``` +docker stop zilliqa-relayer && docker rm zilliqa-relayer +``` +### Stopping Relayer via Docker Compose +``` +docker-compose down +``` +## Getting logs +``` +docker logs -f zilliqa-relayer +``` + ## Other Resources @@ -79,3 +127,4 @@ A sample keystore file could be: + From 34713a38ac8cf5ba9dbe4b6adc8b79185b1c636a Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 05:43:35 +0000 Subject: [PATCH 074/107] Fixed readme typo. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bbf457d..b7b989d 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ If you are running via docker-compose, you'll need to install docker-compose fir https://docs.docker.com/compose/install/ ``` -You need the following files and folders created: +You need the following files and folders created:
If persistence is already created: ``` ./persistence/bolt.bin From 5747433f57b3e9eea25ce0734504df2d0aa844a3 Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 09:00:48 +0000 Subject: [PATCH 075/107] Added dockerhub post push hook to tag with commit. --- hooks/post_push | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 hooks/post_push diff --git a/hooks/post_push b/hooks/post_push new file mode 100644 index 0000000..0fd07be --- /dev/null +++ b/hooks/post_push @@ -0,0 +1,4 @@ +#!/bin/bash + +docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_COMMIT +docker push $DOCKER_REPO:$SOURCE_COMMIT From e591df7cab07f0daeba8e243ec233ababde30462 Mon Sep 17 00:00:00 2001 From: joel-zilliqa Date: Tue, 20 Apr 2021 09:03:17 +0000 Subject: [PATCH 076/107] Added branch detection to post_push hook. --- hooks/post_push | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hooks/post_push b/hooks/post_push index 0fd07be..0574423 100644 --- a/hooks/post_push +++ b/hooks/post_push @@ -1,4 +1,6 @@ #!/bin/bash -docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_COMMIT -docker push $DOCKER_REPO:$SOURCE_COMMIT +if [ $SOURCE_BRANCH == "main" ]; then + docker tag $IMAGE_NAME $DOCKER_REPO:experimental-$SOURCE_COMMIT + docker push $DOCKER_REPO:experimental-$SOURCE_COMMIT +fi From 884f277e181065856bc720981160cc761df501d3 Mon Sep 17 00:00:00 2001 From: Joel Lim <56012934+joel-zilliqa@users.noreply.github.com> Date: Thu, 22 Apr 2021 14:36:59 +0800 Subject: [PATCH 077/107] Updated tag to use first 7 char of commit hash --- hooks/post_push | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/post_push b/hooks/post_push index 0574423..4575c25 100644 --- a/hooks/post_push +++ b/hooks/post_push @@ -1,6 +1,6 @@ #!/bin/bash if [ $SOURCE_BRANCH == "main" ]; then - docker tag $IMAGE_NAME $DOCKER_REPO:experimental-$SOURCE_COMMIT - docker push $DOCKER_REPO:experimental-$SOURCE_COMMIT + docker tag $IMAGE_NAME $DOCKER_REPO:experimental-${SOURCE_COMMIT:0:7} + docker push $DOCKER_REPO:experimental-${SOURCE_COMMIT:0:7} fi From 9e7257213869f482a72052a3da6e2d63a24a7ca2 Mon Sep 17 00:00:00 2001 From: Joel Lim <56012934+joel-zilliqa@users.noreply.github.com> Date: Fri, 23 Apr 2021 15:36:58 +0800 Subject: [PATCH 078/107] updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b7b989d..e42fc6c 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ If persistence is already created: ``` If persistence folder is not created: ``` -create a folder named 'persistence'. +create a folder named 'persistence'. The container will use that folder to store the bolt.bin file. ``` Configuration Files: ``` From 6577db8e95fe1e0c126541c5d6372c7d0b36bbbc Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 27 Apr 2021 15:03:43 +0800 Subject: [PATCH 079/107] feat: add removedb option --- cmd/run.go | 9 ++++++++- config.yaml | 1 + config/config.go | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/run.go b/cmd/run.go index a412312..e40b061 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -12,6 +12,7 @@ import ( "github.com/spf13/viper" "io/ioutil" "os" + "path" ) var cfgFile string @@ -85,6 +86,7 @@ var runCmd = &cobra.Command{ zilConfigMap := viper.GetStringMap("zil_config") targetContractsPath := viper.GetString("target_contracts") dbPath := viper.GetString("db_path") + removeDb := viper.GetBool("remove_db") bytes, e := ioutil.ReadFile(targetContractsPath) if e != nil { log.Errorf("read target contracts error: %s, path: %s\n", e.Error(), targetContractsPath) @@ -127,7 +129,8 @@ var runCmd = &cobra.Command{ ZilConfig: zilConfig, PolyConfig: polyConfig, TargetContracts: targetContract, - Path: dbPath, + Path: dbPath, + RemoveDB: removeDb, } cfgStr, _ := json.Marshal(cfg) @@ -141,6 +144,10 @@ var runCmd = &cobra.Command{ return } + if cfg.RemoveDB { + os.Remove(path.Join(cfg.Path, "bolt.bin")) + } + if !checkIfExist(cfg.Path) { os.Mkdir(cfg.Path, os.ModePerm) } diff --git a/config.yaml b/config.yaml index 4d72def..b4660a1 100644 --- a/config.yaml +++ b/config.yaml @@ -20,3 +20,4 @@ poly_config: entrance_contract_address: "0300000000000000000000000000000000000000" rest_url: http://poly.com target_contracts: target_contracts.json +remove_db: false \ No newline at end of file diff --git a/config/config.go b/config/config.go index eabcb29..82c9276 100644 --- a/config/config.go +++ b/config/config.go @@ -8,6 +8,7 @@ type Config struct { ZilConfig *ZILConfig PolyConfig *POLYConfig Path string + RemoveDB bool TargetContracts []map[string]map[string][]uint64 } From 447ea9e0aca42dd184f455837c97ebd028072ba1 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Mon, 28 Jun 2021 14:47:27 +0800 Subject: [PATCH 080/107] doc: add license header --- cmd/root.go | 17 +++++++++++++++++ cmd/run.go | 31 +++++++++++++++++-------------- config/config.go | 17 +++++++++++++++++ db/db.go | 17 +++++++++++++++++ main.go | 17 +++++++++++++++++ service/common.go | 17 +++++++++++++++++ service/nonce_manager.go | 33 +++++++++++++++++---------------- service/poly2zil.go | 17 +++++++++++++++++ service/poly2zil_test.go | 17 +++++++++++++++++ service/polymanager.go | 17 +++++++++++++++++ service/zil2poly.go | 17 +++++++++++++++++ service/zil_sender.go | 17 +++++++++++++++++ service/zilliqamanager.go | 17 +++++++++++++++++ tools/utils.go | 17 +++++++++++++++++ 14 files changed, 238 insertions(+), 30 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index e095e1b..506ea8f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package cmd import ( diff --git a/cmd/run.go b/cmd/run.go index e40b061..4935a6a 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package cmd import ( @@ -21,20 +38,6 @@ func init() { cobra.OnInitialize(initConfig) RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)") - //runCmd.Flags().String("api", "https://api.zilliqa.com", "zilliqa api endpoint") - //if err := viper.BindPFlag("api", runCmd.Flags().Lookup("api")); err != nil { - // log.Fatal("Unable to bind flag:", err) - //} - //runCmd.Flags().String("zil_start_height", "1", "the from block number will be syncing to poly network") - //if err := viper.BindPFlag("api", runCmd.Flags().Lookup("zil_start_height")); err != nil { - // log.Fatal("Unable to bind flag:", err) - //} - // - //runCmd.Flags().String("zil_scan_interval", "2", "the interval scanning zilliqa block") - //if err := viper.BindPFlag("zil_scan_interval", runCmd.Flags().Lookup("zil_scan_interval")); err != nil { - // log.Fatal("Unable to bind flag:", err) - //} - RootCmd.AddCommand(runCmd) log.SetFormatter(&log.TextFormatter{ FullTimestamp: true, diff --git a/config/config.go b/config/config.go index 82c9276..511c930 100644 --- a/config/config.go +++ b/config/config.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package config const ( diff --git a/db/db.go b/db/db.go index 7bbb223..e21d1cf 100644 --- a/db/db.go +++ b/db/db.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package db import ( diff --git a/main.go b/main.go index 04dd152..56deda4 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package main import "github.com/polynetwork/zilliqa-relayer/cmd" diff --git a/service/common.go b/service/common.go index a103d97..47be13e 100644 --- a/service/common.go +++ b/service/common.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package service import ( diff --git a/service/nonce_manager.go b/service/nonce_manager.go index 9ecf794..e966725 100644 --- a/service/nonce_manager.go +++ b/service/nonce_manager.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package service import ( @@ -168,22 +185,6 @@ func (nm *NonceManager) stat() { StartTxBlock: currentTxEpoch, Age: 0, } - //transactionStatus, err := nm.ZilClient.GetTransactionStatus(hash) - //if err != nil { - // log.Warnf("NonceManager - get transaction status error, hash is %s, err is %s", hash, err.Error()) - //} else { - // age := 0 - // epoch, _ := strconv.ParseUint(transactionStatus.EpochInserted, 10, 64) - // if currentTxEpoch > epoch { - // age = int(currentTxEpoch - epoch) - // } - // - // sentTransactionMap[hash] = TransactionWithAge{ - // Txn: txn.Txn, - // StartTxBlock: epoch, - // Age: age, - // } - //} } else { log.Warnf("NonceManager - stat already has inserted epoch, update age, hash is %s", hash) age := 0 diff --git a/service/poly2zil.go b/service/poly2zil.go index 0c0c724..35d050c 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package service import ( diff --git a/service/poly2zil_test.go b/service/poly2zil_test.go index 5f6aaa1..25f8ff0 100644 --- a/service/poly2zil_test.go +++ b/service/poly2zil_test.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package service import ( diff --git a/service/polymanager.go b/service/polymanager.go index 9f670b3..d053763 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package service import ( diff --git a/service/zil2poly.go b/service/zil2poly.go index 3167dc2..2912fda 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package service import ( diff --git a/service/zil_sender.go b/service/zil_sender.go index b0d3abb..8caa5c6 100644 --- a/service/zil_sender.go +++ b/service/zil_sender.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package service import ( diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 96f765e..d7b6999 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package service import ( diff --git a/tools/utils.go b/tools/utils.go index 704078a..18e0012 100644 --- a/tools/utils.go +++ b/tools/utils.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 Zilliqa + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package tools import ( From fc38bbbde913453bb7e77cea356fd647cfb4101f Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Mon, 28 Jun 2021 14:49:40 +0800 Subject: [PATCH 081/107] chore: add license file --- LICENSE | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4e61c8d --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. From b60f29239bce8171eb78af61512468f19edd7b20 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 6 Jul 2021 10:35:39 +0800 Subject: [PATCH 082/107] chore: add log for querying new ds block --- service/zil2poly.go | 1 + 1 file changed, 1 insertion(+) diff --git a/service/zil2poly.go b/service/zil2poly.go index 2912fda..3da89ea 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -112,6 +112,7 @@ func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { txBlock := core.NewTxBlockFromTxBlockT(txBlockT) if txBlock.BlockHeader.DSBlockNum > s.currentDsBlockNum { + log.Infof("ZilliqaSyncManager - handleBlockHeader query ds block: %d\n", txBlock.BlockHeader.DSBlockNum) dsBlock, err := s.zilSdk.GetDsBlockVerbose(strconv.FormatUint(txBlock.BlockHeader.DSBlockNum, 10)) if err != nil { log.Errorf("ZilliqaSyncManager - handleBlockHeader get ds block error: %s", err) From a977fe2aa7a871f1136d39a5eabcd6a74be68107 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 13 Jul 2021 10:35:36 +0800 Subject: [PATCH 083/107] feat: handle empty ds block --- service/zil2poly.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index 3da89ea..42bf391 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -113,18 +113,24 @@ func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { if txBlock.BlockHeader.DSBlockNum > s.currentDsBlockNum { log.Infof("ZilliqaSyncManager - handleBlockHeader query ds block: %d\n", txBlock.BlockHeader.DSBlockNum) + T: dsBlock, err := s.zilSdk.GetDsBlockVerbose(strconv.FormatUint(txBlock.BlockHeader.DSBlockNum, 10)) if err != nil { log.Errorf("ZilliqaSyncManager - handleBlockHeader get ds block error: %s", err) return false } - txBlockOrDsBlock := core.TxBlockOrDsBlock{ - DsBlock: core.NewDsBlockFromDsBlockT(dsBlock), + if dsBlock.Header.LeaderPubKey == "0x000000000000000000000000000000000000000000000000000000000000000000" { + time.Sleep(time.Second * 2) + goto T + } else { + txBlockOrDsBlock := core.TxBlockOrDsBlock{ + DsBlock: core.NewDsBlockFromDsBlockT(dsBlock), + } + rawBlock, _ := json.Marshal(txBlockOrDsBlock) + log.Infof("ZilliqaSyncManager handle new block header: %s\n", rawBlock) + s.header4sync = append(s.header4sync, rawBlock) + s.currentDsBlockNum++ } - rawBlock, _ := json.Marshal(txBlockOrDsBlock) - log.Infof("ZilliqaSyncManager handle new block header: %s\n", rawBlock) - s.header4sync = append(s.header4sync, rawBlock) - s.currentDsBlockNum++ } txBlockOrDsBlock := core.TxBlockOrDsBlock{ From 0f7f18d8bd0e9c3e02a6d5fdfb9392e4dc32eb9f Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Wed, 14 Jul 2021 14:25:23 +0800 Subject: [PATCH 084/107] fix: remove goto to avoid loop --- service/zil2poly.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index 42bf391..3984630 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -113,24 +113,19 @@ func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { if txBlock.BlockHeader.DSBlockNum > s.currentDsBlockNum { log.Infof("ZilliqaSyncManager - handleBlockHeader query ds block: %d\n", txBlock.BlockHeader.DSBlockNum) - T: + time.Sleep(time.Second * 2) dsBlock, err := s.zilSdk.GetDsBlockVerbose(strconv.FormatUint(txBlock.BlockHeader.DSBlockNum, 10)) if err != nil { log.Errorf("ZilliqaSyncManager - handleBlockHeader get ds block error: %s", err) return false } - if dsBlock.Header.LeaderPubKey == "0x000000000000000000000000000000000000000000000000000000000000000000" { - time.Sleep(time.Second * 2) - goto T - } else { - txBlockOrDsBlock := core.TxBlockOrDsBlock{ - DsBlock: core.NewDsBlockFromDsBlockT(dsBlock), - } - rawBlock, _ := json.Marshal(txBlockOrDsBlock) - log.Infof("ZilliqaSyncManager handle new block header: %s\n", rawBlock) - s.header4sync = append(s.header4sync, rawBlock) - s.currentDsBlockNum++ + txBlockOrDsBlock := core.TxBlockOrDsBlock{ + DsBlock: core.NewDsBlockFromDsBlockT(dsBlock), } + rawBlock, _ := json.Marshal(txBlockOrDsBlock) + log.Infof("ZilliqaSyncManager handle new block header: %s\n", rawBlock) + s.header4sync = append(s.header4sync, rawBlock) + s.currentDsBlockNum++ } txBlockOrDsBlock := core.TxBlockOrDsBlock{ From 0ce01c909382d5088e149365c38e709a1e196256 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 15 Jul 2021 11:38:42 +0800 Subject: [PATCH 085/107] fix: handle dummy ds block --- service/zil2poly.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index 3984630..24c8c05 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -104,16 +104,20 @@ func (s *ZilliqaSyncManager) handleNewBlock(height uint64) bool { func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { log.Infof("ZilliqaSyncManager handle new block header height is: %d\n", height) + T: txBlockT, err := s.zilSdk.GetTxBlockVerbose(strconv.FormatUint(height, 10)) if err != nil { log.Errorf("ZilliqaSyncManager - handleBlockHeader error: %s", err) return false } txBlock := core.NewTxBlockFromTxBlockT(txBlockT) - + if txBlock.BlockHeader.DSBlockNum == 18446744073709551615 { + log.Infof("ZilliqaSyncManager - handleBlockHeader query ds block: ds block not ready") + time.Sleep(time.Second * 2) + goto T + } if txBlock.BlockHeader.DSBlockNum > s.currentDsBlockNum { log.Infof("ZilliqaSyncManager - handleBlockHeader query ds block: %d\n", txBlock.BlockHeader.DSBlockNum) - time.Sleep(time.Second * 2) dsBlock, err := s.zilSdk.GetDsBlockVerbose(strconv.FormatUint(txBlock.BlockHeader.DSBlockNum, 10)) if err != nil { log.Errorf("ZilliqaSyncManager - handleBlockHeader get ds block error: %s", err) From 4356c6e8dfa6ebc9dea689c069423af551009874 Mon Sep 17 00:00:00 2001 From: renlulu Date: Thu, 29 Jul 2021 19:32:01 +0800 Subject: [PATCH 086/107] fix: retry if encounter tx block not exist --- service/zil2poly.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index 2912fda..3c18fec 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -65,7 +65,9 @@ func (s *ZilliqaSyncManager) MonitorChain() { blockHandleResult = true for s.currentHeight < blockNumber { - s.handleNewBlock(s.currentHeight + 1) + if !s.handleNewBlock(s.currentHeight + 1) { + break + } s.currentHeight++ if uint32(len(s.header4sync)) > s.cfg.ZilConfig.ZilHeadersPerBatch { @@ -98,6 +100,7 @@ func (s *ZilliqaSyncManager) handleNewBlock(height uint64) bool { ret = s.fetchLockDepositEvents(height) if !ret { log.Infof("ZilliqaSyncManager handleNewBlock - fetchLockDepositEvents on height :%d failed\n", height) + return false } return true } From db02563c470a165f1568439ee4aa8629cfbcd76c Mon Sep 17 00:00:00 2001 From: renlulu Date: Fri, 17 Sep 2021 17:27:27 +0800 Subject: [PATCH 087/107] enhance: retry 100 times committing blocks --- service/zil2poly.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/service/zil2poly.go b/service/zil2poly.go index 2bb6904..b86c239 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -405,8 +405,14 @@ func (s *ZilliqaSyncManager) commitHeader() int { } tick := time.NewTicker(100 * time.Millisecond) + retries := 0 var h uint32 for range tick.C { + if retries > 100 { + return 1 + } else { + retries++ + } h, err = s.polySdk.GetBlockHeightByTxHash(tx.ToHexString()) if err != nil { From 8f4c3bfbd80658b0d36162ef1929508f3d079230 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Tue, 21 Sep 2021 14:12:40 +0800 Subject: [PATCH 088/107] enhance: audit log --- service/nonce_manager.go | 21 ++++++++++++++++++++- service/zil2poly.go | 3 ++- tools/utils.go | 13 +++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/service/nonce_manager.go b/service/nonce_manager.go index e966725..9a4dc97 100644 --- a/service/nonce_manager.go +++ b/service/nonce_manager.go @@ -18,6 +18,7 @@ package service import ( + "encoding/json" "github.com/Zilliqa/gozilliqa-sdk/keytools" "github.com/Zilliqa/gozilliqa-sdk/provider" "github.com/Zilliqa/gozilliqa-sdk/transaction" @@ -25,6 +26,7 @@ import ( polytypes "github.com/polynetwork/poly/core/types" common2 "github.com/polynetwork/poly/native/service/cross_chain_manager/common" "github.com/polynetwork/zilliqa-relayer/config" + "github.com/polynetwork/zilliqa-relayer/tools" log "github.com/sirupsen/logrus" "math" "strconv" @@ -32,6 +34,8 @@ import ( "time" ) +const AuditLogFile = "audit.log" + type NonceAndSender struct { Sender *ZilSender LocalNonce int64 @@ -103,6 +107,12 @@ func (nm *NonceManager) commitHeader(hdr *polytypes.Header) bool { return true } +type TransactionAuditLog struct { + Time time.Time + PayLoad string + Error string +} + func (nm *NonceManager) commitDepositEventsWithHeader(header *polytypes.Header, param *common2.ToMerkleValue, headerProof string, anchorHeader *polytypes.Header, polyTxHash string, rawAuditPath []byte) bool { nm.LockSentTransaction.Lock() defer nm.LockSentTransaction.Unlock() @@ -116,8 +126,17 @@ func (nm *NonceManager) commitDepositEventsWithHeader(header *polytypes.Header, log.Infof("NonceManager - commitDepositEventsWithHeader use sender %s", currentSender.address) nonce := strconv.FormatUint(uint64(nm.ZilSenderMap[currentSenderPrivateKey].LocalNonce+1), 10) txn, err := currentSender.commitDepositEventsWithHeaderWithNonce(header, param, headerProof, anchorHeader, polyTxHash, rawAuditPath, nonce) + transactionRaw, _ := json.Marshal(txn) + auditLog := TransactionAuditLog{ + Time: time.Now(), + PayLoad: string(transactionRaw), + Error: err.Error(), + } + auditLogRaw, _ := json.Marshal(auditLog) + tools.AppendToFile(AuditLogFile, string(auditLogRaw)) + if err != nil { - log.Warnf("NonceManager - commitDepositEventsWithHeaderWithNonce error %s", err.Error()) + log.Warnf("NonceManager - commitDepositEventsWithHeaderWithNonc e error %s", err.Error()) return false } diff --git a/service/zil2poly.go b/service/zil2poly.go index b86c239..691639e 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -41,6 +41,7 @@ import ( * 2. filter deposit event, put into local database * 3. from database, handle deposit event, get proof and commit to poly */ + func (s *ZilliqaSyncManager) MonitorChain() { log.Infof("ZilliqaSyncManager MonitorChain - start scan block at height: %d\n", s.currentHeight) fetchBlockTicker := time.NewTicker(time.Duration(s.cfg.ZilConfig.ZilMonitorInterval) * time.Second) @@ -107,7 +108,7 @@ func (s *ZilliqaSyncManager) handleNewBlock(height uint64) bool { func (s *ZilliqaSyncManager) handleBlockHeader(height uint64) bool { log.Infof("ZilliqaSyncManager handle new block header height is: %d\n", height) - T: +T: txBlockT, err := s.zilSdk.GetTxBlockVerbose(strconv.FormatUint(height, 10)) if err != nil { log.Errorf("ZilliqaSyncManager - handleBlockHeader error: %s", err) diff --git a/tools/utils.go b/tools/utils.go index 18e0012..5313566 100644 --- a/tools/utils.go +++ b/tools/utils.go @@ -140,3 +140,16 @@ func GetNoCompresskey(key keypair.PublicKey) []byte { } return buf.Bytes() } + +func AppendToFile(fileName string, context string) { + f, err := os.OpenFile(fileName, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + if err != nil { + panic(err) + } + + defer f.Close() + + if _, err = f.WriteString(context); err != nil { + panic(err) + } +} From 8432bf549d4d02cb1aa7f90c86e0993130c9b925 Mon Sep 17 00:00:00 2001 From: renlulu Date: Wed, 22 Sep 2021 15:23:30 +0800 Subject: [PATCH 089/107] fix: nil error for audit log --- service/nonce_manager.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/service/nonce_manager.go b/service/nonce_manager.go index 9a4dc97..d714ac6 100644 --- a/service/nonce_manager.go +++ b/service/nonce_manager.go @@ -126,12 +126,20 @@ func (nm *NonceManager) commitDepositEventsWithHeader(header *polytypes.Header, log.Infof("NonceManager - commitDepositEventsWithHeader use sender %s", currentSender.address) nonce := strconv.FormatUint(uint64(nm.ZilSenderMap[currentSenderPrivateKey].LocalNonce+1), 10) txn, err := currentSender.commitDepositEventsWithHeaderWithNonce(header, param, headerProof, anchorHeader, polyTxHash, rawAuditPath, nonce) - transactionRaw, _ := json.Marshal(txn) - auditLog := TransactionAuditLog{ - Time: time.Now(), - PayLoad: string(transactionRaw), - Error: err.Error(), + var auditLog TransactionAuditLog + if err != nil { + auditLog = TransactionAuditLog{ + Time: time.Now(), + Error: err.Error(), + } + } else { + transactionRaw, _ := json.Marshal(txn) + auditLog = TransactionAuditLog{ + Time: time.Now(), + PayLoad: string(transactionRaw), + } } + auditLogRaw, _ := json.Marshal(auditLog) tools.AppendToFile(AuditLogFile, string(auditLogRaw)) From d30ded0143ad21ac928cc9e1fc4394d89472907e Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Mon, 27 Sep 2021 14:59:20 +0800 Subject: [PATCH 090/107] dep: update golang sdk --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 39d576a..fbb0f01 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/polynetwork/zilliqa-relayer go 1.15 require ( - github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210329093354-1b8e0a7a2e25 + github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210927032600-4c733f2cb879 github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta github.com/ethereum/go-ethereum v1.9.24 // indirect diff --git a/go.sum b/go.sum index c1ce33a..a8bff17 100644 --- a/go.sum +++ b/go.sum @@ -82,6 +82,8 @@ github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210329090957-47fa84b98939 h1:AvHW2ba github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210329090957-47fa84b98939/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/Zilliqa/gozilliqa-sdk v1.2.1-0.20210927032600-4c733f2cb879 h1:/OXqInjRm8CEd81EEFCGJ5Q24TTlY1/qu6DQ0D91WPA= +github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210927032600-4c733f2cb879/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= From ac5dec1735c25bd89588694e9e78caaba96aeb6d Mon Sep 17 00:00:00 2001 From: renlulu Date: Mon, 27 Sep 2021 22:13:55 +0800 Subject: [PATCH 091/107] enhance: adjust wait time --- service/zil2poly.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index 691639e..2d92cac 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -409,7 +409,7 @@ func (s *ZilliqaSyncManager) commitHeader() int { retries := 0 var h uint32 for range tick.C { - if retries > 100 { + if retries > 5000 { return 1 } else { retries++ @@ -428,6 +428,7 @@ func (s *ZilliqaSyncManager) commitHeader() int { log.Warnf("ZilliqaSyncManager commitHeader get current block height error: %s", err2.Error()) } if h > 0 && curr > h { + log.Infof("ZilliqaSyncManager commitHeader h > 0 or curr > h") break } } From de2d5b0647a64bd3d25917293bca32eafadc460b Mon Sep 17 00:00:00 2001 From: Henry Chua Date: Fri, 2 Sep 2022 13:02:44 +0800 Subject: [PATCH 092/107] Fix some relayer bugs --- .gitignore | 6 +++ cmd/run.go | 2 + go.mod | 2 + go.sum | 84 ++++++++++++++++++------------------------ service/poly2zil.go | 8 +++- service/polymanager.go | 11 +++--- 6 files changed, 59 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index 6854ca6..cddf0c9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,10 @@ relayer.wallet secrets config.devnet.yaml config.testnet.yaml +config.production.yaml +target_contracts_local.json target_contracts_devnet.json +target_contracts_production.json +audit.log +zil_relayer +wallet.dat \ No newline at end of file diff --git a/cmd/run.go b/cmd/run.go index 4935a6a..ad08d1e 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -160,11 +160,13 @@ var runCmd = &cobra.Command{ return } + // zil to poly zilliqaManager, err := service.NewZilliqaSyncManager(cfg, zilSdk, polySdk, boltDB) if err != nil { log.Errorf("init zilliqamanger error: %s\n", err.Error()) return } + // poly to zil polyManager, err1 := service.NewPolySyncManager(cfg, zilSdk, polySdk, boltDB, cfg.ZilConfig.CrossChainManagerContract, cfg.ZilConfig.CrossChainManagerProxyContract) if err1 != nil { log.Errorf("init polymanager error: %s\n", err1.Error()) diff --git a/go.mod b/go.mod index fbb0f01..ed342e2 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210927032600-4c733f2cb879 github.com/boltdb/bolt v1.3.1 github.com/btcsuite/btcd v0.20.1-beta + github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e // indirect github.com/ethereum/go-ethereum v1.9.24 // indirect github.com/magiconair/properties v1.8.1 github.com/ontio/ontology v1.11.0 @@ -16,4 +17,5 @@ require ( github.com/spf13/cobra v1.1.1 github.com/spf13/viper v1.7.0 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 + launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect ) diff --git a/go.sum b/go.sum index a8bff17..08f2f03 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,7 @@ 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= @@ -44,44 +45,11 @@ github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrU 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.0 h1:pxINq2woI80BQkMb8dnIVsHw0pk6AkEnZ7DNE94bDMo= -github.com/Zilliqa/gozilliqa-sdk v1.2.0/go.mod h1:eSYp2T6f0apnuW8TzhV3f6Aff2SE8Dwio++U4ha4yEM= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43 h1:m90pmiBsPC1B8CFLWMU6EMfqtVt6lZgeCAah7yuWvJA= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210115043807-15b50134ce43/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210219095216-01f23f46ac19 h1:aSEnsuYQU7BeoKTHIrZpEU7mM5Le5pCgD83T1H9mECs= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210219095216-01f23f46ac19/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134150-463aafc8ddfd h1:/bf/8Lr35tn6WZY6cV25CL9Xv2Os4L59OMa+FQu5E4w= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134150-463aafc8ddfd/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134949-c70ae6ea83ba h1:WMfTz//M7d4MyqYhsTw94lu+0pSL8uhqLAMQuaSV2iw= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210221134949-c70ae6ea83ba/go.mod h1:pFTR1kiObhgi/4GYERw7/WHz+P5BD7ecE49uG12tqAY= -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.20210222003933-7691f5ca42a2 h1:faO7UGk2+OU/NItQMQPeJR2Pw9DkCCw3mhJVEGsodcQ= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210222003933-7691f5ca42a2/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.20210303070214-e9f060dd9677 h1:BczNHdGYMiLdVgENX9cNkza+b24gIHUx6iNygpxtG4c= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210303070214-e9f060dd9677/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= -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.20210308032016-7002414861d8 h1:6JJXeTfBSavuY2YlTbMuzLm6RGDEutPcqcs37AMO84c= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210308032016-7002414861d8/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210319095817-ba48ea16964d h1:YCdnGqR2hKpcr1+6/F9l6hhkqEmHlxrURKJsjOqu388= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210319095817-ba48ea16964d/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.20210324082803-7bad2d49a99e h1:ltcsP84eL0lEni4lMRo+4s0squQgkkoTfRE/r8IyyuU= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210324082803-7bad2d49a99e/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210329090957-47fa84b98939 h1:AvHW2baBlvOyni0yC7/TesgYQIu2GMcc4U9oMGZn65A= -github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210329090957-47fa84b98939/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/Zilliqa/gozilliqa-sdk v1.2.1-0.20210927032600-4c733f2cb879 h1:/OXqInjRm8CEd81EEFCGJ5Q24TTlY1/qu6DQ0D91WPA= github.com/Zilliqa/gozilliqa-sdk v1.2.1-0.20210927032600-4c733f2cb879/go.mod h1:XLd05IRvH+nQt2lLvW6I2pfWBtRYE4i8Tpx45xBrlUE= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= @@ -90,6 +58,7 @@ 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= @@ -107,6 +76,7 @@ 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/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= @@ -128,8 +98,10 @@ 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= @@ -145,6 +117,8 @@ 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 h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw= +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= @@ -189,6 +163,7 @@ github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5m 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/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTyCIo22xvs= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= @@ -201,21 +176,23 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= 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 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -274,12 +251,10 @@ 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= @@ -289,9 +264,11 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ 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/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64= github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -302,6 +279,7 @@ 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/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +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/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= @@ -386,6 +364,7 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u 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/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +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= @@ -399,10 +378,13 @@ 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/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= @@ -423,13 +405,13 @@ 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= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= 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 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= @@ -452,6 +434,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/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= 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= @@ -464,11 +447,13 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 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 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= 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/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 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/ontio/go-bip32 v0.0.0-20190520025953-d3cea6894a2b h1:UQDN12BzdWhXQL0t2QcRixHqAIG+JKNvQ20DhrIODtU= github.com/ontio/go-bip32 v0.0.0-20190520025953-d3cea6894a2b/go.mod h1:J0eVc7BEMmVVXbGv9PHoxjRSEwOwLr0qfzPk8Rdl5iw= @@ -518,23 +503,27 @@ github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod 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 h1:Ctq0iGpCmr3jeP77kbF2UxgvRwzWWz+4Bh9/vJTyg1A= github.com/prometheus/client_golang v1.5.0/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= @@ -553,7 +542,6 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= 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= @@ -562,7 +550,9 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +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= @@ -608,7 +598,6 @@ 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/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.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= @@ -646,6 +635,7 @@ github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWp github.com/zquestz/grab v0.0.0-20190224022517-abcee96e61b1 h1:1qKTeMTSIEvRIjvVYzgcRp0xVp0eoiRTTiHSncb5gD8= github.com/zquestz/grab v0.0.0-20190224022517-abcee96e61b1/go.mod h1:bslhAiUxakrA6z6CHmVyvkfpnxx18RJBwVyx2TluJWw= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= @@ -665,7 +655,6 @@ golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -730,7 +719,6 @@ golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLL 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= @@ -759,7 +747,6 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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= @@ -776,7 +763,6 @@ golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7w 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/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -784,7 +770,6 @@ golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 h1:AvbQYmiaaaza3cW3QXRyPo5kY golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/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= @@ -820,6 +805,7 @@ golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapK 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/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= 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/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= @@ -868,13 +854,13 @@ 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= @@ -888,6 +874,7 @@ gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200316214253-d7b0ff38cac9/go.mod h1:uAJ 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/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= @@ -896,7 +883,6 @@ 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= @@ -907,6 +893,8 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/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 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54= +launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= 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/service/poly2zil.go b/service/poly2zil.go index 35d050c..4cbd4bc 100644 --- a/service/poly2zil.go +++ b/service/poly2zil.go @@ -106,6 +106,7 @@ func (p *PolySyncManager) handleDepositEvents(height, latest uint32) bool { proof, _ := p.polySdk.GetMerkleProof(height+1, height+2) hp = proof.AuditPath } + cnt := 0 events, err := p.polySdk.GetSmartContractEventByBlock(height) for err != nil { @@ -264,5 +265,10 @@ func (p *PolySyncManager) findLatestHeight() uint32 { return 0 } - return 0 + height, err2 := strconv.ParseUint(epochStartHeightRep.Result.CurEpochStartHeight, 10, 32) + if err2 != nil { + log.Errorf("PolySyncManager FindLatestHeight - failed to parse epoch start height: %s\n", err2.Error()) + return 0 + } + return uint32(height) } diff --git a/service/polymanager.go b/service/polymanager.go index d053763..dd95463 100644 --- a/service/polymanager.go +++ b/service/polymanager.go @@ -29,6 +29,7 @@ import ( "github.com/polynetwork/zilliqa-relayer/config" "github.com/polynetwork/zilliqa-relayer/db" "github.com/polynetwork/zilliqa-relayer/tools" + "strings" ) type PolySyncManager struct { @@ -88,7 +89,7 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * if err1 != nil { return nil, err1 } - pwd := keystorepwdset[ks.Address] + pwd := keystorepwdset[strings.ToLower(ks.Address)] if pwd == nil { return nil, errors.New("NewPolySyncManager - there is no password for zilliqa.wallet: " + ks.Address) } @@ -110,10 +111,11 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * MsgVersion: cfg.ZilConfig.ZilMessageVersion, } + addr := strings.Replace(ks.Address, "0x", "", 1) sender := &ZilSender{ cfg: cfg, zilSdk: zilSdk, - address: ks.Address, + address: addr, privateKey: privateKey, polySdk: polySdk, crossChainProxy: proxy, @@ -122,9 +124,9 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * senders = append(senders, sender) - balAndNonce, err3 := zilSdk.GetBalance(ks.Address) + balAndNonce, err3 := zilSdk.GetBalance(addr) if err3 != nil { - log.Infof("NewPolySyncManager get address %s nonce error %s", ks.Address, err3.Error()) + log.Infof("NewPolySyncManager get address %s nonce error %s", addr, err3.Error()) continue } @@ -135,7 +137,6 @@ func NewPolySyncManager(cfg *config.Config, zilSdk *provider.Provider, polySdk * privateKeys = append(privateKeys, privateKey) zilSenderMap[privateKey] = privateKeyAndNonce - } nonceManager := &NonceManager{ From 65c23dcdc2903925acf72e9d814178edf4b108f3 Mon Sep 17 00:00:00 2001 From: Francesco Medas <104889824+frankmeds@users.noreply.github.com> Date: Fri, 5 Jan 2024 16:20:28 +0400 Subject: [PATCH 093/107] feat: add relayer pipeline (#13) --- .github/workflows/ci-image.yml | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/ci-image.yml diff --git a/.github/workflows/ci-image.yml b/.github/workflows/ci-image.yml new file mode 100644 index 0000000..2a4a60f --- /dev/null +++ b/.github/workflows/ci-image.yml @@ -0,0 +1,39 @@ +name: CI - Release + +on: + push: + +jobs: + release-image: + permissions: + id-token: write + contents: write + runs-on: docker + steps: + - name: 'Checkout scm ${{ inputs.commitOrTag }}' + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ inputs.commitOrTag }} + + - name: Image tag + id: set-tag + run: echo "tag=$(git rev-parse --short=7 HEAD)" >> $GITHUB_OUTPUT + shell: bash + + - name: Build Docker images + run: docker build -t zilliqa/zilliqa-relayer:experimental-${{ steps.set-tag.outputs.tag }} -t zilliqa/zilliqa-relayer:latest . + shell: bash + + - name: Login to the DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Push Docker images to Dockerhub + if: github.actor != 'dependabot[bot]' && github.ref_name == 'main' + run: | + docker push zilliqa/zilliqa-relayer:experimental-${{ steps.set-tag.outputs.tag }} + docker push zilliqa/zilliqa-relayer:latest + shell: bash \ No newline at end of file From efd966c782a9331583d304bc6fc428939dbf87da Mon Sep 17 00:00:00 2001 From: Steven Khong Date: Wed, 28 Feb 2024 19:40:38 +0900 Subject: [PATCH 094/107] corrected condition (#12) Co-authored-by: lance.lan --- service/zil2poly.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index 2d92cac..9d3bacc 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -21,6 +21,11 @@ import ( "bytes" "encoding/json" "fmt" + "math/big" + "strconv" + "strings" + "time" + "github.com/Zilliqa/gozilliqa-sdk/bech32" "github.com/Zilliqa/gozilliqa-sdk/core" "github.com/Zilliqa/gozilliqa-sdk/util" @@ -29,10 +34,6 @@ import ( autils "github.com/polynetwork/poly/native/service/utils" "github.com/polynetwork/zilliqa-relayer/tools" log "github.com/sirupsen/logrus" - "math/big" - "strconv" - "strings" - "time" ) /** @@ -149,7 +150,7 @@ T: log.Infof("ZilliqaSyncManager handleBlockHeader - header hash: %s\n", util.EncodeHex(blockHash)) raw, _ := s.polySdk.GetStorage(autils.HeaderSyncContractAddress.ToHexString(), append(append([]byte(scom.MAIN_CHAIN), autils.GetUint64Bytes(s.cfg.ZilConfig.SideChainId)...), autils.GetUint64Bytes(height)...)) - if len(raw) == 0 || bytes.Equal(raw, blockHash) { + if len(raw) == 0 || !bytes.Equal(raw, blockHash) { s.header4sync = append(s.header4sync, rawBlock) } return true From 5c81aae6b55930442a110207d812ab2752a49a5c Mon Sep 17 00:00:00 2001 From: Mauro Medda Date: Wed, 28 Feb 2024 11:51:23 +0100 Subject: [PATCH 095/107] Debug (#14) Co-authored-by: Richard Watts --- .gitignore | 3 +++ service/zil2poly.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/.gitignore b/.gitignore index cddf0c9..a7f71c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +*~ +\#* +.\#* zilliqa-relayer .idea bolt.bin diff --git a/service/zil2poly.go b/service/zil2poly.go index 9d3bacc..7703d41 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -67,6 +67,7 @@ func (s *ZilliqaSyncManager) MonitorChain() { blockHandleResult = true for s.currentHeight < blockNumber { + s.dumpPendingHeaders() if !s.handleNewBlock(s.currentHeight + 1) { break } @@ -74,6 +75,7 @@ func (s *ZilliqaSyncManager) MonitorChain() { if uint32(len(s.header4sync)) > s.cfg.ZilConfig.ZilHeadersPerBatch { log.Infof("ZilliqaSyncManager MonitorChain - commit header") + s.dumpPendingHeaders() if res := s.commitHeader(); res != 0 { log.Errorf("ZilliqaSyncManager MonitorChain -- commit header error, result %d", res) blockHandleResult = false @@ -153,6 +155,7 @@ T: if len(raw) == 0 || !bytes.Equal(raw, blockHash) { s.header4sync = append(s.header4sync, rawBlock) } + s.dumpPendingHeaders() return true } @@ -373,6 +376,21 @@ func (this *CrossTransfer) Deserialization(source *common.ZeroCopySource) error return nil } +func (s *ZilliqaSyncManager) dumpPendingHeaders() { + log.Infof("ZilliqaSyncManager pending headers ------**-*") + for _, raw := range s.header4sync { + var block core.TxBlockOrDsBlock + _ = json.Unmarshal(raw, &block) + if block.TxBlock != nil { + log.Infof("ZilliqaSyncManager txBlk %d", block.TxBlock.BlockHeader.BlockNum) + } + if block.DsBlock != nil { + log.Infof("ZilliqaSyncManager dsBlk %d", block.DsBlock.BlockHeader.BlockNum) + } + } + log.Infof("ZilliqaSyncManager pending headers ======**=*") +} + func (s *ZilliqaSyncManager) commitHeader() int { // maybe delete this after it is stable for _, raw := range s.header4sync { From 73f7cf34ed8808b78b2b63c55dcc0a146f026ef0 Mon Sep 17 00:00:00 2001 From: Mauro Medda Date: Wed, 28 Feb 2024 12:08:49 +0100 Subject: [PATCH 096/107] (add): more debug (#15) * Debug * More debug. --------- Co-authored-by: Richard Watts --- service/zil2poly.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/service/zil2poly.go b/service/zil2poly.go index 7703d41..402b188 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -420,6 +420,11 @@ func (s *ZilliqaSyncManager) commitHeader() int { return 0 } else { log.Errorf("ZilliqaSyncManager commitHeader - send transaction to poly chain err: %s", errDesc) + log.Info("ZilliqaSyncManager - Raw data ****** ") + for _, raw := range s.header4sync { + log.Infof(string(raw[:])) + } + log.Infof("ZilliqaSyncManager - Raw data ends ====== ") return 1 } } From 844f457d5345824ad6ae9f6e97e09de8e096d0de Mon Sep 17 00:00:00 2001 From: Richard Watts <108257153+rrw-zilliqa@users.noreply.github.com> Date: Thu, 29 Feb 2024 13:03:59 +0000 Subject: [PATCH 097/107] Users/richard/debug (#16) * Debug * More debug. * (debug) Add more debugging. --- service/zil2poly.go | 1 + service/zilliqamanager.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/service/zil2poly.go b/service/zil2poly.go index 402b188..c49654e 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -402,6 +402,7 @@ func (s *ZilliqaSyncManager) commitHeader() int { if block.DsBlock != nil { log.Infof("ZilliqaSyncManager commitHeader - about to commit ds block: %d\n", block.DsBlock.BlockHeader.BlockNum) + s.checkDSBlockInStorage(block.DsBlock.BlockHeader.BlockNum) } } diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index d7b6999..5442e52 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -121,6 +121,7 @@ func (s *ZilliqaSyncManager) init() error { s.currentHeight = latestHeight } log.Infof("ZilliqaSyncManager init - start height: %d", s.currentHeight) + s.getGenesisHeader() txBlockT, err := s.zilSdk.GetTxBlockVerbose(strconv.FormatUint(s.currentHeight, 10)) if err != nil { @@ -132,6 +133,43 @@ func (s *ZilliqaSyncManager) init() error { return nil } +func (s *ZilliqaSyncManager) getGenesisHeader() { + var sideChainIdBytes [8]byte + binary.LittleEndian.PutUint64(sideChainIdBytes[:], s.cfg.ZilConfig.SideChainId) + key := append([]byte(scom.GENESIS_HEADER), sideChainIdBytes[:]...) + contractAddress := autils.HeaderSyncContractAddress + result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) + if err != nil { + log.Printf("cannot obtain latest genesis header\n") + } + if result == nil || len(result) == 0 { + log.Printf("0-length result from gensis header query\n") + } + log.Printf("----- GENESIS HEADER ----- \n") + for _, b := range result { + log.Printf("%02x ", b) + } + log.Print("====== END GENESIS HEADER ===== \n") +} + +func (s *ZilliqaSyncManager) checkDSBlockInStorage(blk uint64) { + var sideChainIdBytes [8]byte + binary.LittleEndian.PutUint64(sideChainIdBytes[:], s.cfg.ZilConfig.SideChainId) + var blkc [8]byte + binary.LittleEndian.PutUint64(blkc[:], blk) + key := append(sideChainIdBytes[:], []byte("dsComm")...) + key = append(key, blkc[:]...) + result, err := s.polySdk.GetStorage(autils.HeaderSyncContractAddress.ToHexString(), key) + if err != nil { + log.Printf("Couldn't retrieve polynet storage for DS Block %d: %s", blk, err.Error()) + } + if result == nil || len(result) == 0 { + log.Printf("no DSC stored for ds block %d", blk) + } else { + log.Printf("Something there for ds block %d", blk) + } +} + func (s *ZilliqaSyncManager) findLatestTxBlockHeight() uint64 { // try to get key var sideChainIdBytes [8]byte From 88594be4e79ef768772b4f51623577c0ba3c2959 Mon Sep 17 00:00:00 2001 From: Richard Watts <108257153+rrw-zilliqa@users.noreply.github.com> Date: Thu, 29 Feb 2024 13:38:56 +0000 Subject: [PATCH 098/107] More debug (#17) --- service/zil2poly.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index c49654e..19a1d36 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -397,7 +397,9 @@ func (s *ZilliqaSyncManager) commitHeader() int { var block core.TxBlockOrDsBlock _ = json.Unmarshal(raw, &block) if block.TxBlock != nil { - log.Infof("ZilliqaSyncManager commitHeader - about to commit tx block: %d\n", block.TxBlock.BlockHeader.BlockNum) + log.Infof("ZilliqaSyncManager commitHeader - about to commit tx block: %d from DS %d \n", block.TxBlock.BlockHeader.BlockNum, + block.TxBlock.BlockHeader.DSBlockNum) + s.checkDSBlockInStorage(block.TxBlock.BlockHeader.DSBlockNum) } if block.DsBlock != nil { From 13d0a280de682bb409fd2031b94b10b0a7194042 Mon Sep 17 00:00:00 2001 From: Richard Watts <108257153+rrw-zilliqa@users.noreply.github.com> Date: Fri, 1 Mar 2024 10:44:22 +0000 Subject: [PATCH 099/107] More debug! (#18) --- service/zil2poly.go | 3 ++ service/zilliqamanager.go | 68 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index 19a1d36..d7bd563 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -400,11 +400,14 @@ func (s *ZilliqaSyncManager) commitHeader() int { log.Infof("ZilliqaSyncManager commitHeader - about to commit tx block: %d from DS %d \n", block.TxBlock.BlockHeader.BlockNum, block.TxBlock.BlockHeader.DSBlockNum) s.checkDSBlockInStorage(block.TxBlock.BlockHeader.DSBlockNum) + s.getHeaderIndex(block.TxBlock.BlockHeader.BlockNum, block.TxBlock.BlockHash[:]) + s.getMainChain(block.TxBlock.BlockHeader.BlockNum) } if block.DsBlock != nil { log.Infof("ZilliqaSyncManager commitHeader - about to commit ds block: %d\n", block.DsBlock.BlockHeader.BlockNum) s.checkDSBlockInStorage(block.DsBlock.BlockHeader.BlockNum) + s.getDsBlockHeader(block.DsBlock.BlockHeader.BlockNum, block.DsBlock.BlockHash[:]) } } diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 5442e52..3f718c4 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -122,7 +122,7 @@ func (s *ZilliqaSyncManager) init() error { } log.Infof("ZilliqaSyncManager init - start height: %d", s.currentHeight) s.getGenesisHeader() - + s.getMainChain(latestHeight) txBlockT, err := s.zilSdk.GetTxBlockVerbose(strconv.FormatUint(s.currentHeight, 10)) if err != nil { return fmt.Errorf("ZilliqaSyncManager init - get tx block error: %s", err.Error()) @@ -145,13 +145,73 @@ func (s *ZilliqaSyncManager) getGenesisHeader() { if result == nil || len(result) == 0 { log.Printf("0-length result from gensis header query\n") } + // Turns out the genesis header is a string. + genesisString := string(result[:]) log.Printf("----- GENESIS HEADER ----- \n") - for _, b := range result { - log.Printf("%02x ", b) - } + log.Printf("%s", genesisString) log.Print("====== END GENESIS HEADER ===== \n") } +// Get the DS Block Header +func (s *ZilliqaSyncManager) getDsBlockHeader(dsBlkNum uint64, hash []byte) { + var sideChainIdBytes [8]byte + binary.LittleEndian.PutUint64(sideChainIdBytes[:], s.cfg.ZilConfig.SideChainId) + key := append([]byte(scom.HEADER_INDEX), sideChainIdBytes[:]...) + key = append(key, hash...) + contractAddress := autils.HeaderSyncContractAddress + result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) + log.Printf("---- DS Header hash with blknum %d hash %x", dsBlkNum, hash) + if err != nil { + log.Printf("==== FAILED %s", err) + } + if result == nil || len(result) == 0 { + log.Printf("==== 0-length or empty result") + } else { + log.Printf("==== Retrieved: %x", result) + } + +} + +// Given a tx block number, try to obtain MAIN_CHAIN +func (s *ZilliqaSyncManager) getMainChain(blknum uint64) { + var sideChainIdBytes [8]byte + binary.LittleEndian.PutUint64(sideChainIdBytes[:], s.cfg.ZilConfig.SideChainId) + key := append([]byte(scom.MAIN_CHAIN), sideChainIdBytes[:]...) + var blkNumBytes [8]byte + binary.LittleEndian.PutUint64(blkNumBytes[:], blknum) + key = append(key, blkNumBytes[:]...) + contractAddress := autils.HeaderSyncContractAddress + result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) + log.Printf("---- MAIN_CHAIN with blknum %d", blknum) + if err != nil { + log.Printf("==== FAILED %s", err) + } + if result == nil || len(result) == 0 { + log.Printf("==== 0-length or empty result") + } else { + log.Printf("==== Retrieved: %x", result) + } +} + +// Given a tx block hash, see if the header index is in storage. +func (s *ZilliqaSyncManager) getHeaderIndex(blknum uint64, hash []byte) { + var sideChainIdBytes [8]byte + binary.LittleEndian.PutUint64(sideChainIdBytes[:], s.cfg.ZilConfig.SideChainId) + key := append([]byte(scom.HEADER_INDEX), sideChainIdBytes[:]...) + key = append(key, hash...) + contractAddress := autils.HeaderSyncContractAddress + result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) + log.Printf("---- Header hash with blknum %d hash %x", blknum, hash) + if err != nil { + log.Printf("==== FAILED %s", err) + } + if result == nil || len(result) == 0 { + log.Printf("==== 0-length or empty result") + } else { + log.Printf("==== Retrieved: %x", result) + } +} + func (s *ZilliqaSyncManager) checkDSBlockInStorage(blk uint64) { var sideChainIdBytes [8]byte binary.LittleEndian.PutUint64(sideChainIdBytes[:], s.cfg.ZilConfig.SideChainId) From 666699293698517f56955b55ac72bf96915b36d5 Mon Sep 17 00:00:00 2001 From: Richard Watts <108257153+rrw-zilliqa@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:00:32 +0000 Subject: [PATCH 100/107] Yet more debug (#19) --- service/zil2poly.go | 4 ++++ service/zilliqamanager.go | 42 +++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/service/zil2poly.go b/service/zil2poly.go index d7bd563..e824298 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -399,14 +399,18 @@ func (s *ZilliqaSyncManager) commitHeader() int { if block.TxBlock != nil { log.Infof("ZilliqaSyncManager commitHeader - about to commit tx block: %d from DS %d \n", block.TxBlock.BlockHeader.BlockNum, block.TxBlock.BlockHeader.DSBlockNum) + log.Infof("000 Check if DS block is in storage") s.checkDSBlockInStorage(block.TxBlock.BlockHeader.DSBlockNum) + log.Infof("Check header index") s.getHeaderIndex(block.TxBlock.BlockHeader.BlockNum, block.TxBlock.BlockHash[:]) + log.Infof("Check main chain") s.getMainChain(block.TxBlock.BlockHeader.BlockNum) } if block.DsBlock != nil { log.Infof("ZilliqaSyncManager commitHeader - about to commit ds block: %d\n", block.DsBlock.BlockHeader.BlockNum) s.checkDSBlockInStorage(block.DsBlock.BlockHeader.BlockNum) + log.Infof("000 check ds block hash") s.getDsBlockHeader(block.DsBlock.BlockHeader.BlockNum, block.DsBlock.BlockHash[:]) } } diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 3f718c4..956284e 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -140,16 +140,16 @@ func (s *ZilliqaSyncManager) getGenesisHeader() { contractAddress := autils.HeaderSyncContractAddress result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) if err != nil { - log.Printf("cannot obtain latest genesis header\n") + log.Infof("cannot obtain latest genesis header\n") } if result == nil || len(result) == 0 { - log.Printf("0-length result from gensis header query\n") + log.Infof("0-length result from gensis header query\n") } // Turns out the genesis header is a string. genesisString := string(result[:]) - log.Printf("----- GENESIS HEADER ----- \n") - log.Printf("%s", genesisString) - log.Print("====== END GENESIS HEADER ===== \n") + log.Infof("----- GENESIS HEADER ----- \n") + log.Infof("%s", genesisString) + log.Infof("====== END GENESIS HEADER ===== \n") } // Get the DS Block Header @@ -160,14 +160,14 @@ func (s *ZilliqaSyncManager) getDsBlockHeader(dsBlkNum uint64, hash []byte) { key = append(key, hash...) contractAddress := autils.HeaderSyncContractAddress result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) - log.Printf("---- DS Header hash with blknum %d hash %x", dsBlkNum, hash) + log.Infof("---- DS Header hash with blknum %d hash %x", dsBlkNum, hash) if err != nil { - log.Printf("==== FAILED %s", err) + log.Infof("==== FAILED %s", err) } if result == nil || len(result) == 0 { - log.Printf("==== 0-length or empty result") + log.Infof("==== 0-length or empty result") } else { - log.Printf("==== Retrieved: %x", result) + log.Infof("==== Retrieved: %x", result) } } @@ -182,14 +182,14 @@ func (s *ZilliqaSyncManager) getMainChain(blknum uint64) { key = append(key, blkNumBytes[:]...) contractAddress := autils.HeaderSyncContractAddress result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) - log.Printf("---- MAIN_CHAIN with blknum %d", blknum) + log.Infof("---- MAIN_CHAIN with blknum %d", blknum) if err != nil { - log.Printf("==== FAILED %s", err) + log.Infof("==== FAILED %s", err) } if result == nil || len(result) == 0 { - log.Printf("==== 0-length or empty result") + log.Infof("==== 0-length or empty result") } else { - log.Printf("==== Retrieved: %x", result) + log.Infof("==== Retrieved: %x", result) } } @@ -201,14 +201,14 @@ func (s *ZilliqaSyncManager) getHeaderIndex(blknum uint64, hash []byte) { key = append(key, hash...) contractAddress := autils.HeaderSyncContractAddress result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) - log.Printf("---- Header hash with blknum %d hash %x", blknum, hash) + log.Infof("---- Header hash with blknum %d hash %x", blknum, hash) if err != nil { - log.Printf("==== FAILED %s", err) + log.Infof("==== FAILED %s", err) } if result == nil || len(result) == 0 { - log.Printf("==== 0-length or empty result") + log.Infof("==== 0-length or empty result") } else { - log.Printf("==== Retrieved: %x", result) + log.Infof("==== Retrieved: %x", result) } } @@ -221,12 +221,12 @@ func (s *ZilliqaSyncManager) checkDSBlockInStorage(blk uint64) { key = append(key, blkc[:]...) result, err := s.polySdk.GetStorage(autils.HeaderSyncContractAddress.ToHexString(), key) if err != nil { - log.Printf("Couldn't retrieve polynet storage for DS Block %d: %s", blk, err.Error()) + log.Infof("Couldn't retrieve polynet storage for DS Block %d: %s", blk, err.Error()) } if result == nil || len(result) == 0 { - log.Printf("no DSC stored for ds block %d", blk) + log.Infof("no DSC stored for ds block %d", blk) } else { - log.Printf("Something there for ds block %d", blk) + log.Infof("Something there for ds block %d", blk) } } @@ -239,7 +239,7 @@ func (s *ZilliqaSyncManager) findLatestTxBlockHeight() uint64 { // try to get storage result, err := s.polySdk.GetStorage(contractAddress.ToHexString(), key) if err != nil { - log.Printf("get latest tx block from poly failed,err: %s\n", err.Error()) + log.Infof("get latest tx block from poly failed,err: %s\n", err.Error()) return 0 } if result == nil || len(result) == 0 { From e0050b88ae420e09dd167430ff072aa69d1f1803 Mon Sep 17 00:00:00 2001 From: Richard Watts <108257153+rrw-zilliqa@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:25:15 +0000 Subject: [PATCH 101/107] Yet more debug (#20) --- service/zilliqamanager.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 956284e..13125ef 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -19,8 +19,10 @@ package service import ( "encoding/binary" + "encoding/json" "fmt" "github.com/Zilliqa/gozilliqa-sdk/account" + "github.com/Zilliqa/gozilliqa-sdk/core" "github.com/Zilliqa/gozilliqa-sdk/provider" poly "github.com/polynetwork/poly-go-sdk" sdk "github.com/polynetwork/poly-go-sdk" @@ -146,10 +148,31 @@ func (s *ZilliqaSyncManager) getGenesisHeader() { log.Infof("0-length result from gensis header query\n") } // Turns out the genesis header is a string. + block := new(core.TxBlock) genesisString := string(result[:]) log.Infof("----- GENESIS HEADER ----- \n") log.Infof("%s", genesisString) log.Infof("====== END GENESIS HEADER ===== \n") + err = json.Unmarshal(result, block) + if err != nil { + log.Infof("!!!!! Could not unmarshal genesis - %s", err) + } else { + log.Infof("Get main chain for %d", block.BlockHeader.BlockNum) + s.getMainChain(block.BlockHeader.BlockNum) + log.Infof("GetHeaderIndex for %d:%x", block.BlockHeader.BlockNum, block.BlockHash) + s.getHeaderIndex(block.BlockHeader.BlockNum, block.BlockHash[:]) + dsBlockNum := block.BlockHeader.DSBlockNum + log.Infof("Get DS Block %d from chain", dsBlockNum) + dsb, err := s.zilSdk.GetDsBlock(strconv.Itoa(int(dsBlockNum))) + if err != nil { + log.Infof("Could not get DS Block - %s", err) + } else { + dsbval := core.NewDsBlockFromDsBlockT(dsb) + log.Infof("getDsBlockHeader %x", dsbval.BlockHash) + s.getDsBlockHeader(dsBlockNum, dsbval.BlockHash[:]) + } + log.Infof("XXX Done") + } } // Get the DS Block Header From 23118e283dda944ed531068aea570d0a697c0e4d Mon Sep 17 00:00:00 2001 From: Richard Watts <108257153+rrw-zilliqa@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:44:38 +0000 Subject: [PATCH 102/107] And more (#21) --- service/zilliqamanager.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 13125ef..cd7f423 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -163,13 +163,17 @@ func (s *ZilliqaSyncManager) getGenesisHeader() { s.getHeaderIndex(block.BlockHeader.BlockNum, block.BlockHash[:]) dsBlockNum := block.BlockHeader.DSBlockNum log.Infof("Get DS Block %d from chain", dsBlockNum) - dsb, err := s.zilSdk.GetDsBlock(strconv.Itoa(int(dsBlockNum))) + dsb, err := s.zilSdk.GetDsBlockVerbose(strconv.FormatUint(dsBlockNum, 10)) if err != nil { log.Infof("Could not get DS Block - %s", err) } else { - dsbval := core.NewDsBlockFromDsBlockT(dsb) - log.Infof("getDsBlockHeader %x", dsbval.BlockHash) - s.getDsBlockHeader(dsBlockNum, dsbval.BlockHash[:]) + if dsb == nil { + log.Infof("nil DS Block %s", strconv.Itoa(int(dsBlockNum))) + } else { + dsbval := core.NewDsBlockFromDsBlockT(dsb) + log.Infof("getDsBlockHeader %x", dsbval.BlockHash) + s.getDsBlockHeader(dsBlockNum, dsbval.BlockHash[:]) + } } log.Infof("XXX Done") } From 63fd1ca30abe4c209e0b74cdb34ac92c6afc7594 Mon Sep 17 00:00:00 2001 From: Richard Watts <108257153+rrw-zilliqa@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:57:00 +0000 Subject: [PATCH 103/107] Round 6 (#22) --- service/zilliqamanager.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index cd7f423..34842c9 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -162,6 +162,8 @@ func (s *ZilliqaSyncManager) getGenesisHeader() { log.Infof("GetHeaderIndex for %d:%x", block.BlockHeader.BlockNum, block.BlockHash) s.getHeaderIndex(block.BlockHeader.BlockNum, block.BlockHash[:]) dsBlockNum := block.BlockHeader.DSBlockNum + log.Infof("Get DsComm %d from polynet", dsBlockNum) + s.checkDSBlockInStorage(dsBlockNum) log.Infof("Get DS Block %d from chain", dsBlockNum) dsb, err := s.zilSdk.GetDsBlockVerbose(strconv.FormatUint(dsBlockNum, 10)) if err != nil { @@ -248,12 +250,12 @@ func (s *ZilliqaSyncManager) checkDSBlockInStorage(blk uint64) { key = append(key, blkc[:]...) result, err := s.polySdk.GetStorage(autils.HeaderSyncContractAddress.ToHexString(), key) if err != nil { - log.Infof("Couldn't retrieve polynet storage for DS Block %d: %s", blk, err.Error()) + log.Infof("XXXX Couldn't retrieve polynet storage for DS Block %d: %s", blk, err.Error()) } if result == nil || len(result) == 0 { - log.Infof("no DSC stored for ds block %d", blk) + log.Infof("XXXX no DSC stored for ds block %d", blk) } else { - log.Infof("Something there for ds block %d", blk) + log.Infof("==== DSC for DS block %d is %x", blk, result) } } From baf74b12782f50033b26f08fd3c7d0ef884993b4 Mon Sep 17 00:00:00 2001 From: Richard Watts <108257153+rrw-zilliqa@users.noreply.github.com> Date: Fri, 1 Mar 2024 12:09:43 +0000 Subject: [PATCH 104/107] Search .. (#23) --- service/zilliqamanager.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index 34842c9..fd0114e 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -178,6 +178,16 @@ func (s *ZilliqaSyncManager) getGenesisHeader() { } } log.Infof("XXX Done") + s.scanForDsCommittees(dsBlockNum) + } +} + +func (s *ZilliqaSyncManager) scanForDsCommittees(seedBlk uint64) { + for i := -32; i < 32; i += 1 { + toSearch := int(seedBlk) + i + log.Infof("==== Is there a DSC for %d? ", toSearch) + s.checkDSBlockInStorage(uint64(toSearch)) + log.Infof("---- NEXT DSC") } } From c31613e942269a0718a34bfa7acf3c648b237813 Mon Sep 17 00:00:00 2001 From: Mauro Medda Date: Mon, 4 Mar 2024 15:01:03 +0100 Subject: [PATCH 105/107] (fix): zil2poly dsblock override prevention (#24) --- service/zil2poly.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/service/zil2poly.go b/service/zil2poly.go index e824298..1dbb9ec 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -124,6 +124,17 @@ T: goto T } if txBlock.BlockHeader.DSBlockNum > s.currentDsBlockNum { + // as we can't control the order how the header4sync on the poly + // nodes after we sent it across, + // this will ensure that all the TXBlock for a given DSBlock are synced before + // we proceed with the next dsblock. + log.Infof("ZilliqaSyncManager - new DsBlock %d", txBlock.BlockHeader.DSBlockNum) + log.Infof("ZilliqaSyncManager - sync all the txblock for %d", s.currentDsBlockNum) + if res := s.commitHeader(); res != 0 { + log.Errorf("ZilliqaSyncManager MonitorChain -- commit header error, result %d", res) + return false + } + log.Infof("ZilliqaSyncManager - handleBlockHeader query ds block: %d\n", txBlock.BlockHeader.DSBlockNum) dsBlock, err := s.zilSdk.GetDsBlockVerbose(strconv.FormatUint(txBlock.BlockHeader.DSBlockNum, 10)) if err != nil { From 2d061c89cfa6330b5a9d73d44c21b3b35a6b9528 Mon Sep 17 00:00:00 2001 From: Mauro Medda Date: Tue, 5 Mar 2024 18:07:11 +0100 Subject: [PATCH 106/107] (hack): print the data and returns without commit to poly (#26) --- service/zil2poly.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/service/zil2poly.go b/service/zil2poly.go index 1dbb9ec..dcc8fb7 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -234,6 +234,8 @@ func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { } func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { + // remove later + return nil log.Infof("ZilliqaSyncManager handleLockDepositEvents - height is %d", height) retryList, err := s.db.GetAllRetry() if err != nil { @@ -426,6 +428,9 @@ func (s *ZilliqaSyncManager) commitHeader() int { } } + // remove after the first run + log.Infof("ZilliqaSyncManager commitHeader - exit without sync") + return 1 tx, err := s.polySdk.Native.Hs.SyncBlockHeader( s.cfg.ZilConfig.SideChainId, s.polySigner.Address, From da42edbab14d7389c2028d60f4f3b9990f9166dd Mon Sep 17 00:00:00 2001 From: Richard Watts <108257153+rrw-zilliqa@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:57:18 +0000 Subject: [PATCH 107/107] (feat) If we're lucky, this conditionalises the debug and practice only code. (#29) --- README.md | 5 ++++ cmd/run.go | 6 ++++- service/zil2poly.go | 56 ++++++++++++++++++++++++--------------- service/zilliqamanager.go | 12 ++++++--- 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index e42fc6c..ee4e691 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,12 @@ After creation, you need to register it as a Relayer to Poly net and get consens Before running, you need feed the configuration file `config.yaml`. +`practice_only: true` will stop the relayer sending any actual transactions - it just prints what it would have done. +`debug: true` will produce a bunch of debug info useful when debugging ZilBridge sync. + ```yaml +practice_only: false +debug: true zil_config: zil_api: https://api.zilliqa.com zil_chain_id: 111 diff --git a/cmd/run.go b/cmd/run.go index ad08d1e..00eb5ca 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -86,6 +86,10 @@ var runCmd = &cobra.Command{ Short: "Run zilliqa relayer", Long: `Run zilliqa relayer`, Run: func(cmd *cobra.Command, args []string) { + viper.SetDefault("debug", false) + viper.SetDefault("practiceOnly", false) + debugInfo := viper.GetBool("debug") + practiceOnly := viper.GetBool("practice_only") zilConfigMap := viper.GetStringMap("zil_config") targetContractsPath := viper.GetString("target_contracts") dbPath := viper.GetString("db_path") @@ -161,7 +165,7 @@ var runCmd = &cobra.Command{ } // zil to poly - zilliqaManager, err := service.NewZilliqaSyncManager(cfg, zilSdk, polySdk, boltDB) + zilliqaManager, err := service.NewZilliqaSyncManager(cfg, zilSdk, polySdk, boltDB, debugInfo, practiceOnly) if err != nil { log.Errorf("init zilliqamanger error: %s\n", err.Error()) return diff --git a/service/zil2poly.go b/service/zil2poly.go index dcc8fb7..d617ecb 100644 --- a/service/zil2poly.go +++ b/service/zil2poly.go @@ -67,7 +67,9 @@ func (s *ZilliqaSyncManager) MonitorChain() { blockHandleResult = true for s.currentHeight < blockNumber { - s.dumpPendingHeaders() + if s.debugInfo { + s.dumpPendingHeaders() + } if !s.handleNewBlock(s.currentHeight + 1) { break } @@ -75,7 +77,9 @@ func (s *ZilliqaSyncManager) MonitorChain() { if uint32(len(s.header4sync)) > s.cfg.ZilConfig.ZilHeadersPerBatch { log.Infof("ZilliqaSyncManager MonitorChain - commit header") - s.dumpPendingHeaders() + if s.debugInfo { + s.dumpPendingHeaders() + } if res := s.commitHeader(); res != 0 { log.Errorf("ZilliqaSyncManager MonitorChain -- commit header error, result %d", res) blockHandleResult = false @@ -166,7 +170,9 @@ T: if len(raw) == 0 || !bytes.Equal(raw, blockHash) { s.header4sync = append(s.header4sync, rawBlock) } - s.dumpPendingHeaders() + if s.debugInfo { + s.dumpPendingHeaders() + } return true } @@ -234,8 +240,9 @@ func (s *ZilliqaSyncManager) fetchLockDepositEvents(height uint64) bool { } func (s *ZilliqaSyncManager) handleLockDepositEvents(height uint64) error { - // remove later - return nil + if s.practiceOnly { + return nil + } log.Infof("ZilliqaSyncManager handleLockDepositEvents - height is %d", height) retryList, err := s.db.GetAllRetry() if err != nil { @@ -412,25 +419,30 @@ func (s *ZilliqaSyncManager) commitHeader() int { if block.TxBlock != nil { log.Infof("ZilliqaSyncManager commitHeader - about to commit tx block: %d from DS %d \n", block.TxBlock.BlockHeader.BlockNum, block.TxBlock.BlockHeader.DSBlockNum) - log.Infof("000 Check if DS block is in storage") - s.checkDSBlockInStorage(block.TxBlock.BlockHeader.DSBlockNum) - log.Infof("Check header index") - s.getHeaderIndex(block.TxBlock.BlockHeader.BlockNum, block.TxBlock.BlockHash[:]) - log.Infof("Check main chain") - s.getMainChain(block.TxBlock.BlockHeader.BlockNum) + if s.debugInfo { + log.Infof("000 Check if DS block is in storage") + s.checkDSBlockInStorage(block.TxBlock.BlockHeader.DSBlockNum) + log.Infof("Check header index") + s.getHeaderIndex(block.TxBlock.BlockHeader.BlockNum, block.TxBlock.BlockHash[:]) + log.Infof("Check main chain") + s.getMainChain(block.TxBlock.BlockHeader.BlockNum) + } } if block.DsBlock != nil { log.Infof("ZilliqaSyncManager commitHeader - about to commit ds block: %d\n", block.DsBlock.BlockHeader.BlockNum) - s.checkDSBlockInStorage(block.DsBlock.BlockHeader.BlockNum) - log.Infof("000 check ds block hash") - s.getDsBlockHeader(block.DsBlock.BlockHeader.BlockNum, block.DsBlock.BlockHash[:]) + if s.debugInfo { + s.checkDSBlockInStorage(block.DsBlock.BlockHeader.BlockNum) + log.Infof("000 check ds block hash") + s.getDsBlockHeader(block.DsBlock.BlockHeader.BlockNum, block.DsBlock.BlockHash[:]) + } } } - // remove after the first run - log.Infof("ZilliqaSyncManager commitHeader - exit without sync") - return 1 + if s.practiceOnly { + log.Infof("ZilliqaSyncManager commitHeader - exit without sync") + return 1 + } tx, err := s.polySdk.Native.Hs.SyncBlockHeader( s.cfg.ZilConfig.SideChainId, s.polySigner.Address, @@ -446,11 +458,13 @@ func (s *ZilliqaSyncManager) commitHeader() int { return 0 } else { log.Errorf("ZilliqaSyncManager commitHeader - send transaction to poly chain err: %s", errDesc) - log.Info("ZilliqaSyncManager - Raw data ****** ") - for _, raw := range s.header4sync { - log.Infof(string(raw[:])) + if s.debugInfo { + log.Info("ZilliqaSyncManager - Raw data ****** ") + for _, raw := range s.header4sync { + log.Infof(string(raw[:])) + } + log.Infof("ZilliqaSyncManager - Raw data ends ====== ") } - log.Infof("ZilliqaSyncManager - Raw data ends ====== ") return 1 } } diff --git a/service/zilliqamanager.go b/service/zilliqamanager.go index fd0114e..354f1b6 100644 --- a/service/zilliqamanager.go +++ b/service/zilliqamanager.go @@ -52,9 +52,11 @@ type ZilliqaSyncManager struct { db *db.BoltDB exitChan chan int header4sync [][]byte + debugInfo bool + practiceOnly bool } -func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysdk *sdk.PolySdk, boltDB *db.BoltDB) (*ZilliqaSyncManager, error) { +func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysdk *sdk.PolySdk, boltDB *db.BoltDB, debugInfo bool, practiceOnly bool) (*ZilliqaSyncManager, error) { var wallet *sdk.Wallet var err error if !common.FileExisted(cfg.PolyConfig.PolyWalletFile) { @@ -92,6 +94,8 @@ func NewZilliqaSyncManager(cfg *config.Config, zilSdk *provider.Provider, polysd crossChainManagerAddress: cfg.ZilConfig.CrossChainManagerContract, polySigner: signer, polySdk: polysdk, + debugInfo: debugInfo, + practiceOnly: practiceOnly, } err = zilliqaSyncManager.init() @@ -123,8 +127,10 @@ func (s *ZilliqaSyncManager) init() error { s.currentHeight = latestHeight } log.Infof("ZilliqaSyncManager init - start height: %d", s.currentHeight) - s.getGenesisHeader() - s.getMainChain(latestHeight) + if s.debugInfo { + s.getGenesisHeader() + s.getMainChain(latestHeight) + } txBlockT, err := s.zilSdk.GetTxBlockVerbose(strconv.FormatUint(s.currentHeight, 10)) if err != nil { return fmt.Errorf("ZilliqaSyncManager init - get tx block error: %s", err.Error())