From fcd8f6d66c66914015ccc16f43bc633e7f42048d Mon Sep 17 00:00:00 2001 From: alok Date: Fri, 10 Nov 2023 03:39:40 +0530 Subject: [PATCH 1/4] feat: add commitment contract --- .gitignore | 1 + cmd/main.go | 42 +++--- go.mod | 9 ++ go.sum | 42 ++++++ pkg/contracts/preconf/preconf.go | 134 ++++++++++++++++++++ pkg/node/node.go | 74 +++++++++-- pkg/preconfirmation/preconfirmation.go | 41 ++++-- pkg/preconfirmation/preconfirmation_test.go | 24 +++- 8 files changed, 323 insertions(+), 44 deletions(-) create mode 100644 pkg/contracts/preconf/preconf.go diff --git a/.gitignore b/.gitignore index 9f294703..e4526a5d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor **/.idea **/.vscode *.DS_STORE +bin/* diff --git a/cmd/main.go b/cmd/main.go index b7f7690c..8a9af3cf 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -90,16 +90,18 @@ func createKey(c *cli.Context) error { } type config struct { - PrivKeyFile string `yaml:"priv_key_file" json:"priv_key_file"` - Secret string `yaml:"secret" json:"secret"` - PeerType string `yaml:"peer_type" json:"peer_type"` - P2PPort int `yaml:"p2p_port" json:"p2p_port"` - HTTPPort int `yaml:"http_port" json:"http_port"` - RPCPort int `yaml:"rpc_port" json:"rpc_port"` - LogFmt string `yaml:"log_fmt" json:"log_fmt"` - LogLevel string `yaml:"log_level" json:"log_level"` - Bootnodes []string `yaml:"bootnodes" json:"bootnodes"` - ExposeProviderAPI bool `yaml:"expose_provider_api" json:"expose_provider_api"` + PrivKeyFile string `yaml:"priv_key_file" json:"priv_key_file"` + Secret string `yaml:"secret" json:"secret"` + PeerType string `yaml:"peer_type" json:"peer_type"` + P2PPort int `yaml:"p2p_port" json:"p2p_port"` + HTTPPort int `yaml:"http_port" json:"http_port"` + RPCPort int `yaml:"rpc_port" json:"rpc_port"` + LogFmt string `yaml:"log_fmt" json:"log_fmt"` + LogLevel string `yaml:"log_level" json:"log_level"` + Bootnodes []string `yaml:"bootnodes" json:"bootnodes"` + ExposeProviderAPI bool `yaml:"expose_provider_api" json:"expose_provider_api"` + PreconfContract string `yaml:"preconf_contract" json:"preconf_contract"` + PreconfContractRPC string `yaml:"preconf_contract_rpc" json:"preconf_contract_rpc"` } func checkConfig(cfg *config) error { @@ -177,15 +179,17 @@ func start(c *cli.Context) error { } nd, err := node.NewNode(&node.Options{ - PrivKey: privKey, - Secret: cfg.Secret, - PeerType: cfg.PeerType, - P2PPort: cfg.P2PPort, - HTTPPort: cfg.HTTPPort, - RPCPort: cfg.RPCPort, - Logger: logger, - Bootnodes: cfg.Bootnodes, - ExposeProviderAPI: cfg.ExposeProviderAPI, + PrivKey: privKey, + Secret: cfg.Secret, + PeerType: cfg.PeerType, + P2PPort: cfg.P2PPort, + HTTPPort: cfg.HTTPPort, + RPCPort: cfg.RPCPort, + Logger: logger, + Bootnodes: cfg.Bootnodes, + ExposeProviderAPI: cfg.ExposeProviderAPI, + PreconfContract: cfg.PreconfContract, + PreconfContractRPC: cfg.PreconfContractRPC, }) if err != nil { return fmt.Errorf("failed starting node: %w", err) diff --git a/go.mod b/go.mod index 73add949..100f2e78 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,8 @@ require ( ) require ( + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/StackExchange/wmi v1.2.1 // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.7.0 // indirect @@ -35,12 +37,15 @@ require ( github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect + github.com/deckarep/golang-set/v2 v2.1.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect github.com/ethereum/c-kzg-4844 v0.3.1 // indirect github.com/flynn/noise v1.0.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect + github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/go-ole/go-ole v1.2.5 // indirect github.com/go-stack/stack v1.8.1 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect @@ -49,6 +54,7 @@ require ( github.com/golang/protobuf v1.5.3 // indirect github.com/google/gopacket v1.1.19 // indirect github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b // indirect + github.com/google/uuid v1.3.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/holiman/uint256 v1.2.3 // indirect github.com/huin/goupnp v1.3.0 // indirect @@ -99,8 +105,11 @@ require ( github.com/quic-go/webtransport-go v0.5.3 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/supranational/blst v0.3.11 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.uber.org/dig v1.17.0 // indirect diff --git a/go.sum b/go.sum index c438747a..3e42a089 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGy github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40= @@ -42,6 +44,8 @@ github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg 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/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= +github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= +github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cilium/ebpf v0.2.0/go.mod h1:To2CFviqOWL/M0gIMsvSMlqe7em/l1ALkX1PyjrX2Qs= @@ -81,6 +85,8 @@ 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/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU= github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U= +github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= +github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= @@ -97,12 +103,18 @@ github.com/ethereum/c-kzg-4844 v0.3.1 h1:sR65+68+WdnMKxseNWxSJuAv2tsUrihTpVBTfM/ github.com/ethereum/c-kzg-4844 v0.3.1/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/ethereum/go-ethereum v1.13.4 h1:25HJnaWVg3q1O7Z62LaaI6S9wVq8QCw3K88g8wEzrcM= github.com/ethereum/go-ethereum v1.13.4/go.mod h1:I0U5VewuuTzvBtVzKo7b3hJzDhXOUtn9mJW7SsIPB0Q= +github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= +github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI= +github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= @@ -124,6 +136,8 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= @@ -154,6 +168,8 @@ github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OI github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b h1:h9U78+dx9a4BKdQkBBos92HalKpaGKHrp+3Uo6yTodo= github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -163,6 +179,12 @@ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:Fecb github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk= github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk= +github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= +github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= +github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw= +github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= +github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= +github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -233,6 +255,8 @@ github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk= github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= @@ -255,6 +279,10 @@ github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8Rv github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= +github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= +github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= +github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= @@ -336,6 +364,8 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= +github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= @@ -371,6 +401,8 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= +github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -388,6 +420,8 @@ github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFA github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= +github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= @@ -489,6 +523,7 @@ golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -498,8 +533,11 @@ golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -510,6 +548,8 @@ golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 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.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= +golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 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-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -563,6 +603,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 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= diff --git a/pkg/contracts/preconf/preconf.go b/pkg/contracts/preconf/preconf.go new file mode 100644 index 00000000..6133c46c --- /dev/null +++ b/pkg/contracts/preconf/preconf.go @@ -0,0 +1,134 @@ +package preconfcontract + +import ( + "context" + "crypto/ecdsa" + "log/slog" + "math/big" + + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/ethclient" +) + +type Interface interface { + StoreCommitment( + ctx context.Context, + bid *big.Int, + blockNumber uint64, + txHash string, + commitmentHash string, + bidSignature []byte, + commitmentSignature []byte, + ) error +} + +type preconfContract struct { + preconfABI abi.ABI + preconfContractAddr common.Address + client *ethclient.Client + owner common.Address + signer *ecdsa.PrivateKey + logger *slog.Logger +} + +func New( + owner common.Address, + preconfContractAddr common.Address, + preconfABI abi.ABI, + client *ethclient.Client, + signer *ecdsa.PrivateKey, + logger *slog.Logger, +) Interface { + return &preconfContract{ + preconfABI: preconfABI, + preconfContractAddr: preconfContractAddr, + client: client, + owner: owner, + signer: signer, + logger: logger, + } +} + +func (p *preconfContract) StoreCommitment( + ctx context.Context, + bid *big.Int, + blockNumber uint64, + txHash string, + commitmentHash string, + bidSignature []byte, + commitmentSignature []byte, +) error { + + callData, err := p.preconfABI.Pack( + "storeCommitment", + bid, + blockNumber, + txHash, + commitmentHash, + bidSignature, + commitmentSignature, + ) + if err != nil { + return err + } + + nonce, err := p.client.PendingNonceAt(ctx, p.owner) + if err != nil { + return err + } + + chainID, err := p.client.NetworkID(ctx) + if err != nil { + return err + } + + gasPrice, err := p.client.SuggestGasPrice(ctx) + if err != nil { + return err + } + + gasTipCap, err := p.client.SuggestGasTipCap(ctx) + if err != nil { + return err + } + + gasFeeCap := new(big.Int).Add(gasPrice, gasTipCap) + + txnData := types.NewTx(&types.DynamicFeeTx{ + ChainID: chainID, + To: &p.preconfContractAddr, + Nonce: nonce, + Data: callData, + Gas: uint64(gasPrice.Int64()), + GasFeeCap: gasFeeCap, + GasTipCap: gasTipCap, + }) + + signedTxn, err := types.SignTx( + txnData, + types.LatestSignerForChainID(chainID), + p.signer, + ) + if err != nil { + return err + } + + err = p.client.SendTransaction(ctx, signedTxn) + if err != nil { + return err + } + + receipt, err := bind.WaitMined(ctx, p.client, txnData) + if err != nil { + return err + } + + if receipt.Status != types.ReceiptStatusSuccessful { + return err + } + + return nil +} diff --git a/pkg/node/node.go b/pkg/node/node.go index a68cc836..cd94a52a 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -7,14 +7,19 @@ import ( "fmt" "io" "log/slog" + "math/big" "net" "net/http" + "strings" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" providerapiv1 "github.com/primevprotocol/mev-commit/gen/go/rpc/providerapi/v1" userapiv1 "github.com/primevprotocol/mev-commit/gen/go/rpc/userapi/v1" "github.com/primevprotocol/mev-commit/pkg/apiserver" + preconfcontract "github.com/primevprotocol/mev-commit/pkg/contracts/preconf" "github.com/primevprotocol/mev-commit/pkg/debugapi" "github.com/primevprotocol/mev-commit/pkg/discovery" "github.com/primevprotocol/mev-commit/pkg/p2p" @@ -30,17 +35,21 @@ import ( "google.golang.org/grpc/credentials/insecure" ) +var preconfContractABI = "" + type Options struct { - Version string - PrivKey *ecdsa.PrivateKey - Secret string - PeerType string - Logger *slog.Logger - P2PPort int - HTTPPort int - RPCPort int - Bootnodes []string - ExposeProviderAPI bool + Version string + PrivKey *ecdsa.PrivateKey + Secret string + PeerType string + Logger *slog.Logger + P2PPort int + HTTPPort int + RPCPort int + Bootnodes []string + ExposeProviderAPI bool + PreconfContract string + PreconfContractRPC string } type Node struct { @@ -103,7 +112,11 @@ func NewNode(opts *Options) (*Node, error) { grpcServer := grpc.NewServer() preconfSigner := preconfsigner.NewSigner(opts.PrivKey) - var bidProcessor preconfirmation.BidProcessor = noOpBidProcessor{} + + var ( + bidProcessor preconfirmation.BidProcessor = noOpBidProcessor{} + commitmentDA preconfcontract.Interface = noOpCommitmentDA{} + ) switch opts.PeerType { case p2p.PeerTypeProvider.String(): @@ -112,13 +125,35 @@ func NewNode(opts *Options) (*Node, error) { providerapiv1.RegisterProviderServer(grpcServer, providerAPI) bidProcessor = providerAPI } - // TODO(@ckartik): Update noOpBidProcessor to be selected as default in a flag paramater. + + preconfContractABI, err := abi.JSON(strings.NewReader(preconfContractABI)) + if err != nil { + return nil, err + } + + preconfContractAddr := common.HexToAddress(opts.PreconfContract) + + preconfRPC, err := ethclient.Dial(opts.PreconfContractRPC) + if err != nil { + return nil, err + } + + commitmentDA = preconfcontract.New( + libp2p.GetEthAddressFromPubKey(&(opts.PrivKey.PublicKey)), + preconfContractAddr, + preconfContractABI, + preconfRPC, + opts.PrivKey, + opts.Logger.With("component", "preconfcontract"), + ) + preconfProto := preconfirmation.New( topo, p2pSvc, preconfSigner, noOpUserStore{}, bidProcessor, + commitmentDA, opts.Logger.With("component", "preconfirmation_protocol"), ) // Only register handler for provider @@ -131,6 +166,7 @@ func NewNode(opts *Options) (*Node, error) { preconfSigner, noOpUserStore{}, bidProcessor, + commitmentDA, opts.Logger.With("component", "preconfirmation_protocol"), ) @@ -244,3 +280,17 @@ func (noOpBidProcessor) ProcessBid( return statusC, nil } + +type noOpCommitmentDA struct{} + +func (noOpCommitmentDA) StoreCommitment( + _ context.Context, + _ *big.Int, + _ uint64, + _ string, + _ string, + _ []byte, + _ []byte, +) error { + return nil +} diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index f12b2ea9..9b073a30 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -2,6 +2,7 @@ package preconfirmation import ( "context" + "encoding/hex" "errors" "log/slog" "math/big" @@ -10,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/common" providerapiv1 "github.com/primevprotocol/mev-commit/gen/go/rpc/providerapi/v1" + preconfcontract "github.com/primevprotocol/mev-commit/pkg/contracts/preconf" "github.com/primevprotocol/mev-commit/pkg/p2p" "github.com/primevprotocol/mev-commit/pkg/p2p/msgpack" "github.com/primevprotocol/mev-commit/pkg/signer/preconfsigner" @@ -22,12 +24,13 @@ const ( ) type Preconfirmation struct { - signer preconfsigner.Signer - topo Topology - streamer p2p.Streamer - us UserStore - processer BidProcessor - logger *slog.Logger + signer preconfsigner.Signer + topo Topology + streamer p2p.Streamer + us UserStore + processer BidProcessor + commitmentDA preconfcontract.Interface + logger *slog.Logger } type Topology interface { @@ -48,15 +51,17 @@ func New( signer preconfsigner.Signer, us UserStore, processor BidProcessor, + commitmentDA preconfcontract.Interface, logger *slog.Logger, ) *Preconfirmation { return &Preconfirmation{ - topo: topo, - streamer: streamer, - signer: signer, - us: us, - processer: processor, - logger: logger, + topo: topo, + streamer: streamer, + signer: signer, + us: us, + processer: processor, + commitmentDA: commitmentDA, + logger: logger, } } @@ -201,6 +206,18 @@ func (p *Preconfirmation) handleBid( if err != nil { return err } + err = p.commitmentDA.StoreCommitment( + ctx, + preConfirmation.Bid.BidAmt, + uint64(preConfirmation.Bid.BlockNumber.Int64()), + preConfirmation.Bid.TxHash, + hex.EncodeToString(preConfirmation.Digest), + preConfirmation.Bid.Signature, + preConfirmation.Signature, + ) + if err != nil { + return err + } return w.WriteMsg(ctx, preConfirmation) } } diff --git a/pkg/preconfirmation/preconfirmation_test.go b/pkg/preconfirmation/preconfirmation_test.go index 9655d6d2..fec57787 100644 --- a/pkg/preconfirmation/preconfirmation_test.go +++ b/pkg/preconfirmation/preconfirmation_test.go @@ -66,6 +66,20 @@ func (t *testProcessor) ProcessBid( return statusC, nil } +type testCommitmentDA struct{} + +func (t *testCommitmentDA) StoreCommitment( + _ context.Context, + _ *big.Int, + _ uint64, + _ string, + _ string, + _ []byte, + _ []byte, +) error { + return nil +} + func newTestLogger(t *testing.T, w io.Writer) *slog.Logger { t.Helper() @@ -118,7 +132,15 @@ func TestPreconfBidSubmission(t *testing.T) { preConfirmationSigner: common.HexToAddress("0x2"), } - p := preconfirmation.New(topo, svc, signer, us, proc, newTestLogger(t, os.Stdout)) + p := preconfirmation.New( + topo, + svc, + signer, + us, + proc, + &testCommitmentDA{}, + newTestLogger(t, os.Stdout), + ) svc.SetPeerHandler(server, p.Protocol()) From ea8b9e642edcdd1cb78b87a07752548d4dbe54d3 Mon Sep 17 00:00:00 2001 From: alok Date: Fri, 10 Nov 2023 18:16:22 +0530 Subject: [PATCH 2/4] feat: add commitment contract --- pkg/node/node.go | 2 +- pkg/node/preconfabi.go | 865 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 866 insertions(+), 1 deletion(-) create mode 100644 pkg/node/preconfabi.go diff --git a/pkg/node/node.go b/pkg/node/node.go index cd94a52a..8578ac36 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -35,7 +35,7 @@ import ( "google.golang.org/grpc/credentials/insecure" ) -var preconfContractABI = "" +var preconfContractABI = preConfJson type Options struct { Version string diff --git a/pkg/node/preconfabi.go b/pkg/node/preconfabi.go new file mode 100644 index 00000000..e1977bb9 --- /dev/null +++ b/pkg/node/preconfabi.go @@ -0,0 +1,865 @@ +package node + +var preConfJson = ` +[ + { + "inputs": [ + { + "internalType": "address", + "name": "_providerRegistry", + "type": "address" + }, + { + "internalType": "address", + "name": "_userRegistry", + "type": "address" + }, + { + "internalType": "address", + "name": "_oracle", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "ECDSAInvalidSignature", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "ECDSAInvalidSignatureLength", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "ECDSAInvalidSignatureS", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "OwnableInvalidOwner", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "OwnableUnauthorizedAccount", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "signer", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "indexed": true, + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + } + ], + "name": "SignatureVerified", + "type": "event" + }, + { + "stateMutability": "payable", + "type": "fallback" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR_BID", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR_PRECONF", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EIP712_COMMITMENT_TYPEHASH", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "EIP712_MESSAGE_TYPEHASH", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "_bytes", + "type": "bytes" + } + ], + "name": "_bytesToHexString", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "blockCommitments", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "commitmentCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "commitments", + "outputs": [ + { + "internalType": "bool", + "name": "commitmentUsed", + "type": "bool" + }, + { + "internalType": "address", + "name": "bidder", + "type": "address" + }, + { + "internalType": "address", + "name": "commiter", + "type": "address" + }, + { + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "bidHash", + "type": "bytes32" + }, + { + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "string", + "name": "commitmentHash", + "type": "string" + }, + { + "internalType": "bytes", + "name": "bidSignature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "commitmentSignature", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "commitmentsCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_txnHash", + "type": "string" + }, + { + "internalType": "uint64", + "name": "_bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "_blockNumber", + "type": "uint64" + } + ], + "name": "getBidHash", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "commitmentHash", + "type": "bytes32" + } + ], + "name": "getCommitment", + "outputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "commitmentUsed", + "type": "bool" + }, + { + "internalType": "address", + "name": "bidder", + "type": "address" + }, + { + "internalType": "address", + "name": "commiter", + "type": "address" + }, + { + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "bidHash", + "type": "bytes32" + }, + { + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "string", + "name": "commitmentHash", + "type": "string" + }, + { + "internalType": "bytes", + "name": "bidSignature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "commitmentSignature", + "type": "bytes" + } + ], + "internalType": "struct PreConfCommitmentStore.PreConfCommitment", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "commitmentUsed", + "type": "bool" + }, + { + "internalType": "address", + "name": "bidder", + "type": "address" + }, + { + "internalType": "address", + "name": "commiter", + "type": "address" + }, + { + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "bidHash", + "type": "bytes32" + }, + { + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "string", + "name": "commitmentHash", + "type": "string" + }, + { + "internalType": "bytes", + "name": "bidSignature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "commitmentSignature", + "type": "bytes" + } + ], + "internalType": "struct PreConfCommitmentStore.PreConfCommitment", + "name": "commitment", + "type": "tuple" + } + ], + "name": "getCommitmentIndex", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "commiter", + "type": "address" + } + ], + "name": "getCommitmentsByCommitter", + "outputs": [ + { + "internalType": "bytes32[]", + "name": "", + "type": "bytes32[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_txnHash", + "type": "string" + }, + { + "internalType": "uint64", + "name": "_bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "_blockNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "_bidHash", + "type": "bytes32" + }, + { + "internalType": "string", + "name": "_bidSignature", + "type": "string" + } + ], + "name": "getPreConfHash", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "commitmentIndex", + "type": "bytes32" + } + ], + "name": "initateReward", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "commitmentIndex", + "type": "bytes32" + } + ], + "name": "initiateSlash", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "lastProcessedBlock", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "oracle", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "providerCommitments", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "providerRegistry", + "outputs": [ + { + "internalType": "contract IProviderRegistry", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + }, + { + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "string", + "name": "commitmentHash", + "type": "string" + }, + { + "internalType": "bytes", + "name": "bidSignature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "commitmentSignature", + "type": "bytes" + } + ], + "name": "storeCommitment", + "outputs": [ + { + "internalType": "bytes32", + "name": "commitmentIndex", + "type": "bytes32" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOracle", + "type": "address" + } + ], + "name": "updateOracle", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newProviderRegistry", + "type": "address" + } + ], + "name": "updateProviderRegistry", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newUserRegistry", + "type": "address" + } + ], + "name": "updateUserRegistry", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "userRegistry", + "outputs": [ + { + "internalType": "contract IUserRegistry", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + }, + { + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "bytes", + "name": "bidSignature", + "type": "bytes" + } + ], + "name": "verifyBid", + "outputs": [ + { + "internalType": "bytes32", + "name": "messageDigest", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "recoveredAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "stake", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "bidHash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "bidSignature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "commitmentSignature", + "type": "bytes" + } + ], + "name": "verifyPreConfCommitment", + "outputs": [ + { + "internalType": "bytes32", + "name": "preConfHash", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "commiterAddress", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } +] +` From 13dad4ba9fafe4576068b648e85b1eef98b5958c Mon Sep 17 00:00:00 2001 From: alok Date: Mon, 13 Nov 2023 19:18:35 +0530 Subject: [PATCH 3/4] feat: add registry contract --- cmd/main.go | 48 +- config/provider.yml | 3 + gen/go/rpc/providerapi/v1/providerapi.pb.go | 236 ++++++++-- .../rpc/providerapi/v1/providerapi.pb.gw.go | 172 +++++++ .../rpc/providerapi/v1/providerapi_grpc.pb.go | 89 +++- .../providerapi/v1/providerapi.swagger.yaml | 44 ++ pkg/contracts/preconf/preconf.go | 26 +- pkg/contracts/registry/registry.go | 155 +++++++ pkg/node/node.go | 68 ++- pkg/node/preconfabi.go | 438 ++++++++++++++++++ pkg/preconfirmation/preconfirmation.go | 2 +- pkg/rpc/provider/service.go | 49 +- rpc/providerapi/v1/providerapi.proto | 35 ++ 13 files changed, 1263 insertions(+), 102 deletions(-) create mode 100644 pkg/contracts/registry/registry.go diff --git a/cmd/main.go b/cmd/main.go index 8a9af3cf..86e287cc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -90,18 +90,19 @@ func createKey(c *cli.Context) error { } type config struct { - PrivKeyFile string `yaml:"priv_key_file" json:"priv_key_file"` - Secret string `yaml:"secret" json:"secret"` - PeerType string `yaml:"peer_type" json:"peer_type"` - P2PPort int `yaml:"p2p_port" json:"p2p_port"` - HTTPPort int `yaml:"http_port" json:"http_port"` - RPCPort int `yaml:"rpc_port" json:"rpc_port"` - LogFmt string `yaml:"log_fmt" json:"log_fmt"` - LogLevel string `yaml:"log_level" json:"log_level"` - Bootnodes []string `yaml:"bootnodes" json:"bootnodes"` - ExposeProviderAPI bool `yaml:"expose_provider_api" json:"expose_provider_api"` - PreconfContract string `yaml:"preconf_contract" json:"preconf_contract"` - PreconfContractRPC string `yaml:"preconf_contract_rpc" json:"preconf_contract_rpc"` + PrivKeyFile string `yaml:"priv_key_file" json:"priv_key_file"` + Secret string `yaml:"secret" json:"secret"` + PeerType string `yaml:"peer_type" json:"peer_type"` + P2PPort int `yaml:"p2p_port" json:"p2p_port"` + HTTPPort int `yaml:"http_port" json:"http_port"` + RPCPort int `yaml:"rpc_port" json:"rpc_port"` + LogFmt string `yaml:"log_fmt" json:"log_fmt"` + LogLevel string `yaml:"log_level" json:"log_level"` + Bootnodes []string `yaml:"bootnodes" json:"bootnodes"` + ExposeProviderAPI bool `yaml:"expose_provider_api" json:"expose_provider_api"` + PreconfContract string `yaml:"preconf_contract" json:"preconf_contract"` + RegistryContract string `yaml:"registry_contract" json:"registry_contract"` + RPCEndpoint string `yaml:"rpc_endpoint" json:"rpc_endpoint"` } func checkConfig(cfg *config) error { @@ -179,17 +180,18 @@ func start(c *cli.Context) error { } nd, err := node.NewNode(&node.Options{ - PrivKey: privKey, - Secret: cfg.Secret, - PeerType: cfg.PeerType, - P2PPort: cfg.P2PPort, - HTTPPort: cfg.HTTPPort, - RPCPort: cfg.RPCPort, - Logger: logger, - Bootnodes: cfg.Bootnodes, - ExposeProviderAPI: cfg.ExposeProviderAPI, - PreconfContract: cfg.PreconfContract, - PreconfContractRPC: cfg.PreconfContractRPC, + PrivKey: privKey, + Secret: cfg.Secret, + PeerType: cfg.PeerType, + P2PPort: cfg.P2PPort, + HTTPPort: cfg.HTTPPort, + RPCPort: cfg.RPCPort, + Logger: logger, + Bootnodes: cfg.Bootnodes, + ExposeProviderAPI: cfg.ExposeProviderAPI, + PreconfContract: cfg.PreconfContract, + RegistryContract: cfg.RegistryContract, + RPCEndpoint: cfg.RPCEndpoint, }) if err != nil { return fmt.Errorf("failed starting node: %w", err) diff --git a/config/provider.yml b/config/provider.yml index 60047dc8..b65c448e 100644 --- a/config/provider.yml +++ b/config/provider.yml @@ -7,5 +7,8 @@ secret: hello log_fmt: text log_level: debug expose_provider_api: true +preconf_contract: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 +registry_contract: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 +rpc_endpoint: http://34.215.163.180:8545 bootnodes: - /ip4//tcp/13522/p2p/ diff --git a/gen/go/rpc/providerapi/v1/providerapi.pb.go b/gen/go/rpc/providerapi/v1/providerapi.pb.go index d6af000a..8c746ab2 100644 --- a/gen/go/rpc/providerapi/v1/providerapi.pb.go +++ b/gen/go/rpc/providerapi/v1/providerapi.pb.go @@ -68,7 +68,101 @@ func (x BidResponse_Status) Number() protoreflect.EnumNumber { // Deprecated: Use BidResponse_Status.Descriptor instead. func (BidResponse_Status) EnumDescriptor() ([]byte, []int) { - return file_rpc_providerapi_v1_providerapi_proto_rawDescGZIP(), []int{2, 0} + return file_rpc_providerapi_v1_providerapi_proto_rawDescGZIP(), []int{4, 0} +} + +type StakeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Amount int64 `protobuf:"varint,1,opt,name=amount,proto3" json:"amount,omitempty"` +} + +func (x *StakeRequest) Reset() { + *x = StakeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StakeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StakeRequest) ProtoMessage() {} + +func (x *StakeRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StakeRequest.ProtoReflect.Descriptor instead. +func (*StakeRequest) Descriptor() ([]byte, []int) { + return file_rpc_providerapi_v1_providerapi_proto_rawDescGZIP(), []int{0} +} + +func (x *StakeRequest) GetAmount() int64 { + if x != nil { + return x.Amount + } + return 0 +} + +type StakeResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Amount int64 `protobuf:"varint,1,opt,name=amount,proto3" json:"amount,omitempty"` +} + +func (x *StakeResponse) Reset() { + *x = StakeResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StakeResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StakeResponse) ProtoMessage() {} + +func (x *StakeResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StakeResponse.ProtoReflect.Descriptor instead. +func (*StakeResponse) Descriptor() ([]byte, []int) { + return file_rpc_providerapi_v1_providerapi_proto_rawDescGZIP(), []int{1} +} + +func (x *StakeResponse) GetAmount() int64 { + if x != nil { + return x.Amount + } + return 0 } type EmptyMessage struct { @@ -80,7 +174,7 @@ type EmptyMessage struct { func (x *EmptyMessage) Reset() { *x = EmptyMessage{} if protoimpl.UnsafeEnabled { - mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[0] + mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -93,7 +187,7 @@ func (x *EmptyMessage) String() string { func (*EmptyMessage) ProtoMessage() {} func (x *EmptyMessage) ProtoReflect() protoreflect.Message { - mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[0] + mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -106,7 +200,7 @@ func (x *EmptyMessage) ProtoReflect() protoreflect.Message { // Deprecated: Use EmptyMessage.ProtoReflect.Descriptor instead. func (*EmptyMessage) Descriptor() ([]byte, []int) { - return file_rpc_providerapi_v1_providerapi_proto_rawDescGZIP(), []int{0} + return file_rpc_providerapi_v1_providerapi_proto_rawDescGZIP(), []int{2} } type Bid struct { @@ -123,7 +217,7 @@ type Bid struct { func (x *Bid) Reset() { *x = Bid{} if protoimpl.UnsafeEnabled { - mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[1] + mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -136,7 +230,7 @@ func (x *Bid) String() string { func (*Bid) ProtoMessage() {} func (x *Bid) ProtoReflect() protoreflect.Message { - mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[1] + mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -149,7 +243,7 @@ func (x *Bid) ProtoReflect() protoreflect.Message { // Deprecated: Use Bid.ProtoReflect.Descriptor instead. func (*Bid) Descriptor() ([]byte, []int) { - return file_rpc_providerapi_v1_providerapi_proto_rawDescGZIP(), []int{1} + return file_rpc_providerapi_v1_providerapi_proto_rawDescGZIP(), []int{3} } func (x *Bid) GetTxHash() string { @@ -192,7 +286,7 @@ type BidResponse struct { func (x *BidResponse) Reset() { *x = BidResponse{} if protoimpl.UnsafeEnabled { - mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[2] + mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -205,7 +299,7 @@ func (x *BidResponse) String() string { func (*BidResponse) ProtoMessage() {} func (x *BidResponse) ProtoReflect() protoreflect.Message { - mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[2] + mi := &file_rpc_providerapi_v1_providerapi_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -218,7 +312,7 @@ func (x *BidResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use BidResponse.ProtoReflect.Descriptor instead. func (*BidResponse) Descriptor() ([]byte, []int) { - return file_rpc_providerapi_v1_providerapi_proto_rawDescGZIP(), []int{2} + return file_rpc_providerapi_v1_providerapi_proto_rawDescGZIP(), []int{4} } func (x *BidResponse) GetBidDigest() []byte { @@ -246,7 +340,26 @@ var file_rpc_providerapi_v1_providerapi_proto_rawDesc = []byte{ 0x2f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x0e, 0x0a, 0x0c, 0x45, 0x6d, 0x70, 0x74, + 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x90, 0x01, 0x0a, 0x0c, 0x53, 0x74, 0x61, + 0x6b, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, + 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, + 0x74, 0x3a, 0x68, 0x92, 0x41, 0x65, 0x0a, 0x41, 0x2a, 0x0d, 0x53, 0x74, 0x61, 0x6b, 0x65, 0x20, + 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x32, 0x28, 0x53, 0x74, 0x61, 0x6b, 0x65, 0x20, 0x70, + 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, + 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x20, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x79, + 0x2e, 0xd2, 0x01, 0x05, 0x73, 0x74, 0x61, 0x6b, 0x65, 0x32, 0x20, 0x7b, 0x22, 0x61, 0x6d, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x3a, 0x20, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x20, 0x7d, 0x22, 0x9a, 0x01, 0x0a, 0x0d, + 0x53, 0x74, 0x61, 0x6b, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, + 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x61, + 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x3a, 0x71, 0x92, 0x41, 0x6e, 0x0a, 0x4a, 0x2a, 0x0e, 0x53, 0x74, + 0x61, 0x6b, 0x65, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x38, 0x47, 0x65, + 0x74, 0x20, 0x73, 0x74, 0x61, 0x6b, 0x65, 0x64, 0x20, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x20, 0x69, 0x6e, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x20, 0x72, 0x65, 0x67, + 0x69, 0x73, 0x74, 0x72, 0x79, 0x2e, 0x32, 0x20, 0x7b, 0x22, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, + 0x22, 0x3a, 0x20, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x20, 0x7d, 0x22, 0x0e, 0x0a, 0x0c, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xb7, 0x06, 0x0a, 0x03, 0x42, 0x69, 0x64, 0x12, 0x8f, 0x01, 0x0a, 0x07, 0x74, 0x78, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x76, 0x92, 0x41, 0x73, 0x32, 0x5f, 0x48, 0x65, 0x78, 0x20, 0x73, 0x74, 0x72, @@ -331,7 +444,7 @@ var file_rpc_providerapi_v1_providerapi_proto_rawDesc = []byte{ 0x5a, 0x79, 0x67, 0x64, 0x78, 0x47, 0x73, 0x58, 0x38, 0x2b, 0x50, 0x33, 0x62, 0x79, 0x4d, 0x45, 0x41, 0x35, 0x69, 0x67, 0x3d, 0x3d, 0x22, 0x2c, 0x20, 0x22, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x3a, 0x20, 0x22, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x41, 0x43, 0x43, 0x45, 0x50, - 0x54, 0x45, 0x44, 0x22, 0x7d, 0x32, 0x81, 0x02, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, + 0x54, 0x45, 0x44, 0x22, 0x7d, 0x32, 0xf7, 0x03, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x6d, 0x0a, 0x0b, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x42, 0x69, 0x64, 0x73, 0x12, 0x20, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x4d, 0x65, 0x73, 0x73, @@ -347,20 +460,35 @@ var file_rpc_providerapi_v1_providerapi_proto_rawDesc = []byte{ 0x70, 0x74, 0x79, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x2b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x25, 0x3a, 0x01, 0x2a, 0x22, 0x20, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2f, 0x73, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, - 0x65, 0x64, 0x5f, 0x62, 0x69, 0x64, 0x73, 0x28, 0x01, 0x42, 0xc6, 0x01, 0x92, 0x41, 0x7c, 0x12, - 0x7a, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x20, 0x41, 0x50, 0x49, 0x2a, - 0x5d, 0x0a, 0x1b, 0x42, 0x75, 0x73, 0x69, 0x6e, 0x65, 0x73, 0x73, 0x20, 0x53, 0x6f, 0x75, 0x72, - 0x63, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x31, 0x2e, 0x31, 0x12, 0x3e, - 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x69, 0x6d, 0x65, 0x76, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, - 0x6c, 0x2f, 0x6d, 0x65, 0x76, 0x2d, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x2f, 0x62, 0x6c, 0x6f, - 0x62, 0x2f, 0x6d, 0x61, 0x69, 0x6e, 0x2f, 0x4c, 0x49, 0x43, 0x45, 0x4e, 0x53, 0x45, 0x32, 0x0b, - 0x31, 0x2e, 0x30, 0x2e, 0x30, 0x2d, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x5a, 0x45, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x69, 0x6d, 0x65, 0x76, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x6d, 0x65, 0x76, 0x2d, 0x63, 0x6f, 0x6d, 0x6d, 0x69, - 0x74, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x61, 0x70, - 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x61, 0x70, 0x69, - 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x64, 0x5f, 0x62, 0x69, 0x64, 0x73, 0x28, 0x01, 0x12, 0x82, 0x01, 0x0a, 0x0d, 0x52, 0x65, + 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x6b, 0x65, 0x12, 0x20, 0x2e, 0x72, 0x70, + 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, + 0x2e, 0x53, 0x74, 0x61, 0x6b, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, + 0x72, 0x70, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x61, 0x70, 0x69, 0x2e, + 0x76, 0x31, 0x2e, 0x53, 0x74, 0x61, 0x6b, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x2c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x22, 0x24, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x72, + 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, + 0x73, 0x74, 0x61, 0x6b, 0x65, 0x2f, 0x7b, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x7d, 0x12, 0x6f, + 0x0a, 0x08, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x6b, 0x65, 0x12, 0x20, 0x2e, 0x72, 0x70, 0x63, + 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x21, 0x2e, 0x72, + 0x70, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x61, 0x70, 0x69, 0x2e, 0x76, + 0x31, 0x2e, 0x53, 0x74, 0x61, 0x6b, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x1e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x18, 0x12, 0x16, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x72, 0x6f, + 0x76, 0x69, 0x64, 0x65, 0x72, 0x2f, 0x67, 0x65, 0x74, 0x5f, 0x73, 0x74, 0x61, 0x6b, 0x65, 0x42, + 0xc6, 0x01, 0x92, 0x41, 0x7c, 0x12, 0x7a, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, + 0x72, 0x20, 0x41, 0x50, 0x49, 0x2a, 0x5d, 0x0a, 0x1b, 0x42, 0x75, 0x73, 0x69, 0x6e, 0x65, 0x73, + 0x73, 0x20, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, + 0x20, 0x31, 0x2e, 0x31, 0x12, 0x3e, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x69, 0x6d, 0x65, 0x76, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x6d, 0x65, 0x76, 0x2d, 0x63, 0x6f, 0x6d, 0x6d, + 0x69, 0x74, 0x2f, 0x62, 0x6c, 0x6f, 0x62, 0x2f, 0x6d, 0x61, 0x69, 0x6e, 0x2f, 0x4c, 0x49, 0x43, + 0x45, 0x4e, 0x53, 0x45, 0x32, 0x0b, 0x31, 0x2e, 0x30, 0x2e, 0x30, 0x2d, 0x61, 0x6c, 0x70, 0x68, + 0x61, 0x5a, 0x45, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, + 0x69, 0x6d, 0x65, 0x76, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x6d, 0x65, 0x76, + 0x2d, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x76, + 0x69, 0x64, 0x65, 0x72, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x72, 0x6f, 0x76, 0x69, + 0x64, 0x65, 0x72, 0x61, 0x70, 0x69, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -376,21 +504,27 @@ func file_rpc_providerapi_v1_providerapi_proto_rawDescGZIP() []byte { } var file_rpc_providerapi_v1_providerapi_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_rpc_providerapi_v1_providerapi_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_rpc_providerapi_v1_providerapi_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_rpc_providerapi_v1_providerapi_proto_goTypes = []interface{}{ (BidResponse_Status)(0), // 0: rpc.providerapi.v1.BidResponse.Status - (*EmptyMessage)(nil), // 1: rpc.providerapi.v1.EmptyMessage - (*Bid)(nil), // 2: rpc.providerapi.v1.Bid - (*BidResponse)(nil), // 3: rpc.providerapi.v1.BidResponse + (*StakeRequest)(nil), // 1: rpc.providerapi.v1.StakeRequest + (*StakeResponse)(nil), // 2: rpc.providerapi.v1.StakeResponse + (*EmptyMessage)(nil), // 3: rpc.providerapi.v1.EmptyMessage + (*Bid)(nil), // 4: rpc.providerapi.v1.Bid + (*BidResponse)(nil), // 5: rpc.providerapi.v1.BidResponse } var file_rpc_providerapi_v1_providerapi_proto_depIdxs = []int32{ 0, // 0: rpc.providerapi.v1.BidResponse.status:type_name -> rpc.providerapi.v1.BidResponse.Status - 1, // 1: rpc.providerapi.v1.Provider.ReceiveBids:input_type -> rpc.providerapi.v1.EmptyMessage - 3, // 2: rpc.providerapi.v1.Provider.SendProcessedBids:input_type -> rpc.providerapi.v1.BidResponse - 2, // 3: rpc.providerapi.v1.Provider.ReceiveBids:output_type -> rpc.providerapi.v1.Bid - 1, // 4: rpc.providerapi.v1.Provider.SendProcessedBids:output_type -> rpc.providerapi.v1.EmptyMessage - 3, // [3:5] is the sub-list for method output_type - 1, // [1:3] is the sub-list for method input_type + 3, // 1: rpc.providerapi.v1.Provider.ReceiveBids:input_type -> rpc.providerapi.v1.EmptyMessage + 5, // 2: rpc.providerapi.v1.Provider.SendProcessedBids:input_type -> rpc.providerapi.v1.BidResponse + 1, // 3: rpc.providerapi.v1.Provider.RegisterStake:input_type -> rpc.providerapi.v1.StakeRequest + 3, // 4: rpc.providerapi.v1.Provider.GetStake:input_type -> rpc.providerapi.v1.EmptyMessage + 4, // 5: rpc.providerapi.v1.Provider.ReceiveBids:output_type -> rpc.providerapi.v1.Bid + 3, // 6: rpc.providerapi.v1.Provider.SendProcessedBids:output_type -> rpc.providerapi.v1.EmptyMessage + 2, // 7: rpc.providerapi.v1.Provider.RegisterStake:output_type -> rpc.providerapi.v1.StakeResponse + 2, // 8: rpc.providerapi.v1.Provider.GetStake:output_type -> rpc.providerapi.v1.StakeResponse + 5, // [5:9] is the sub-list for method output_type + 1, // [1:5] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name 1, // [1:1] is the sub-list for extension extendee 0, // [0:1] is the sub-list for field type_name @@ -403,7 +537,7 @@ func file_rpc_providerapi_v1_providerapi_proto_init() { } if !protoimpl.UnsafeEnabled { file_rpc_providerapi_v1_providerapi_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EmptyMessage); i { + switch v := v.(*StakeRequest); i { case 0: return &v.state case 1: @@ -415,7 +549,7 @@ func file_rpc_providerapi_v1_providerapi_proto_init() { } } file_rpc_providerapi_v1_providerapi_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Bid); i { + switch v := v.(*StakeResponse); i { case 0: return &v.state case 1: @@ -427,6 +561,30 @@ func file_rpc_providerapi_v1_providerapi_proto_init() { } } file_rpc_providerapi_v1_providerapi_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EmptyMessage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_rpc_providerapi_v1_providerapi_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Bid); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_rpc_providerapi_v1_providerapi_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*BidResponse); i { case 0: return &v.state @@ -445,7 +603,7 @@ func file_rpc_providerapi_v1_providerapi_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_rpc_providerapi_v1_providerapi_proto_rawDesc, NumEnums: 1, - NumMessages: 3, + NumMessages: 5, NumExtensions: 0, NumServices: 1, }, diff --git a/gen/go/rpc/providerapi/v1/providerapi.pb.gw.go b/gen/go/rpc/providerapi/v1/providerapi.pb.gw.go index 145224ca..6dee02a8 100644 --- a/gen/go/rpc/providerapi/v1/providerapi.pb.gw.go +++ b/gen/go/rpc/providerapi/v1/providerapi.pb.gw.go @@ -92,6 +92,76 @@ func request_Provider_SendProcessedBids_0(ctx context.Context, marshaler runtime } +func request_Provider_RegisterStake_0(ctx context.Context, marshaler runtime.Marshaler, client ProviderClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq StakeRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["amount"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "amount") + } + + protoReq.Amount, err = runtime.Int64(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "amount", err) + } + + msg, err := client.RegisterStake(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Provider_RegisterStake_0(ctx context.Context, marshaler runtime.Marshaler, server ProviderServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq StakeRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["amount"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "amount") + } + + protoReq.Amount, err = runtime.Int64(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "amount", err) + } + + msg, err := server.RegisterStake(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Provider_GetStake_0(ctx context.Context, marshaler runtime.Marshaler, client ProviderClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq EmptyMessage + var metadata runtime.ServerMetadata + + msg, err := client.GetStake(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Provider_GetStake_0(ctx context.Context, marshaler runtime.Marshaler, server ProviderServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq EmptyMessage + var metadata runtime.ServerMetadata + + msg, err := server.GetStake(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterProviderHandlerServer registers the http handlers for service Provider to "mux". // UnaryRPC :call ProviderServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -112,6 +182,56 @@ func RegisterProviderHandlerServer(ctx context.Context, mux *runtime.ServeMux, s return }) + mux.Handle("POST", pattern_Provider_RegisterStake_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/rpc.providerapi.v1.Provider/RegisterStake", runtime.WithHTTPPathPattern("/v1/provider/register_stake/{amount}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Provider_RegisterStake_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Provider_RegisterStake_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Provider_GetStake_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/rpc.providerapi.v1.Provider/GetStake", runtime.WithHTTPPathPattern("/v1/provider/get_stake")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Provider_GetStake_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Provider_GetStake_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -197,6 +317,50 @@ func RegisterProviderHandlerClient(ctx context.Context, mux *runtime.ServeMux, c }) + mux.Handle("POST", pattern_Provider_RegisterStake_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/rpc.providerapi.v1.Provider/RegisterStake", runtime.WithHTTPPathPattern("/v1/provider/register_stake/{amount}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Provider_RegisterStake_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Provider_RegisterStake_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Provider_GetStake_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/rpc.providerapi.v1.Provider/GetStake", runtime.WithHTTPPathPattern("/v1/provider/get_stake")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Provider_GetStake_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Provider_GetStake_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -204,10 +368,18 @@ var ( pattern_Provider_ReceiveBids_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "provider", "receive_bids"}, "")) pattern_Provider_SendProcessedBids_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "provider", "send_processed_bids"}, "")) + + pattern_Provider_RegisterStake_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "provider", "register_stake", "amount"}, "")) + + pattern_Provider_GetStake_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "provider", "get_stake"}, "")) ) var ( forward_Provider_ReceiveBids_0 = runtime.ForwardResponseStream forward_Provider_SendProcessedBids_0 = runtime.ForwardResponseMessage + + forward_Provider_RegisterStake_0 = runtime.ForwardResponseMessage + + forward_Provider_GetStake_0 = runtime.ForwardResponseMessage ) diff --git a/gen/go/rpc/providerapi/v1/providerapi_grpc.pb.go b/gen/go/rpc/providerapi/v1/providerapi_grpc.pb.go index fdbac233..300b2333 100644 --- a/gen/go/rpc/providerapi/v1/providerapi_grpc.pb.go +++ b/gen/go/rpc/providerapi/v1/providerapi_grpc.pb.go @@ -21,6 +21,8 @@ const _ = grpc.SupportPackageIsVersion7 const ( Provider_ReceiveBids_FullMethodName = "/rpc.providerapi.v1.Provider/ReceiveBids" Provider_SendProcessedBids_FullMethodName = "/rpc.providerapi.v1.Provider/SendProcessedBids" + Provider_RegisterStake_FullMethodName = "/rpc.providerapi.v1.Provider/RegisterStake" + Provider_GetStake_FullMethodName = "/rpc.providerapi.v1.Provider/GetStake" ) // ProviderClient is the client API for Provider service. @@ -37,6 +39,14 @@ type ProviderClient interface { // SendProcessedBids is called by the provider to send processed bids to the mev-commit node. // The provider will stream processed bids to the mev-commit node. SendProcessedBids(ctx context.Context, opts ...grpc.CallOption) (Provider_SendProcessedBidsClient, error) + // RegisterStake + // + // RegisterStake is called by the provider to register its stake in the provider registry. + RegisterStake(ctx context.Context, in *StakeRequest, opts ...grpc.CallOption) (*StakeResponse, error) + // GetStake + // + // GetStake is called by the provider to get its stake in the provider registry. + GetStake(ctx context.Context, in *EmptyMessage, opts ...grpc.CallOption) (*StakeResponse, error) } type providerClient struct { @@ -113,6 +123,24 @@ func (x *providerSendProcessedBidsClient) CloseAndRecv() (*EmptyMessage, error) return m, nil } +func (c *providerClient) RegisterStake(ctx context.Context, in *StakeRequest, opts ...grpc.CallOption) (*StakeResponse, error) { + out := new(StakeResponse) + err := c.cc.Invoke(ctx, Provider_RegisterStake_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *providerClient) GetStake(ctx context.Context, in *EmptyMessage, opts ...grpc.CallOption) (*StakeResponse, error) { + out := new(StakeResponse) + err := c.cc.Invoke(ctx, Provider_GetStake_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // ProviderServer is the server API for Provider service. // All implementations must embed UnimplementedProviderServer // for forward compatibility @@ -127,6 +155,14 @@ type ProviderServer interface { // SendProcessedBids is called by the provider to send processed bids to the mev-commit node. // The provider will stream processed bids to the mev-commit node. SendProcessedBids(Provider_SendProcessedBidsServer) error + // RegisterStake + // + // RegisterStake is called by the provider to register its stake in the provider registry. + RegisterStake(context.Context, *StakeRequest) (*StakeResponse, error) + // GetStake + // + // GetStake is called by the provider to get its stake in the provider registry. + GetStake(context.Context, *EmptyMessage) (*StakeResponse, error) mustEmbedUnimplementedProviderServer() } @@ -140,6 +176,12 @@ func (UnimplementedProviderServer) ReceiveBids(*EmptyMessage, Provider_ReceiveBi func (UnimplementedProviderServer) SendProcessedBids(Provider_SendProcessedBidsServer) error { return status.Errorf(codes.Unimplemented, "method SendProcessedBids not implemented") } +func (UnimplementedProviderServer) RegisterStake(context.Context, *StakeRequest) (*StakeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterStake not implemented") +} +func (UnimplementedProviderServer) GetStake(context.Context, *EmptyMessage) (*StakeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetStake not implemented") +} func (UnimplementedProviderServer) mustEmbedUnimplementedProviderServer() {} // UnsafeProviderServer may be embedded to opt out of forward compatibility for this service. @@ -200,13 +242,58 @@ func (x *providerSendProcessedBidsServer) Recv() (*BidResponse, error) { return m, nil } +func _Provider_RegisterStake_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StakeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProviderServer).RegisterStake(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Provider_RegisterStake_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProviderServer).RegisterStake(ctx, req.(*StakeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Provider_GetStake_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmptyMessage) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProviderServer).GetStake(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Provider_GetStake_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProviderServer).GetStake(ctx, req.(*EmptyMessage)) + } + return interceptor(ctx, in, info, handler) +} + // Provider_ServiceDesc is the grpc.ServiceDesc for Provider service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) var Provider_ServiceDesc = grpc.ServiceDesc{ ServiceName: "rpc.providerapi.v1.Provider", HandlerType: (*ProviderServer)(nil), - Methods: []grpc.MethodDesc{}, + Methods: []grpc.MethodDesc{ + { + MethodName: "RegisterStake", + Handler: _Provider_RegisterStake_Handler, + }, + { + MethodName: "GetStake", + Handler: _Provider_GetStake_Handler, + }, + }, Streams: []grpc.StreamDesc{ { StreamName: "ReceiveBids", diff --git a/gen/openapi/rpc/providerapi/v1/providerapi.swagger.yaml b/gen/openapi/rpc/providerapi/v1/providerapi.swagger.yaml index 51e56e8f..5b8da6c2 100644 --- a/gen/openapi/rpc/providerapi/v1/providerapi.swagger.yaml +++ b/gen/openapi/rpc/providerapi/v1/providerapi.swagger.yaml @@ -10,6 +10,20 @@ consumes: produces: - application/json paths: + /v1/provider/get_stake: + get: + summary: GetStake + description: GetStake is called by the provider to get its stake in the provider registry. + operationId: Provider_GetStake + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1StakeResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' /v1/provider/receive_bids: get: summary: ReceiveBids @@ -32,6 +46,26 @@ paths: description: An unexpected error response. schema: $ref: '#/definitions/googlerpcStatus' + /v1/provider/register_stake/{amount}: + post: + summary: RegisterStake + description: RegisterStake is called by the provider to register its stake in the provider registry. + operationId: Provider_RegisterStake + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1StakeResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: amount + in: path + required: true + type: string + format: int64 /v1/provider/send_processed_bids: post: summary: SendProcessedBids @@ -131,3 +165,13 @@ definitions: - STATUS_REJECTED v1EmptyMessage: type: object + v1StakeResponse: + type: object + example: + amount: 1e+18 + properties: + amount: + type: string + format: int64 + description: Get staked amount for provider in the provider registry. + title: Stake response diff --git a/pkg/contracts/preconf/preconf.go b/pkg/contracts/preconf/preconf.go index 6133c46c..fe7e81da 100644 --- a/pkg/contracts/preconf/preconf.go +++ b/pkg/contracts/preconf/preconf.go @@ -64,7 +64,7 @@ func (p *preconfContract) StoreCommitment( callData, err := p.preconfABI.Pack( "storeCommitment", - bid, + uint64(bid.Int64()), blockNumber, txHash, commitmentHash, @@ -72,6 +72,7 @@ func (p *preconfContract) StoreCommitment( commitmentSignature, ) if err != nil { + p.logger.Error("preconf contract storeCommitment pack error", "err", err) return err } @@ -85,15 +86,18 @@ func (p *preconfContract) StoreCommitment( return err } - gasPrice, err := p.client.SuggestGasPrice(ctx) - if err != nil { - return err - } + // gasPrice, err := p.client.SuggestGasPrice(ctx) + // if err != nil { + // return err + // } - gasTipCap, err := p.client.SuggestGasTipCap(ctx) - if err != nil { - return err - } + // gasTipCap, err := p.client.SuggestGasTipCap(ctx) + // if err != nil { + // return err + // } + + gasPrice := big.NewInt(50000) + gasTipCap := big.NewInt(50000) gasFeeCap := new(big.Int).Add(gasPrice, gasTipCap) @@ -121,6 +125,8 @@ func (p *preconfContract) StoreCommitment( return err } + p.logger.Info("sent txn", "txnData", txnData) + receipt, err := bind.WaitMined(ctx, p.client, txnData) if err != nil { return err @@ -130,5 +136,7 @@ func (p *preconfContract) StoreCommitment( return err } + p.logger.Info("preconf contract storeCommitment successful", "txnData", txnData) + return nil } diff --git a/pkg/contracts/registry/registry.go b/pkg/contracts/registry/registry.go new file mode 100644 index 00000000..e4aab584 --- /dev/null +++ b/pkg/contracts/registry/registry.go @@ -0,0 +1,155 @@ +package registrycontract + +import ( + "context" + "crypto/ecdsa" + "log/slog" + "math/big" + + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/ethclient" +) + +type Interface interface { + // RegisterProvider registers a provider with the registry contract. + RegisterProvider(ctx context.Context, amount *big.Int) error + // GetStake returns the stake of a provider. + GetStake(ctx context.Context) (*big.Int, error) +} + +type registryContract struct { + registryABI abi.ABI + registryContractAddr common.Address + client *ethclient.Client + owner common.Address + signer *ecdsa.PrivateKey + logger *slog.Logger +} + +func New( + owner common.Address, + registryContractAddr common.Address, + registryABI abi.ABI, + client *ethclient.Client, + signer *ecdsa.PrivateKey, + logger *slog.Logger, +) Interface { + return ®istryContract{ + registryABI: registryABI, + registryContractAddr: registryContractAddr, + client: client, + owner: owner, + signer: signer, + logger: logger, + } +} + +func (r *registryContract) RegisterProvider(ctx context.Context, amount *big.Int) error { + callData, err := r.registryABI.Pack("registerAndStake") + if err != nil { + return err + } + + nonce, err := r.client.PendingNonceAt(ctx, r.owner) + if err != nil { + return err + } + + chainID, err := r.client.NetworkID(ctx) + if err != nil { + return err + } + + // gasPrice, err := p.client.SuggestGasPrice(ctx) + // if err != nil { + // return err + // } + + // gasTipCap, err := p.client.SuggestGasTipCap(ctx) + // if err != nil { + // return err + // } + + gasPrice := big.NewInt(50000) + gasTipCap := big.NewInt(50000) + + gasFeeCap := new(big.Int).Add(gasPrice, gasTipCap) + + txnData := types.NewTx(&types.DynamicFeeTx{ + ChainID: chainID, + To: &r.registryContractAddr, + Nonce: nonce, + Data: callData, + Value: amount, + Gas: uint64(gasPrice.Int64()), + GasFeeCap: gasFeeCap, + GasTipCap: gasTipCap, + }) + + signedTxn, err := types.SignTx( + txnData, + types.LatestSignerForChainID(chainID), + r.signer, + ) + if err != nil { + return err + } + + err = r.client.SendTransaction(ctx, signedTxn) + if err != nil { + return err + } + + r.logger.Info("sent txn", "txnData", txnData) + + receipt, err := bind.WaitMined(ctx, r.client, txnData) + if err != nil { + return err + } + + if receipt.Status != types.ReceiptStatusSuccessful { + return err + } + + r.logger.Info("registry contract registerAndStake successful", "txnData", txnData) + + return nil +} + +func (r *registryContract) GetStake(ctx context.Context) (*big.Int, error) { + var address [32]byte + copy(address[:], r.owner.Bytes()) + + callData, err := r.registryABI.Pack("providerStakes", address) + if err != nil { + r.logger.Error("error packing call data", "error", err) + return nil, err + } + + msg := ethereum.CallMsg{ + From: r.owner, + To: &r.registryContractAddr, + Data: callData, + } + + result, err := r.client.CallContract(ctx, msg, nil) + if err != nil { + r.logger.Error("error calling contract", "error", err) + return nil, err + } + + var stake *big.Int + err = r.registryABI.UnpackIntoInterface(&stake, "providerStakes", result) + if err != nil { + r.logger.Error("error unpacking result", "error", err) + return nil, err + } + + r.logger.Info("got stake", "address", address, "stake", stake) + + return stake, nil +} diff --git a/pkg/node/node.go b/pkg/node/node.go index 8578ac36..914ccb35 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -20,6 +20,7 @@ import ( userapiv1 "github.com/primevprotocol/mev-commit/gen/go/rpc/userapi/v1" "github.com/primevprotocol/mev-commit/pkg/apiserver" preconfcontract "github.com/primevprotocol/mev-commit/pkg/contracts/preconf" + registrycontract "github.com/primevprotocol/mev-commit/pkg/contracts/registry" "github.com/primevprotocol/mev-commit/pkg/debugapi" "github.com/primevprotocol/mev-commit/pkg/discovery" "github.com/primevprotocol/mev-commit/pkg/p2p" @@ -35,21 +36,25 @@ import ( "google.golang.org/grpc/credentials/insecure" ) -var preconfContractABI = preConfJson +var ( + preconfContractABI = preConfJson + registryContractABI = providerRegistryJson +) type Options struct { - Version string - PrivKey *ecdsa.PrivateKey - Secret string - PeerType string - Logger *slog.Logger - P2PPort int - HTTPPort int - RPCPort int - Bootnodes []string - ExposeProviderAPI bool - PreconfContract string - PreconfContractRPC string + Version string + PrivKey *ecdsa.PrivateKey + Secret string + PeerType string + Logger *slog.Logger + P2PPort int + HTTPPort int + RPCPort int + Bootnodes []string + ExposeProviderAPI bool + PreconfContract string + RegistryContract string + RPCEndpoint string } type Node struct { @@ -120,8 +125,34 @@ func NewNode(opts *Options) (*Node, error) { switch opts.PeerType { case p2p.PeerTypeProvider.String(): + contractRPC, err := ethclient.Dial(opts.RPCEndpoint) + if err != nil { + return nil, err + } + ownerEthAddress := libp2p.GetEthAddressFromPubKey(&opts.PrivKey.PublicKey) + if opts.ExposeProviderAPI { - providerAPI := providerapi.NewService(opts.Logger.With("component", "providerapi")) + + registryContractABI, err := abi.JSON(strings.NewReader(registryContractABI)) + if err != nil { + return nil, err + } + + registryContractAddr := common.HexToAddress(opts.RegistryContract) + + providerRegistry := registrycontract.New( + ownerEthAddress, + registryContractAddr, + registryContractABI, + contractRPC, + opts.PrivKey, + opts.Logger.With("component", "registrycontract"), + ) + + providerAPI := providerapi.NewService( + opts.Logger.With("component", "providerapi"), + providerRegistry, + ) providerapiv1.RegisterProviderServer(grpcServer, providerAPI) bidProcessor = providerAPI } @@ -133,16 +164,11 @@ func NewNode(opts *Options) (*Node, error) { preconfContractAddr := common.HexToAddress(opts.PreconfContract) - preconfRPC, err := ethclient.Dial(opts.PreconfContractRPC) - if err != nil { - return nil, err - } - commitmentDA = preconfcontract.New( - libp2p.GetEthAddressFromPubKey(&(opts.PrivKey.PublicKey)), + ownerEthAddress, preconfContractAddr, preconfContractABI, - preconfRPC, + contractRPC, opts.PrivKey, opts.Logger.With("component", "preconfcontract"), ) diff --git a/pkg/node/preconfabi.go b/pkg/node/preconfabi.go index e1977bb9..6a64a588 100644 --- a/pkg/node/preconfabi.go +++ b/pkg/node/preconfabi.go @@ -863,3 +863,441 @@ var preConfJson = ` } ] ` +var providerRegistryJson = ` +[ + { + "inputs": [ + { + "internalType": "uint256", + "name": "_minStake", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_feeRecipient", + "type": "address" + }, + { + "internalType": "uint16", + "name": "_feePercent", + "type": "uint16" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "OwnableInvalidOwner", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "OwnableUnauthorizedAccount", + "type": "error" + }, + { + "inputs": [], + "name": "ReentrancyGuardReentrantCall", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "provider", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "FundsDeposited", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "provider", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "FundsRewarded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "provider", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "FundsSlashed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "provider", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "stakedAmount", + "type": "uint256" + } + ], + "name": "ProviderRegistered", + "type": "event" + }, + { + "stateMutability": "payable", + "type": "fallback" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "provider", + "type": "address" + } + ], + "name": "checkStake", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "depositFunds", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "feePercent", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "feeRecipient", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "feeRecipientAmount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "minStake", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "preConfirmationsContract", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "providerRegistered", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "providerStakes", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "registerAndStake", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "newFeePercent", + "type": "uint16" + } + ], + "name": "setNewFeePercent", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newFeeRecipient", + "type": "address" + } + ], + "name": "setNewFeeRecipient", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "contractAddress", + "type": "address" + } + ], + "name": "setPreconfirmationsContract", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + }, + { + "internalType": "address", + "name": "provider", + "type": "address" + }, + { + "internalType": "address payable", + "name": "user", + "type": "address" + } + ], + "name": "slash", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "userAmount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "withdrawFeeRecipientAmount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "provider", + "type": "address" + } + ], + "name": "withdrawStakedAmount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + } + ], + "name": "withdrawUserAmount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } +] +` diff --git a/pkg/preconfirmation/preconfirmation.go b/pkg/preconfirmation/preconfirmation.go index 9b073a30..9dc97691 100644 --- a/pkg/preconfirmation/preconfirmation.go +++ b/pkg/preconfirmation/preconfirmation.go @@ -187,7 +187,7 @@ func (p *Preconfirmation) handleBid( if p.us.CheckUserRegistred(ethAddress) { // try to enqueue for 5 seconds - ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + ctx, cancel := context.WithTimeout(ctx, 15*time.Second) defer cancel() statusC, err := p.processer.ProcessBid(ctx, bid) diff --git a/pkg/rpc/provider/service.go b/pkg/rpc/provider/service.go index 7f78b7f7..7bfe14e1 100644 --- a/pkg/rpc/provider/service.go +++ b/pkg/rpc/provider/service.go @@ -3,25 +3,29 @@ package providerapi import ( "context" "log/slog" + "math/big" "sync" providerapiv1 "github.com/primevprotocol/mev-commit/gen/go/rpc/providerapi/v1" + registrycontract "github.com/primevprotocol/mev-commit/pkg/contracts/registry" "github.com/primevprotocol/mev-commit/pkg/signer/preconfsigner" ) type Service struct { providerapiv1.UnimplementedProviderServer - receiver chan *providerapiv1.Bid - bidsInProcess map[string]func(providerapiv1.BidResponse_Status) - bidsMu sync.Mutex - logger *slog.Logger + receiver chan *providerapiv1.Bid + bidsInProcess map[string]func(providerapiv1.BidResponse_Status) + bidsMu sync.Mutex + logger *slog.Logger + registryContract registrycontract.Interface } -func NewService(logger *slog.Logger) *Service { +func NewService(logger *slog.Logger, registryContract registrycontract.Interface) *Service { return &Service{ - receiver: make(chan *providerapiv1.Bid), - bidsInProcess: make(map[string]func(providerapiv1.BidResponse_Status)), - logger: logger, + receiver: make(chan *providerapiv1.Bid), + bidsInProcess: make(map[string]func(providerapiv1.BidResponse_Status)), + registryContract: registryContract, + logger: logger, } } @@ -95,3 +99,32 @@ func (s *Service) SendProcessedBids(srv providerapiv1.Provider_SendProcessedBids } } } + +func (s *Service) RegisterStake( + ctx context.Context, + stake *providerapiv1.StakeRequest, +) (*providerapiv1.StakeResponse, error) { + err := s.registryContract.RegisterProvider(ctx, big.NewInt(stake.Amount)) + if err != nil { + return nil, err + } + + stakeAmount, err := s.registryContract.GetStake(ctx) + if err != nil { + return nil, err + } + + return &providerapiv1.StakeResponse{Amount: stakeAmount.Int64()}, nil +} + +func (s *Service) GetStake( + ctx context.Context, + _ *providerapiv1.EmptyMessage, +) (*providerapiv1.StakeResponse, error) { + stakeAmount, err := s.registryContract.GetStake(ctx) + if err != nil { + return nil, err + } + + return &providerapiv1.StakeResponse{Amount: stakeAmount.Int64()}, nil +} diff --git a/rpc/providerapi/v1/providerapi.proto b/rpc/providerapi/v1/providerapi.proto index 1e81b719..5e32dfd9 100644 --- a/rpc/providerapi/v1/providerapi.proto +++ b/rpc/providerapi/v1/providerapi.proto @@ -36,8 +36,43 @@ service Provider { body: "*" }; } + // RegisterStake + // + // RegisterStake is called by the provider to register its stake in the provider registry. + rpc RegisterStake(StakeRequest) returns (StakeResponse) { + option (google.api.http) = {post: "/v1/provider/register_stake/{amount}"}; + } + // GetStake + // + // GetStake is called by the provider to get its stake in the provider registry. + rpc GetStake(EmptyMessage) returns (StakeResponse) { + option (google.api.http) = {get: "/v1/provider/get_stake"}; + } } +message StakeRequest { + option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema) = { + json_schema: { + title: "Stake request" + description: "Stake provider in the provider registry." + required: ["stake"] + } + example: "{\"amount\": 1000000000000000000 }" + }; + int64 amount = 1; +}; + +message StakeResponse { + option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema) = { + json_schema: { + title: "Stake response" + description: "Get staked amount for provider in the provider registry." + } + example: "{\"amount\": 1000000000000000000 }" + }; + int64 amount = 1; +}; + message EmptyMessage {}; message Bid { From d808e1f5cef82b232d884d86ea44a3ae469a669b Mon Sep 17 00:00:00 2001 From: alok Date: Tue, 14 Nov 2023 04:34:06 +0530 Subject: [PATCH 4/4] feat: add commitmentDA --- pkg/contracts/preconf/preconf.go | 18 +- pkg/contracts/registry/registry.go | 48 +- pkg/node/preconfabi.go | 1329 +++++++++++++--------------- 3 files changed, 673 insertions(+), 722 deletions(-) diff --git a/pkg/contracts/preconf/preconf.go b/pkg/contracts/preconf/preconf.go index fe7e81da..2cfa5a64 100644 --- a/pkg/contracts/preconf/preconf.go +++ b/pkg/contracts/preconf/preconf.go @@ -67,7 +67,6 @@ func (p *preconfContract) StoreCommitment( uint64(bid.Int64()), blockNumber, txHash, - commitmentHash, bidSignature, commitmentSignature, ) @@ -96,8 +95,17 @@ func (p *preconfContract) StoreCommitment( // return err // } - gasPrice := big.NewInt(50000) - gasTipCap := big.NewInt(50000) + gasPrice, err := p.client.SuggestGasPrice(ctx) + if err != nil { + return err + } + + gasTipCap, err := p.client.SuggestGasTipCap(ctx) + if err != nil { + return err + } + + gas := big.NewInt(10000000) gasFeeCap := new(big.Int).Add(gasPrice, gasTipCap) @@ -106,7 +114,7 @@ func (p *preconfContract) StoreCommitment( To: &p.preconfContractAddr, Nonce: nonce, Data: callData, - Gas: uint64(gasPrice.Int64()), + Gas: uint64(gas.Int64()), GasFeeCap: gasFeeCap, GasTipCap: gasTipCap, }) @@ -127,7 +135,7 @@ func (p *preconfContract) StoreCommitment( p.logger.Info("sent txn", "txnData", txnData) - receipt, err := bind.WaitMined(ctx, p.client, txnData) + receipt, err := bind.WaitMined(ctx, p.client, signedTxn) if err != nil { return err } diff --git a/pkg/contracts/registry/registry.go b/pkg/contracts/registry/registry.go index e4aab584..90c89bd0 100644 --- a/pkg/contracts/registry/registry.go +++ b/pkg/contracts/registry/registry.go @@ -64,18 +64,20 @@ func (r *registryContract) RegisterProvider(ctx context.Context, amount *big.Int return err } - // gasPrice, err := p.client.SuggestGasPrice(ctx) - // if err != nil { - // return err - // } + r.logger.Info("chainID", "chainID", chainID, "nonce", nonce) - // gasTipCap, err := p.client.SuggestGasTipCap(ctx) - // if err != nil { - // return err - // } + gasPrice, err := r.client.SuggestGasPrice(ctx) + if err != nil { + return err + } + + gasTipCap, err := r.client.SuggestGasTipCap(ctx) + if err != nil { + return err + } - gasPrice := big.NewInt(50000) - gasTipCap := big.NewInt(50000) + gas := big.NewInt(10000000) + // gasTipCap := big.NewInt(0) gasFeeCap := new(big.Int).Add(gasPrice, gasTipCap) @@ -85,7 +87,7 @@ func (r *registryContract) RegisterProvider(ctx context.Context, amount *big.Int Nonce: nonce, Data: callData, Value: amount, - Gas: uint64(gasPrice.Int64()), + Gas: uint64(gas.Int64()), GasFeeCap: gasFeeCap, GasTipCap: gasTipCap, }) @@ -99,14 +101,22 @@ func (r *registryContract) RegisterProvider(ctx context.Context, amount *big.Int return err } + r.logger.Info("signed txn", "txnData", signedTxn) + err = r.client.SendTransaction(ctx, signedTxn) if err != nil { return err } - r.logger.Info("sent txn", "txnData", txnData) + // data, err := signedTxn.MarshalBinary() + // if err != nil { + // return err + // } + // rawTxHex := hexutil.Encode(data) + + // r.logger.Info("sent txn", "txnData", txnData, "txHash", signedTxn.Hash(), "rawTxHex", rawTxHex) - receipt, err := bind.WaitMined(ctx, r.client, txnData) + receipt, err := bind.WaitMined(ctx, r.client, signedTxn) if err != nil { return err } @@ -121,10 +131,7 @@ func (r *registryContract) RegisterProvider(ctx context.Context, amount *big.Int } func (r *registryContract) GetStake(ctx context.Context) (*big.Int, error) { - var address [32]byte - copy(address[:], r.owner.Bytes()) - - callData, err := r.registryABI.Pack("providerStakes", address) + callData, err := r.registryABI.Pack("checkStake", r.owner) if err != nil { r.logger.Error("error packing call data", "error", err) return nil, err @@ -142,14 +149,11 @@ func (r *registryContract) GetStake(ctx context.Context) (*big.Int, error) { return nil, err } - var stake *big.Int - err = r.registryABI.UnpackIntoInterface(&stake, "providerStakes", result) + results, err := r.registryABI.Unpack("checkStake", result) if err != nil { r.logger.Error("error unpacking result", "error", err) return nil, err } - r.logger.Info("got stake", "address", address, "stake", stake) - - return stake, nil + return abi.ConvertType(results[0], new(big.Int)).(*big.Int), nil } diff --git a/pkg/node/preconfabi.go b/pkg/node/preconfabi.go index 6a64a588..47e211c1 100644 --- a/pkg/node/preconfabi.go +++ b/pkg/node/preconfabi.go @@ -1,76 +1,84 @@ package node -var preConfJson = ` +var providerRegistryJson = ` [ { "inputs": [ { - "internalType": "address", - "name": "_providerRegistry", - "type": "address" + "internalType": "uint256", + "name": "_minStake", + "type": "uint256" }, { "internalType": "address", - "name": "_userRegistry", + "name": "_feeRecipient", "type": "address" }, { - "internalType": "address", - "name": "_oracle", - "type": "address" + "internalType": "uint16", + "name": "_feePercent", + "type": "uint16" } ], "stateMutability": "nonpayable", "type": "constructor" }, { - "inputs": [], - "name": "ECDSAInvalidSignature", - "type": "error" - }, - { + "anonymous": false, "inputs": [ { + "indexed": true, + "internalType": "address", + "name": "provider", + "type": "address" + }, + { + "indexed": false, "internalType": "uint256", - "name": "length", + "name": "amount", "type": "uint256" } ], - "name": "ECDSAInvalidSignatureLength", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "s", - "type": "bytes32" - } - ], - "name": "ECDSAInvalidSignatureS", - "type": "error" + "name": "FundsDeposited", + "type": "event" }, { + "anonymous": false, "inputs": [ { + "indexed": true, "internalType": "address", - "name": "owner", + "name": "provider", "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" } ], - "name": "OwnableInvalidOwner", - "type": "error" + "name": "FundsRewarded", + "type": "event" }, { + "anonymous": false, "inputs": [ { + "indexed": true, "internalType": "address", - "name": "account", + "name": "provider", "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" } ], - "name": "OwnableUnauthorizedAccount", - "type": "error" + "name": "FundsSlashed", + "type": "event" }, { "anonymous": false, @@ -97,29 +105,17 @@ var preConfJson = ` { "indexed": true, "internalType": "address", - "name": "signer", + "name": "provider", "type": "address" }, { "indexed": false, - "internalType": "string", - "name": "txnHash", - "type": "string" - }, - { - "indexed": true, - "internalType": "uint64", - "name": "bid", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "blockNumber", - "type": "uint64" + "internalType": "uint256", + "name": "stakedAmount", + "type": "uint256" } ], - "name": "SignatureVerified", + "name": "ProviderRegistered", "type": "event" }, { @@ -127,13 +123,19 @@ var preConfJson = ` "type": "fallback" }, { - "inputs": [], - "name": "DOMAIN_SEPARATOR_BID", + "inputs": [ + { + "internalType": "address", + "name": "provider", + "type": "address" + } + ], + "name": "checkStake", "outputs": [ { - "internalType": "bytes32", + "internalType": "uint256", "name": "", - "type": "bytes32" + "type": "uint256" } ], "stateMutability": "view", @@ -141,25 +143,19 @@ var preConfJson = ` }, { "inputs": [], - "name": "DOMAIN_SEPARATOR_PRECONF", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", + "name": "depositFunds", + "outputs": [], + "stateMutability": "payable", "type": "function" }, { "inputs": [], - "name": "EIP712_COMMITMENT_TYPEHASH", + "name": "feePercent", "outputs": [ { - "internalType": "bytes32", + "internalType": "uint16", "name": "", - "type": "bytes32" + "type": "uint16" } ], "stateMutability": "view", @@ -167,55 +163,51 @@ var preConfJson = ` }, { "inputs": [], - "name": "EIP712_MESSAGE_TYPEHASH", + "name": "feeRecipient", "outputs": [ { - "internalType": "bytes32", + "internalType": "address", "name": "", - "type": "bytes32" + "type": "address" } ], "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "bytes", - "name": "_bytes", - "type": "bytes" - } - ], - "name": "_bytesToHexString", + "inputs": [], + "name": "feeRecipientAmount", "outputs": [ { - "internalType": "string", + "internalType": "uint256", "name": "", - "type": "string" + "type": "uint256" } ], - "stateMutability": "pure", + "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, + "inputs": [], + "name": "minStake", + "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], - "name": "blockCommitments", + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", "outputs": [ { - "internalType": "bytes32", + "internalType": "address", "name": "", - "type": "bytes32" + "type": "address" } ], "stateMutability": "view", @@ -223,12 +215,12 @@ var preConfJson = ` }, { "inputs": [], - "name": "commitmentCount", + "name": "preConfirmationsContract", "outputs": [ { - "internalType": "uint256", + "internalType": "address", "name": "", - "type": "uint256" + "type": "address" } ], "stateMutability": "view", @@ -237,62 +229,17 @@ var preConfJson = ` { "inputs": [ { - "internalType": "bytes32", + "internalType": "address", "name": "", - "type": "bytes32" + "type": "address" } ], - "name": "commitments", + "name": "providerRegistered", "outputs": [ { "internalType": "bool", - "name": "commitmentUsed", + "name": "", "type": "bool" - }, - { - "internalType": "address", - "name": "bidder", - "type": "address" - }, - { - "internalType": "address", - "name": "commiter", - "type": "address" - }, - { - "internalType": "uint64", - "name": "bid", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "blockNumber", - "type": "uint64" - }, - { - "internalType": "bytes32", - "name": "bidHash", - "type": "bytes32" - }, - { - "internalType": "string", - "name": "txnHash", - "type": "string" - }, - { - "internalType": "string", - "name": "commitmentHash", - "type": "string" - }, - { - "internalType": "bytes", - "name": "bidSignature", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "commitmentSignature", - "type": "bytes" } ], "stateMutability": "view", @@ -306,7 +253,7 @@ var preConfJson = ` "type": "address" } ], - "name": "commitmentsCount", + "name": "providerStakes", "outputs": [ { "internalType": "uint256", @@ -318,243 +265,90 @@ var preConfJson = ` "type": "function" }, { - "inputs": [ - { - "internalType": "string", - "name": "_txnHash", - "type": "string" - }, - { - "internalType": "uint64", - "name": "_bid", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "_blockNumber", - "type": "uint64" - } - ], - "name": "getBidHash", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", + "inputs": [], + "name": "registerAndStake", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { - "internalType": "bytes32", - "name": "commitmentHash", - "type": "bytes32" - } - ], - "name": "getCommitment", - "outputs": [ - { - "components": [ - { - "internalType": "bool", - "name": "commitmentUsed", - "type": "bool" - }, - { - "internalType": "address", - "name": "bidder", - "type": "address" - }, - { - "internalType": "address", - "name": "commiter", - "type": "address" - }, - { - "internalType": "uint64", - "name": "bid", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "blockNumber", - "type": "uint64" - }, - { - "internalType": "bytes32", - "name": "bidHash", - "type": "bytes32" - }, - { - "internalType": "string", - "name": "txnHash", - "type": "string" - }, - { - "internalType": "string", - "name": "commitmentHash", - "type": "string" - }, - { - "internalType": "bytes", - "name": "bidSignature", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "commitmentSignature", - "type": "bytes" - } - ], - "internalType": "struct PreConfCommitmentStore.PreConfCommitment", - "name": "", - "type": "tuple" + "internalType": "uint16", + "name": "newFeePercent", + "type": "uint16" } ], - "stateMutability": "view", + "name": "setNewFeePercent", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { - "components": [ - { - "internalType": "bool", - "name": "commitmentUsed", - "type": "bool" - }, - { - "internalType": "address", - "name": "bidder", - "type": "address" - }, - { - "internalType": "address", - "name": "commiter", - "type": "address" - }, - { - "internalType": "uint64", - "name": "bid", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "blockNumber", - "type": "uint64" - }, - { - "internalType": "bytes32", - "name": "bidHash", - "type": "bytes32" - }, - { - "internalType": "string", - "name": "txnHash", - "type": "string" - }, - { - "internalType": "string", - "name": "commitmentHash", - "type": "string" - }, - { - "internalType": "bytes", - "name": "bidSignature", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "commitmentSignature", - "type": "bytes" - } - ], - "internalType": "struct PreConfCommitmentStore.PreConfCommitment", - "name": "commitment", - "type": "tuple" - } - ], - "name": "getCommitmentIndex", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" + "internalType": "address", + "name": "newFeeRecipient", + "type": "address" } ], - "stateMutability": "pure", + "name": "setNewFeeRecipient", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", - "name": "commiter", + "name": "contractAddress", "type": "address" } ], - "name": "getCommitmentsByCommitter", - "outputs": [ - { - "internalType": "bytes32[]", - "name": "", - "type": "bytes32[]" - } - ], - "stateMutability": "view", + "name": "setPreconfirmationsContract", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { - "internalType": "string", - "name": "_txnHash", - "type": "string" - }, - { - "internalType": "uint64", - "name": "_bid", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "_blockNumber", - "type": "uint64" + "internalType": "uint256", + "name": "amt", + "type": "uint256" }, { - "internalType": "bytes32", - "name": "_bidHash", - "type": "bytes32" + "internalType": "address", + "name": "provider", + "type": "address" }, { - "internalType": "string", - "name": "_bidSignature", - "type": "string" - } - ], - "name": "getPreConfHash", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" + "internalType": "address payable", + "name": "user", + "type": "address" } ], - "stateMutability": "view", + "name": "slash", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { - "internalType": "bytes32", - "name": "commitmentIndex", - "type": "bytes32" + "internalType": "address", + "name": "newOwner", + "type": "address" } ], - "name": "initateReward", + "name": "transferOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -562,19 +356,12 @@ var preConfJson = ` { "inputs": [ { - "internalType": "bytes32", - "name": "commitmentIndex", - "type": "bytes32" + "internalType": "address", + "name": "", + "type": "address" } ], - "name": "initiateSlash", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "lastProcessedBlock", + "name": "userAmount", "outputs": [ { "internalType": "uint256", @@ -587,221 +374,223 @@ var preConfJson = ` }, { "inputs": [], - "name": "oracle", - "outputs": [ + "name": "withdrawFeeRecipientAmount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ { - "internalType": "address", - "name": "", + "internalType": "address payable", + "name": "provider", "type": "address" } ], - "stateMutability": "view", + "name": "withdrawStakedAmount", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [], - "name": "owner", - "outputs": [ + "inputs": [ { "internalType": "address", - "name": "", + "name": "user", "type": "address" } ], - "stateMutability": "view", + "name": "withdrawUserAmount", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, + { + "stateMutability": "payable", + "type": "receive" + } +] +` + +var preConfJson = ` +[ { "inputs": [ { "internalType": "address", - "name": "", + "name": "_providerRegistry", "type": "address" }, { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "providerCommitments", - "outputs": [ + "internalType": "address", + "name": "_userRegistry", + "type": "address" + }, { - "internalType": "bytes32", - "name": "", - "type": "bytes32" + "internalType": "address", + "name": "_oracle", + "type": "address" } ], - "stateMutability": "view", - "type": "function" + "stateMutability": "nonpayable", + "type": "constructor" }, { - "inputs": [], - "name": "providerRegistry", - "outputs": [ + "anonymous": false, + "inputs": [ { - "internalType": "contract IProviderRegistry", - "name": "", + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", "type": "address" } ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "renounceOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + "name": "OwnershipTransferred", + "type": "event" }, { + "anonymous": false, "inputs": [ { - "internalType": "uint64", - "name": "bid", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "blockNumber", - "type": "uint64" + "indexed": true, + "internalType": "address", + "name": "signer", + "type": "address" }, { + "indexed": false, "internalType": "string", "name": "txnHash", "type": "string" }, { - "internalType": "string", - "name": "commitmentHash", - "type": "string" - }, - { - "internalType": "bytes", - "name": "bidSignature", - "type": "bytes" + "indexed": true, + "internalType": "uint64", + "name": "bid", + "type": "uint64" }, { - "internalType": "bytes", - "name": "commitmentSignature", - "type": "bytes" + "indexed": false, + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" } ], - "name": "storeCommitment", + "name": "SignatureVerified", + "type": "event" + }, + { + "stateMutability": "payable", + "type": "fallback" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR_BID", "outputs": [ { "internalType": "bytes32", - "name": "commitmentIndex", + "name": "", "type": "bytes32" } ], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { - "inputs": [ + "inputs": [], + "name": "DOMAIN_SEPARATOR_PRECONF", + "outputs": [ { - "internalType": "address", - "name": "newOwner", - "type": "address" + "internalType": "bytes32", + "name": "", + "type": "bytes32" } ], - "name": "transferOwnership", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { - "inputs": [ + "inputs": [], + "name": "EIP712_COMMITMENT_TYPEHASH", + "outputs": [ { - "internalType": "address", - "name": "newOracle", - "type": "address" + "internalType": "bytes32", + "name": "", + "type": "bytes32" } ], - "name": "updateOracle", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { - "inputs": [ + "inputs": [], + "name": "EIP712_MESSAGE_TYPEHASH", + "outputs": [ { - "internalType": "address", - "name": "newProviderRegistry", - "type": "address" + "internalType": "bytes32", + "name": "", + "type": "bytes32" } ], - "name": "updateProviderRegistry", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { "inputs": [ { - "internalType": "address", - "name": "newUserRegistry", - "type": "address" + "internalType": "bytes", + "name": "_bytes", + "type": "bytes" } ], - "name": "updateUserRegistry", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "userRegistry", + "name": "_bytesToHexString", "outputs": [ { - "internalType": "contract IUserRegistry", + "internalType": "string", "name": "", - "type": "address" + "type": "string" } ], - "stateMutability": "view", + "stateMutability": "pure", "type": "function" }, { "inputs": [ { - "internalType": "uint64", - "name": "bid", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "blockNumber", - "type": "uint64" - }, - { - "internalType": "string", - "name": "txnHash", - "type": "string" + "internalType": "uint256", + "name": "", + "type": "uint256" }, { - "internalType": "bytes", - "name": "bidSignature", - "type": "bytes" + "internalType": "uint256", + "name": "", + "type": "uint256" } ], - "name": "verifyBid", + "name": "blockCommitments", "outputs": [ { "internalType": "bytes32", - "name": "messageDigest", + "name": "", "type": "bytes32" - }, - { - "internalType": "address", - "name": "recoveredAddress", - "type": "address" - }, + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "commitmentCount", + "outputs": [ { "internalType": "uint256", - "name": "stake", + "name": "", "type": "uint256" } ], @@ -811,9 +600,27 @@ var preConfJson = ` { "inputs": [ { - "internalType": "string", - "name": "txnHash", - "type": "string" + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "commitments", + "outputs": [ + { + "internalType": "bool", + "name": "commitmentUsed", + "type": "bool" + }, + { + "internalType": "address", + "name": "bidder", + "type": "address" + }, + { + "internalType": "address", + "name": "commiter", + "type": "address" }, { "internalType": "uint64", @@ -830,6 +637,16 @@ var preConfJson = ` "name": "bidHash", "type": "bytes32" }, + { + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "bytes32", + "name": "commitmentHash", + "type": "bytes32" + }, { "internalType": "bytes", "name": "bidSignature", @@ -841,245 +658,305 @@ var preConfJson = ` "type": "bytes" } ], - "name": "verifyPreConfCommitment", - "outputs": [ - { - "internalType": "bytes32", - "name": "preConfHash", - "type": "bytes32" - }, + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ { "internalType": "address", - "name": "commiterAddress", + "name": "", "type": "address" } ], + "name": "commitmentsCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], "stateMutability": "view", "type": "function" }, - { - "stateMutability": "payable", - "type": "receive" - } -] -` -var providerRegistryJson = ` -[ { "inputs": [ { - "internalType": "uint256", - "name": "_minStake", - "type": "uint256" + "internalType": "string", + "name": "_txnHash", + "type": "string" }, { - "internalType": "address", - "name": "_feeRecipient", - "type": "address" + "internalType": "uint64", + "name": "_bid", + "type": "uint64" }, { - "internalType": "uint16", - "name": "_feePercent", - "type": "uint16" + "internalType": "uint64", + "name": "_blockNumber", + "type": "uint64" } ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [ + "name": "getBidHash", + "outputs": [ { - "internalType": "address", - "name": "owner", - "type": "address" + "internalType": "bytes32", + "name": "", + "type": "bytes32" } ], - "name": "OwnableInvalidOwner", - "type": "error" + "stateMutability": "view", + "type": "function" }, { "inputs": [ { - "internalType": "address", - "name": "account", - "type": "address" + "internalType": "bytes32", + "name": "commitmentIndex", + "type": "bytes32" } ], - "name": "OwnableUnauthorizedAccount", - "type": "error" - }, - { - "inputs": [], - "name": "ReentrancyGuardReentrantCall", - "type": "error" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "provider", - "type": "address" - }, + "name": "getCommitment", + "outputs": [ { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "components": [ + { + "internalType": "bool", + "name": "commitmentUsed", + "type": "bool" + }, + { + "internalType": "address", + "name": "bidder", + "type": "address" + }, + { + "internalType": "address", + "name": "commiter", + "type": "address" + }, + { + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "bidHash", + "type": "bytes32" + }, + { + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "bytes32", + "name": "commitmentHash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "bidSignature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "commitmentSignature", + "type": "bytes" + } + ], + "internalType": "struct PreConfCommitmentStore.PreConfCommitment", + "name": "", + "type": "tuple" } ], - "name": "FundsDeposited", - "type": "event" + "stateMutability": "view", + "type": "function" }, { - "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "provider", - "type": "address" - }, + "components": [ + { + "internalType": "bool", + "name": "commitmentUsed", + "type": "bool" + }, + { + "internalType": "address", + "name": "bidder", + "type": "address" + }, + { + "internalType": "address", + "name": "commiter", + "type": "address" + }, + { + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "bidHash", + "type": "bytes32" + }, + { + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "bytes32", + "name": "commitmentHash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "bidSignature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "commitmentSignature", + "type": "bytes" + } + ], + "internalType": "struct PreConfCommitmentStore.PreConfCommitment", + "name": "commitment", + "type": "tuple" + } + ], + "name": "getCommitmentIndex", + "outputs": [ { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "internalType": "bytes32", + "name": "", + "type": "bytes32" } ], - "name": "FundsRewarded", - "type": "event" + "stateMutability": "pure", + "type": "function" }, { - "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "provider", - "type": "address" - }, - { - "indexed": false, "internalType": "uint256", - "name": "amount", + "name": "blockNumber", "type": "uint256" } ], - "name": "FundsSlashed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "previousOwner", - "type": "address" - }, + "name": "getCommitmentsByBlockNumber", + "outputs": [ { - "indexed": true, - "internalType": "address", - "name": "newOwner", - "type": "address" + "internalType": "bytes32[]", + "name": "", + "type": "bytes32[]" } ], - "name": "OwnershipTransferred", - "type": "event" + "stateMutability": "view", + "type": "function" }, { - "anonymous": false, "inputs": [ { - "indexed": true, "internalType": "address", - "name": "provider", + "name": "commiter", "type": "address" - }, + } + ], + "name": "getCommitmentsByCommitter", + "outputs": [ { - "indexed": false, - "internalType": "uint256", - "name": "stakedAmount", - "type": "uint256" + "internalType": "bytes32[]", + "name": "", + "type": "bytes32[]" } ], - "name": "ProviderRegistered", - "type": "event" - }, - { - "stateMutability": "payable", - "type": "fallback" + "stateMutability": "view", + "type": "function" }, { "inputs": [ { - "internalType": "address", - "name": "provider", - "type": "address" - } - ], - "name": "checkStake", - "outputs": [ + "internalType": "string", + "name": "_txnHash", + "type": "string" + }, + { + "internalType": "uint64", + "name": "_bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "_blockNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "_bidHash", + "type": "bytes32" + }, { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "string", + "name": "_bidSignature", + "type": "string" } ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "depositFunds", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [], - "name": "feePercent", + "name": "getPreConfHash", "outputs": [ { - "internalType": "uint16", + "internalType": "bytes32", "name": "", - "type": "uint16" + "type": "bytes32" } ], "stateMutability": "view", "type": "function" }, { - "inputs": [], - "name": "feeRecipient", - "outputs": [ + "inputs": [ { - "internalType": "address", - "name": "", - "type": "address" + "internalType": "bytes32", + "name": "commitmentIndex", + "type": "bytes32" } ], - "stateMutability": "view", + "name": "initateReward", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [], - "name": "feeRecipientAmount", - "outputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "bytes32", + "name": "commitmentIndex", + "type": "bytes32" } ], - "stateMutability": "view", + "name": "initiateSlash", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], - "name": "minStake", + "name": "lastProcessedBlock", "outputs": [ { "internalType": "uint256", @@ -1092,7 +969,7 @@ var providerRegistryJson = ` }, { "inputs": [], - "name": "owner", + "name": "oracle", "outputs": [ { "internalType": "address", @@ -1105,7 +982,7 @@ var providerRegistryJson = ` }, { "inputs": [], - "name": "preConfirmationsContract", + "name": "owner", "outputs": [ { "internalType": "address", @@ -1122,45 +999,37 @@ var providerRegistryJson = ` "internalType": "address", "name": "", "type": "address" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" } ], - "name": "providerRegistered", + "name": "providerCommitments", "outputs": [ { - "internalType": "bool", + "internalType": "bytes32", "name": "", - "type": "bool" + "type": "bytes32" } ], "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "providerStakes", + "inputs": [], + "name": "providerRegistry", "outputs": [ { - "internalType": "uint256", + "internalType": "contract IProviderRegistry", "name": "", - "type": "uint256" + "type": "address" } ], "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "registerAndStake", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, { "inputs": [], "name": "renounceOwnership", @@ -1171,13 +1040,39 @@ var providerRegistryJson = ` { "inputs": [ { - "internalType": "uint16", - "name": "newFeePercent", - "type": "uint16" + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + }, + { + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "bytes", + "name": "bidSignature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "commitmentSignature", + "type": "bytes" + } + ], + "name": "storeCommitment", + "outputs": [ + { + "internalType": "bytes32", + "name": "commitmentIndex", + "type": "bytes32" } ], - "name": "setNewFeePercent", - "outputs": [], "stateMutability": "nonpayable", "type": "function" }, @@ -1185,11 +1080,11 @@ var providerRegistryJson = ` "inputs": [ { "internalType": "address", - "name": "newFeeRecipient", + "name": "newOwner", "type": "address" } ], - "name": "setNewFeeRecipient", + "name": "transferOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -1198,34 +1093,24 @@ var providerRegistryJson = ` "inputs": [ { "internalType": "address", - "name": "contractAddress", + "name": "newOracle", "type": "address" } ], - "name": "setPreconfirmationsContract", + "name": "updateOracle", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ - { - "internalType": "uint256", - "name": "amt", - "type": "uint256" - }, { "internalType": "address", - "name": "provider", - "type": "address" - }, - { - "internalType": "address payable", - "name": "user", + "name": "newProviderRegistry", "type": "address" } ], - "name": "slash", + "name": "updateProviderRegistry", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -1234,65 +1119,119 @@ var providerRegistryJson = ` "inputs": [ { "internalType": "address", - "name": "newOwner", + "name": "newUserRegistry", "type": "address" } ], - "name": "transferOwnership", + "name": "updateUserRegistry", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [ + "inputs": [], + "name": "userRegistry", + "outputs": [ { - "internalType": "address", + "internalType": "contract IUserRegistry", "name": "", "type": "address" } ], - "name": "userAmount", + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + }, + { + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "bytes", + "name": "bidSignature", + "type": "bytes" + } + ], + "name": "verifyBid", "outputs": [ + { + "internalType": "bytes32", + "name": "messageDigest", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "recoveredAddress", + "type": "address" + }, { "internalType": "uint256", - "name": "", + "name": "stake", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "withdrawFeeRecipientAmount", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { - "internalType": "address payable", - "name": "provider", - "type": "address" + "internalType": "string", + "name": "txnHash", + "type": "string" + }, + { + "internalType": "uint64", + "name": "bid", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "bidHash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "bidSignature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "commitmentSignature", + "type": "bytes" } ], - "name": "withdrawStakedAmount", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ + "name": "verifyPreConfCommitment", + "outputs": [ + { + "internalType": "bytes32", + "name": "preConfHash", + "type": "bytes32" + }, { "internalType": "address", - "name": "user", + "name": "commiterAddress", "type": "address" } ], - "name": "withdrawUserAmount", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, {