From a59651105fa4cd0280e987a1de763d6d5565c2cf Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 13:41:02 +0800 Subject: [PATCH 01/68] add miner api --- go.work | 1 + go.work.sum | 67 +++++++++-------- miner-api/cmd/app/app.go | 78 ++++++++++++++++++++ miner-api/cmd/app/app_test.go | 19 +++++ miner-api/cmd/app/flags.go | 15 ++++ miner-api/cmd/main.go | 21 ++++++ miner-api/controller/controller.go | 100 ++++++++++++++++++++++++++ miner-api/go.mod | 37 ++++++++++ miner-api/go.sum | 91 +++++++++++++++++++++++ miner-api/internal/config/config.go | 28 ++++++++ miner-api/internal/orm/prover_task.go | 97 +++++++++++++++++++++++++ 11 files changed, 526 insertions(+), 28 deletions(-) create mode 100644 miner-api/cmd/app/app.go create mode 100644 miner-api/cmd/app/app_test.go create mode 100644 miner-api/cmd/app/flags.go create mode 100644 miner-api/cmd/main.go create mode 100644 miner-api/controller/controller.go create mode 100644 miner-api/go.mod create mode 100644 miner-api/go.sum create mode 100644 miner-api/internal/config/config.go create mode 100644 miner-api/internal/orm/prover_task.go diff --git a/go.work b/go.work index 37c825049e..4e8dc9b38d 100644 --- a/go.work +++ b/go.work @@ -8,4 +8,5 @@ use ( ./database ./roller ./tests/integration-test + ./miner-api ) diff --git a/go.work.sum b/go.work.sum index 2f60f57e92..fca783d194 100644 --- a/go.work.sum +++ b/go.work.sum @@ -24,6 +24,7 @@ github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+B github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= github.com/Azure/go-autorest/autorest/adal v0.8.0 h1:CxTzQrySOxDnKpLjFJeZAS5Qrv/qFPkgLjx5bOAi//I= github.com/Azure/go-autorest/autorest/adal v0.8.0/go.mod h1:Z6vX6WXXuyieHAXwMj0S6HY6e6wcHn37qQMBQlvY3lc= +github.com/Azure/go-autorest/autorest/adal v0.9.23 h1:Yepx8CvFxwNKpH6ja7RZ+sKX+DWYNldbLiALMC3BTz8= github.com/Azure/go-autorest/autorest/adal v0.9.23/go.mod h1:5pcMqFkdPhviJdlEy3kC/v1ZLnQl0MH6XA5YCcMhy4c= github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA= github.com/Azure/go-autorest/autorest/date v0.2.0 h1:yW+Zlqf26583pE43KhfnhFcdmSWlm5Ew6bxipnr/tbM= @@ -196,6 +197,7 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c h1:CndMRAH4JIwxbW8KYq6Q+cGWcGHz0FjGR3QqcInWcW0= github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY= +github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e h1:bBLctRc7kr01YGvaDfgLbTwjFNW5jdp5y5rj8XXBHfY= github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90 h1:WXb3TSNmHp2vHoCroCIB1foO/yQ36swABL8aOVeDpgg= github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 h1:IZqZOB2fydHte3kUgxrzK5E1fW7RQGeDwE8F/ZZnUYc= @@ -207,8 +209,6 @@ github.com/getkin/kin-openapi v0.61.0 h1:6awGqF5nG5zkVpMsAih1QH4VgzS8phTxECUWIFo github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9 h1:r5GgOLGbza2wVHRzK7aAj6lWZjfbAwiu/RDCVOKjRyM= github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd h1:r04MMPyLHj/QwZuMJ5+7tJcBr1AQjpiAK/rZWRrQT7o= @@ -270,6 +270,7 @@ github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLe github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= +github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE= github.com/google/uuid v1.1.5/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM= @@ -278,6 +279,7 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gotestyourself/gotestyourself v1.4.0 h1:CDSlSIuRL/Fsc72Ln5lMybtrCvSRDddsHsDRG/nP7Rg= github.com/gotestyourself/gotestyourself v1.4.0/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY= github.com/graph-gophers/graphql-go v0.0.0-20201113091052-beb923fada29/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E= @@ -286,7 +288,11 @@ github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e h1:pIYdhNkDh+YENVNi3gt github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e/go.mod h1:j9cQbcqHQujT0oKJ38PylVfqohClLr3CvDC+Qcg+lhU= github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/huin/goupnp v1.0.2/go.mod h1:0dxJBVBHqTMjIUMkESDTNgOOx/Mw5wYIfyFmdzSamkM= +github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150 h1:vlNjIqmUZ9CMAWsbURYl3a6wZbw7q5RHVvlXTNS/Bs8= +github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91 h1:KyZDvZ/GGn+r+Y3DKZ7UOQ/TP4xV6HNkrwiVMB1GnNY= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6 h1:UDMh68UUwekSh5iP2OMhRRZJiiBccgV7axzUG8vi56c= github.com/iden3/go-iden3-crypto v0.0.12/go.mod h1:swXIv0HFbJKobbQBtsB50G7IHr6PbTowutSew/iBEoo= github.com/iden3/go-iden3-crypto v0.0.14/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= @@ -309,37 +315,36 @@ github.com/jackc/pgconn v1.13.0 h1:3L1XMNV2Zvca/8BYhzcRFS70Lr0WlDg16Di6SFGAbys= github.com/jackc/pgconn v1.13.0/go.mod h1:AnowpAqO4CMIIJNZl2VJp+KrkAZciAkhEl0W0JIobpI= github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= -github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgproto3/v2 v2.3.1 h1:nwj7qwf0S+Q7ISFfBndqeLwSwxs+4DPsbRFjECT1Y4Y= github.com/jackc/pgproto3/v2 v2.3.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgtype v1.12.0 h1:Dlq8Qvcch7kiehm8wPGIW0W3KsCCHJnRacKW0UM8n5w= github.com/jackc/pgtype v1.12.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= github.com/jackc/pgx/v4 v4.17.0 h1:Hsx+baY8/zU2WtPLQyZi8WbecgcsWEeyoK1jvg/WgIo= github.com/jackc/pgx/v4 v4.17.0/go.mod h1:Gd6RmOhtFLTu8cp/Fhq4kP195KrshxYJH3oW8AWJ1pw= -github.com/jackc/pgx/v5 v5.3.0/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= -github.com/jackc/puddle/v2 v2.2.0/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jackc/puddle/v2 v2.2.0 h1:RdcDk92EJBuBS55nQMMYFXTxwstHug4jkhT5pq8VxPk= github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= +github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e h1:UvSe12bq+Uj2hWd8aOlwPmoZ+CITRFrdit+sDGfAg8U= github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU= +github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89 h1:12K8AlpT0/6QUXSfV0yi4Q0jkbq8NDtIKFtF61AoqV0= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0 h1:lQ1bL/n9mBNeIXoTUoYRlK4dHuNJVofX9oWqBtPnSzI= github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= -github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.9.1 h1:6QPYqodiu3GuPL+7mfx+NwDdp2eTkp9IfEUpgAwUN0o= github.com/jsternberg/zap-logfmt v1.0.0 h1:0Dz2s/eturmdUS34GM82JwNEdQ9hPoJgqptcEKcbpzY= github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5 h1:PJr+ZMXIecYc1Ey2zucXdR73SMBtgjPgwa31099IMv0= github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef h1:2jNeR4YUziVtswNP9sEFAI913cVrzH85T+8Q6LpYbT0= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM= github.com/karalabe/usb v0.0.0-20211005121534-4c5740d64559/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= +github.com/karalabe/usb v0.0.2 h1:M6QQBNxF+CQ8OFvxrT90BA0qBOXymndZnk5q235mFc4= github.com/karalabe/usb v0.0.2/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= github.com/kataras/jwt v0.1.8 h1:u71baOsYD22HWeSOg32tCHbczPjdCk7V4MMeJqTtmGk= github.com/kataras/jwt v0.1.8/go.mod h1:Q5j2IkcIHnfwy+oNY3TVWuEBJNw0ADgCcXK9CaZwV4o= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= +github.com/kilic/bls12-381 v0.1.0 h1:encrdjqKMEvabVQ7qYOKu1OvhqpK4s47wDYtNiPtlp4= github.com/kilic/bls12-381 v0.1.0/go.mod h1:vDTTHJONJ6G+P2R74EhnyotQDTliQDnFEwhdmfzw1ig= github.com/kisielk/errcheck v1.5.0 h1:e8esj/e4R+SAOwFwN+n3zr0nYeCyeweozKfO23MvHzY= github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= @@ -347,6 +352,12 @@ github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 h1:FOOIBWrEkLgmlgGfM github.com/klauspost/compress v1.4.0 h1:8nsMz3tWa9SWWPL60G1V6CUsf4lLjWLTNEtibhe8gh8= github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4= +github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w= +github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6 h1:KAZ1BW2TCmT6PRihDPpocIy1QTtsAsrx6TneU/4+CMg= +github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada h1:3L+neHp83cTjegPdCiOxVOJtRIy7/8RldvMTsyPYH10= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY= +github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/labstack/echo/v4 v4.2.1 h1:LF5Iq7t/jrtUuSutNuiEWtB5eiHfZ5gSe2pcu5exjQw= github.com/labstack/echo/v4 v4.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY= @@ -364,6 +375,7 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd h1:HvFwW+cm9bCbZ/+vuGNq7CRWXql8c0y8nGeYpqmpvmk= github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 h1:JAEbJn3j/FrhdWA9jW8B5ajsLIjeuEHLi8xE4fk997o= github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= +github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d h1:oNAwILwmgWKFpuU+dXvI6dl9jG2mAWAZLX3r9s0PPiw= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104 h1:d8RFOZ2IiFtFWBcKEHAFYJcPTf0wY5q0exFNJZVWa1U= github.com/mattn/goveralls v0.0.2 h1:7eJB6EqsPhRVxvwEXGnqdO2sJI0PTsrWoTMXEk9/OQc= @@ -371,7 +383,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/mmcloughlin/profile v0.1.1 h1:jhDmAqPyebOsVDOCICJoINoLb/AnLBaUw58nFzxWS2w= github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs= github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae h1:VeRdUYdCw49yizlSbMEn2SZ+gT+3IUKx8BqxyQdz+BY= @@ -380,6 +392,7 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks= github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0= +github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 h1:shk/vn9oCoOTmwcouEdwIeOtOGA/ELRUw/GwvxwfT+0= github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= github.com/nats-io/jwt/v2 v2.3.0/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k= github.com/nats-io/nats-server/v2 v2.9.11/go.mod h1:b0oVuxSlkvS3ZjMkncFeACGyZohbO4XhSqW1Lt7iRRY= @@ -414,6 +427,7 @@ github.com/prometheus/client_golang v1.0.0 h1:vrDKnkGzuGvhNAL56c7DBz29ZL+KxnoR0x github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= github.com/prometheus/procfs v0.0.2 h1:6LJUbpNm42llc4HRCuvApCSWB/WfhuNo9K98Q9sNGfs= +github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7 h1:cZC+usqsYgHtlBaGulVnZ1hfKAi8iWtujBnRLQE698c= github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7/go.mod h1:IToEjHuttnUzwZI5KBSM/LOOW3qLbbrHOEfp3SbECGY= github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52 h1:RnWNS9Hlm8BIkjr6wx8li5abe0fr73jljLycdfemTp0= @@ -451,10 +465,15 @@ github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw= +github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/tinylib/msgp v1.0.2 h1:DfdQrzQa7Yh2es9SuLkixqxuXS2SxsdYn0KbdrOGWD8= github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM= @@ -475,7 +494,6 @@ github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6 h1:YdYsPAZ2pC6Tow/n github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 h1:ESFSdwYZvkeru3RtdrYueztKhOBCSAAzS4Gf+k0tEow= github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI= github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs= github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= go.etcd.io/gofail v0.1.0 h1:XItAMIhOojXFQMgrxjnd2EIIHun/d5qL0Pf7FzVTkFg= @@ -493,9 +511,7 @@ golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= -golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/exp v0.0.0-20191227195350-da58074b4299 h1:zQpM52jfKHG6II1ISZY1ZcpygvuSFZpLwfluuF89XOg= golang.org/x/exp v0.0.0-20220426173459-3bcf042a4bf5 h1:rxKZ2gOnYxjfmakvUUqh9Gyb6KXfrj7JWTxORTYqb0E= golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4= @@ -503,7 +519,6 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNT golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs= golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= @@ -512,41 +527,30 @@ golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= golang.org/x/oauth2 v0.3.0 h1:6l90koy8/LaBLmLu8jpHeHexzMwEita0zFfYlggy2F8= golang.org/x/oauth2 v0.3.0/go.mod h1:rQrIauxkUhJ6CuwEXwymO2/eh4xz2ZWF1nBkcxS+tGk= golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20201101102859-da207088b7d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20211020174200-9d6173849985/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.9.0 h1:GRRCnKYhdQrD8kfRAdQ6Zcw1P0OcELxGLKJvtjVMZ28= golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= gonum.org/v1/gonum v0.6.0 h1:DJy6UzXbahnGUf1ujUNkh/NEtK14qMo2nvlBPs4U5yw= @@ -564,12 +568,19 @@ google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/l google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= +gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= +gopkg.in/go-playground/validator.v8 v8.18.2 h1:lFB4DoMU6B626w8ny76MV7VX6W2VHct2GVOI3xgiMrQ= +gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU= +gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6 h1:a6cXbcDDUkSBlpnkWV1bJ+vv3mOgQEltEJ2rPxroVu0= gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gorm.io/driver/postgres v1.5.0/go.mod h1:FUZXzO+5Uqg5zzwzv4KK49R8lvGIyscBOqYrtI1Ce9A= -gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +gotest.tools v1.4.0 h1:BjtEgfuw8Qyd+jPvQz8CfoxiO/UjFEidWinwEXZiWv0= gotest.tools v1.4.0/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= modernc.org/cc/v3 v3.36.1/go.mod h1:NFUHyPn4ekoC/JHeZFfZurN6ixxawE1BnVonP/oahEI= diff --git a/miner-api/cmd/app/app.go b/miner-api/cmd/app/app.go new file mode 100644 index 0000000000..93d6cb261d --- /dev/null +++ b/miner-api/cmd/app/app.go @@ -0,0 +1,78 @@ +package app + +import ( + "fmt" + "os" + "os/signal" + "scroll-tech/miner-api/controller" + "scroll-tech/miner-api/internal/config" + "scroll-tech/miner-api/internal/orm" + + "github.com/scroll-tech/go-ethereum/log" + "github.com/urfave/cli/v2" + + "scroll-tech/common/database" + "scroll-tech/common/utils" + "scroll-tech/common/version" +) + +var app *cli.App + +func init() { + // Set up miner-api info. + app = cli.NewApp() + app.Action = action + app.Name = "Miner API" + app.Usage = "The Scroll L2 ZK Miner API" + app.Version = version.Version + app.Flags = append(app.Flags, utils.CommonFlags...) + app.Flags = append(app.Flags, apiFlags...) + app.Before = func(ctx *cli.Context) error { + return utils.LogSetup(ctx) + } +} + +func action(ctx *cli.Context) error { + // Load config file. + cfgFile := ctx.String(utils.ConfigFileFlag.Name) + cfg, err := config.NewConfig(cfgFile) + if err != nil { + log.Crit("failed to load config file", "config file", cfgFile, "error", err) + } + + // init db handler + db, err := database.InitDB(cfg.DBConfig) + if err != nil { + log.Crit("failed to init db connection", "err", err) + } + defer func() { + if err = database.CloseDB(db); err != nil { + log.Error("can not close ormFactory", "error", err) + } + }() + + ptdb := orm.NewProverTask(db) + + c := controller.NewController(ptdb) + go func() { + c.Run(ctx.String(httpPortFlag.Name)) + }() + + // Catch CTRL-C to ensure a graceful shutdown. + interrupt := make(chan os.Signal, 1) + signal.Notify(interrupt, os.Interrupt) + + // Wait until the interrupt signal is received from an OS signal. + <-interrupt + + return nil +} + +// Run run miner-api. +func Run() { + // RunApp the miner-api. + if err := app.Run(os.Args); err != nil { + _, _ = fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} diff --git a/miner-api/cmd/app/app_test.go b/miner-api/cmd/app/app_test.go new file mode 100644 index 0000000000..146fbc863c --- /dev/null +++ b/miner-api/cmd/app/app_test.go @@ -0,0 +1,19 @@ +package app + +import ( + "fmt" + "testing" + "time" + + "scroll-tech/common/cmd" + "scroll-tech/common/version" +) + +func TestRunCoordinator(t *testing.T) { + coordinator := cmd.NewCmd("coordinator-test", "--version") + defer coordinator.WaitExit() + + // wait result + coordinator.ExpectWithTimeout(t, true, time.Second*3, fmt.Sprintf("coordinator version %s", version.Version)) + coordinator.RunApp(nil) +} diff --git a/miner-api/cmd/app/flags.go b/miner-api/cmd/app/flags.go new file mode 100644 index 0000000000..4c6afd44c7 --- /dev/null +++ b/miner-api/cmd/app/flags.go @@ -0,0 +1,15 @@ +package app + +import "github.com/urfave/cli/v2" + +var ( + apiFlags = []cli.Flag{ + &httpPortFlag, + } + // httpPortFlag set http.port. + httpPortFlag = cli.IntFlag{ + Name: "http.port", + Usage: "HTTP server listening port", + Value: 8990, + } +) diff --git a/miner-api/cmd/main.go b/miner-api/cmd/main.go new file mode 100644 index 0000000000..76b4a6ec25 --- /dev/null +++ b/miner-api/cmd/main.go @@ -0,0 +1,21 @@ +package main + +import "scroll-tech/miner-api/cmd/app" + +// @title Zero-knowledge Miners API +// @version 1.0 +// @description This is an API server for Miners. + +// @contact.name Miner API Support +// @contact.email Be Pending + +// @license.name Apache 2.0 +// @license.url http://www.apache.org/licenses/LICENSE-2.0.html + +// @host localhost:8990 +// @BasePath /api/v1 + +// @securityDefinitions.basic BasicAuth +func main() { + app.Run() +} diff --git a/miner-api/controller/controller.go b/miner-api/controller/controller.go new file mode 100644 index 0000000000..1a44fd5fe9 --- /dev/null +++ b/miner-api/controller/controller.go @@ -0,0 +1,100 @@ +package controller + +import ( + "context" + "github.com/gin-gonic/gin" + "net/http" + "scroll-tech/miner-api/internal/orm" +) + +type Controller struct { + engine *gin.Engine + db *orm.ProverTask +} + +func NewController(db *orm.ProverTask) *Controller { + r := gin.Default() + v1 := r.Group("/api/v1") + c := &Controller{ + db: db, + } + v1.GET("/tasks", c.GetTasksByProver) + v1.GET("/total_rewards", c.GetTotalRewards) + v1.GET("/task", c.GetTask) + + c.engine = r + return c +} + +func (c *Controller) Run(port string) { + c.engine.Run(port) +} + +// GetTasksByProver godoc +// @Summary give the proverTasks +// @Description get []*ProverTask by prover public key +// @Tags prover_task +// @Accept string +// @Produce json +// @Param pubkey path string true "prover public key" +// @Success 200 {object} []*orm.ProverTask +// @Failure 404 {object} string +// @Failure 500 {object} string +// @Router /tasks/{pubkey} [get] +func (c *Controller) GetTasksByProver(ctx *gin.Context) { + pubkey := ctx.Param("pubkey") + tasks, err := c.db.GetProverTasksByProver(context.Background(), pubkey) + if err != nil { + ctx.String(http.StatusNotFound, err.Error()) + return + } + ctx.JSON(http.StatusOK, tasks) +} + +// GetTotalRewards godoc +// @Summary give the total rewards of a prover +// @Description get uint64 by prover public key +// @Tags prover_task +// @Accept string +// @Produce json +// @Param pubkey path string true "prover public key" +// @Success 200 {object} map[string]uint64 +// @Failure 404 {object} string +// @Failure 500 {object} string +// @Router /total_rewards/{pubkey} [get] +func (c *Controller) GetTotalRewards(ctx *gin.Context) { + pubkey := ctx.Param("pubkey") + tasks, err := c.db.GetProverTasksByProver(context.Background(), pubkey) + if err != nil { + ctx.String(http.StatusNotFound, err.Error()) + return + } + var rewards uint64 + for _, task := range tasks { + rewards += task.Reward + } + ctx.JSON(http.StatusOK, gin.H{"rewards": rewards}) +} + +// GetTask godoc +// @Summary give the specific prover task +// @Description get prover task by task id +// @Tags prover_task +// @Accept string +// @Produce json +// @Param task_id path string true "prover task hash" +// @Success 200 {object} *orm.ProverTask +// @Failure 404 {object} string +// @Failure 500 {object} string +// @Router /task/{pubkey} [get] +func (c *Controller) GetTask(ctx *gin.Context) { + taskID := ctx.Param("task_id") + tasks, err := c.db.GetProverTasksByHashes(context.Background(), []string{taskID}) + if err != nil { + ctx.String(http.StatusNotFound, err.Error()) + return + } + if len(tasks) > 0 { + ctx.JSON(http.StatusOK, tasks[0]) + } +} diff --git a/miner-api/go.mod b/miner-api/go.mod new file mode 100644 index 0000000000..e8f15e9773 --- /dev/null +++ b/miner-api/go.mod @@ -0,0 +1,37 @@ +module scroll-tech/miner-api + +go 1.19 + +require ( + github.com/gin-gonic/gin v1.9.1 + gorm.io/gorm v1.25.2 +) + +require ( + github.com/bytedance/sonic v1.9.1 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.4 // indirect + github.com/leodido/go-urn v1.2.4 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.11 // indirect + golang.org/x/arch v0.3.0 // indirect + golang.org/x/crypto v0.9.0 // indirect + golang.org/x/net v0.10.0 // indirect + golang.org/x/sys v0.8.0 // indirect + golang.org/x/text v0.9.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/miner-api/go.sum b/miner-api/go.sum new file mode 100644 index 0000000000..a1ab44ab40 --- /dev/null +++ b/miner-api/go.sum @@ -0,0 +1,91 @@ +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= +github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= +github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= +github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= +github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= +github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +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= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= +golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho= +gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/miner-api/internal/config/config.go b/miner-api/internal/config/config.go new file mode 100644 index 0000000000..5ef2056412 --- /dev/null +++ b/miner-api/internal/config/config.go @@ -0,0 +1,28 @@ +package config + +import ( + "encoding/json" + "os" + "path/filepath" + "scroll-tech/common/database" +) + +type Config struct { + DBConfig *database.Config `json:"db_config"` +} + +// NewConfig returns a new instance of Config. +func NewConfig(file string) (*Config, error) { + buf, err := os.ReadFile(filepath.Clean(file)) + if err != nil { + return nil, err + } + + cfg := &Config{} + err = json.Unmarshal(buf, cfg) + if err != nil { + return nil, err + } + + return cfg, nil +} diff --git a/miner-api/internal/orm/prover_task.go b/miner-api/internal/orm/prover_task.go new file mode 100644 index 0000000000..84195e5410 --- /dev/null +++ b/miner-api/internal/orm/prover_task.go @@ -0,0 +1,97 @@ +package orm + +import ( + "context" + "fmt" + "time" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + + "scroll-tech/common/types" + "scroll-tech/common/types/message" +) + +// ProverTask is assigned rollers info of chunk/batch proof prover task +type ProverTask struct { + db *gorm.DB `gorm:"column:-"` + + ID int64 `json:"id" gorm:"column:id"` + TaskID string `json:"task_id" gorm:"column:task_id"` + ProverPublicKey string `json:"prover_public_key" gorm:"column:prover_public_key"` + ProverName string `json:"prover_name" gorm:"column:prover_name"` + TaskType int16 `json:"task_type" gorm:"column:task_type;default:0"` + ProvingStatus int16 `json:"proving_status" gorm:"column:proving_status;default:0"` + FailureType int16 `json:"failure_type" gorm:"column:failure_type;default:0"` + Reward uint64 `json:"reward" gorm:"column:reward;default:0"` + Proof []byte `json:"proof" gorm:"column:proof;default:NULL"` + CreatedAt time.Time `json:"created_at" gorm:"column:created_at"` + UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at"` + DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"column:deleted_at"` +} + +// NewProverTask creates a new ProverTask instance. +func NewProverTask(db *gorm.DB) *ProverTask { + return &ProverTask{db: db} +} + +// TableName returns the name of the "prover_task" table. +func (*ProverTask) TableName() string { + return "prover_task" +} + +// GetProverTasksByHashes retrieves the ProverTask records associated with the specified hashes. +// The returned prover task objects are sorted in ascending order by their ids. +func (o *ProverTask) GetProverTasksByHashes(ctx context.Context, hashes []string) ([]*ProverTask, error) { + if len(hashes) == 0 { + return nil, nil + } + + db := o.db.WithContext(ctx) + db = db.Model(&ProverTask{}) + db = db.Where("task_id IN ?", hashes) + db = db.Order("id asc") + + var proverTasks []*ProverTask + if err := db.Find(&proverTasks).Error; err != nil { + return nil, fmt.Errorf("ProverTask.GetProverTasksByHashes error: %w, hashes: %v", err, hashes) + } + return proverTasks, nil +} + +func (o *ProverTask) GetProverTasksByProver(ctx context.Context, pubkey string) ([]*ProverTask, error) { + var proverTasks []*ProverTask + err := o.db.WithContext(ctx).Model(&ProverTask{}).Where(&ProverTask{ProverPublicKey: pubkey}).Order("id asc").Find(&proverTasks).Error + if err != nil { + return nil, fmt.Errorf("ProverTask.GetProverTasksByProver error: %w, prover %s", err, pubkey) + } + return proverTasks, nil + +} + +// SetProverTask updates or inserts a ProverTask record. +func (o *ProverTask) SetProverTask(ctx context.Context, proverTask *ProverTask) error { + db := o.db.WithContext(ctx) + db = db.Model(&ProverTask{}) + db = db.Clauses(clause.OnConflict{ + Columns: []clause.Column{{Name: "task_type"}, {Name: "task_id"}, {Name: "prover_public_key"}}, + DoUpdates: clause.AssignmentColumns([]string{"proving_status"}), + }) + + if err := db.Create(&proverTask).Error; err != nil { + return fmt.Errorf("ProverTask.SetProverTask error: %w, prover task: %v", err, proverTask) + } + return nil +} + +// UpdateProverTaskProvingStatus updates the proving_status of a specific ProverTask record. +func (o *ProverTask) UpdateProverTaskProvingStatus(ctx context.Context, proofType message.ProofType, taskID string, pk string, status types.RollerProveStatus) error { + db := o.db.WithContext(ctx) + db = db.Model(&ProverTask{}) + db = db.Where("task_type = ? AND task_id = ? AND prover_public_key = ?", proofType, taskID, pk) + + if err := db.Update("proving_status", status).Error; err != nil { + return fmt.Errorf("ProverTask.UpdateProverTaskProvingStatus error: %w, proof type: %v, taskID: %v, prover public key: %v, status: %v", err, proofType.String(), taskID, pk, status.String()) + } + return nil +} From 7e780ec1455e09772f647537419fd2d0e77cdf3b Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 13:46:41 +0800 Subject: [PATCH 02/68] add ci --- .github/workflows/miner_api.yml | 81 +++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/miner_api.yml diff --git a/.github/workflows/miner_api.yml b/.github/workflows/miner_api.yml new file mode 100644 index 0000000000..bafbfa060d --- /dev/null +++ b/.github/workflows/miner_api.yml @@ -0,0 +1,81 @@ +name: MinerAPI + +on: + push: + branches: + - main + - staging + - develop + - alpha + paths: + - 'miner-api/**' + - '.github/workflows/miner_api.yml' + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + paths: + - 'miner-api/**' + - '.github/workflows/bridge_history_api.yml' + +defaults: + run: + working-directory: 'miner-api' + +jobs: + # check: + # if: github.event.pull_request.draft == false + # runs-on: ubuntu-latest + # steps: + # - name: Install Go + # uses: actions/setup-go@v2 + # with: + # go-version: 1.19.x + # - name: Checkout code + # uses: actions/checkout@v2 + # - name: Lint + # run: | + # rm -rf $HOME/.cache/golangci-lint + # make lint + test: + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.19.x + - name: Checkout code + uses: actions/checkout@v2 + - name: Test + run: | + go get ./... + make test + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + with: + flags: miner-api + goimports-lint: + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.19.x + - name: Checkout code + uses: actions/checkout@v2 + - name: Install goimports + run: go install golang.org/x/tools/cmd/goimports + - run: goimports -local scroll-tech/miner-api/ -w . + - run: go mod tidy + # If there are any diffs from goimports or go mod tidy, fail. + - name: Verify no changes from goimports and go mod tidy + run: | + if [ -n "$(git status --porcelain)" ]; then + exit 1 + fi From 38f32b2559effafaf755f5e8606852553cd22e1f Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 14:10:38 +0800 Subject: [PATCH 03/68] add service --- miner-api/cmd/app/app.go | 13 +++++-- miner-api/controller/controller.go | 58 +++++++++++++----------------- miner-api/service/service.go | 41 +++++++++++++++++++++ 3 files changed, 76 insertions(+), 36 deletions(-) create mode 100644 miner-api/service/service.go diff --git a/miner-api/cmd/app/app.go b/miner-api/cmd/app/app.go index 93d6cb261d..a249f4eb4e 100644 --- a/miner-api/cmd/app/app.go +++ b/miner-api/cmd/app/app.go @@ -2,11 +2,13 @@ package app import ( "fmt" + "github.com/gin-gonic/gin" "os" "os/signal" "scroll-tech/miner-api/controller" "scroll-tech/miner-api/internal/config" "scroll-tech/miner-api/internal/orm" + "scroll-tech/miner-api/service" "github.com/scroll-tech/go-ethereum/log" "github.com/urfave/cli/v2" @@ -51,11 +53,18 @@ func action(ctx *cli.Context) error { } }() + // init miner api ptdb := orm.NewProverTask(db) + taskService := service.NewProverTaskService(ptdb) + + r := gin.Default() + router := r.Group("/api/v1") + + c := controller.NewProverTaskController(router, taskService) + c.Route() - c := controller.NewController(ptdb) go func() { - c.Run(ctx.String(httpPortFlag.Name)) + r.Run(ctx.String(httpPortFlag.Name)) }() // Catch CTRL-C to ensure a graceful shutdown. diff --git a/miner-api/controller/controller.go b/miner-api/controller/controller.go index 1a44fd5fe9..9143fa047d 100644 --- a/miner-api/controller/controller.go +++ b/miner-api/controller/controller.go @@ -1,33 +1,28 @@ package controller import ( - "context" "github.com/gin-gonic/gin" "net/http" - "scroll-tech/miner-api/internal/orm" + "scroll-tech/miner-api/service" ) -type Controller struct { - engine *gin.Engine - db *orm.ProverTask +type ProverTaskController struct { + router *gin.RouterGroup + service *service.ProverTaskService } -func NewController(db *orm.ProverTask) *Controller { - r := gin.Default() - v1 := r.Group("/api/v1") - c := &Controller{ - db: db, +func NewProverTaskController(r *gin.RouterGroup, taskService *service.ProverTaskService) *ProverTaskController { + router := r.Group("/prover_task") + return &ProverTaskController{ + router: router, + service: taskService, } - v1.GET("/tasks", c.GetTasksByProver) - v1.GET("/total_rewards", c.GetTotalRewards) - v1.GET("/task", c.GetTask) - - c.engine = r - return c } -func (c *Controller) Run(port string) { - c.engine.Run(port) +func (c *ProverTaskController) Route() { + c.router.GET("/tasks", c.GetTasksByProver) + c.router.GET("/total_rewards", c.GetTotalRewards) + c.router.GET("/task", c.GetTask) } // GetTasksByProver godoc @@ -40,10 +35,10 @@ func (c *Controller) Run(port string) { // @Success 200 {object} []*orm.ProverTask // @Failure 404 {object} string // @Failure 500 {object} string -// @Router /tasks/{pubkey} [get] -func (c *Controller) GetTasksByProver(ctx *gin.Context) { +// @Router /prover_task/tasks/{pubkey} [get] +func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) { pubkey := ctx.Param("pubkey") - tasks, err := c.db.GetProverTasksByProver(context.Background(), pubkey) + tasks, err := c.service.GetTasksByProver(pubkey) if err != nil { ctx.String(http.StatusNotFound, err.Error()) return @@ -61,18 +56,14 @@ func (c *Controller) GetTasksByProver(ctx *gin.Context) { // @Success 200 {object} map[string]uint64 // @Failure 404 {object} string // @Failure 500 {object} string -// @Router /total_rewards/{pubkey} [get] -func (c *Controller) GetTotalRewards(ctx *gin.Context) { +// @Router /prover_task/total_rewards/{pubkey} [get] +func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { pubkey := ctx.Param("pubkey") - tasks, err := c.db.GetProverTasksByProver(context.Background(), pubkey) + rewards, err := c.service.GetTotalRewards(pubkey) if err != nil { ctx.String(http.StatusNotFound, err.Error()) return } - var rewards uint64 - for _, task := range tasks { - rewards += task.Reward - } ctx.JSON(http.StatusOK, gin.H{"rewards": rewards}) } @@ -86,15 +77,14 @@ func (c *Controller) GetTotalRewards(ctx *gin.Context) { // @Success 200 {object} *orm.ProverTask // @Failure 404 {object} string // @Failure 500 {object} string -// @Router /task/{pubkey} [get] -func (c *Controller) GetTask(ctx *gin.Context) { +// @Router /prover_task/task/{pubkey} [get] +func (c *ProverTaskController) GetTask(ctx *gin.Context) { taskID := ctx.Param("task_id") - tasks, err := c.db.GetProverTasksByHashes(context.Background(), []string{taskID}) + task, err := c.service.GetTask(taskID) if err != nil { ctx.String(http.StatusNotFound, err.Error()) return } - if len(tasks) > 0 { - ctx.JSON(http.StatusOK, tasks[0]) - } + ctx.JSON(http.StatusOK, task) + } diff --git a/miner-api/service/service.go b/miner-api/service/service.go new file mode 100644 index 0000000000..bf956300bc --- /dev/null +++ b/miner-api/service/service.go @@ -0,0 +1,41 @@ +package service + +import ( + "context" + "scroll-tech/miner-api/internal/orm" +) + +type ProverTaskService struct { + db *orm.ProverTask +} + +func NewProverTaskService(db *orm.ProverTask) *ProverTaskService { + return &ProverTaskService{db: db} +} + +func (p *ProverTaskService) GetTasksByProver(pubkey string) ([]*orm.ProverTask, error) { + return p.db.GetProverTasksByProver(context.Background(), pubkey) +} + +func (p *ProverTaskService) GetTotalRewards(pubkey string) (uint64, error) { + tasks, err := p.db.GetProverTasksByProver(context.Background(), pubkey) + if err != nil { + return 0, err + } + var rewards uint64 + for _, task := range tasks { + rewards += task.Reward + } + return rewards, nil +} + +func (p *ProverTaskService) GetTask(taskID string) (*orm.ProverTask, error) { + tasks, err := p.db.GetProverTasksByHashes(context.Background(), []string{taskID}) + if err != nil { + return nil, err + } + if len(tasks) > 0 { + return tasks[0], nil + } + return nil, nil +} From 489888446aa9c3de69e85247d75522141b2e18db Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 14:21:21 +0800 Subject: [PATCH 04/68] add makefile --- miner-api/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 miner-api/Makefile diff --git a/miner-api/Makefile b/miner-api/Makefile new file mode 100644 index 0000000000..1d78a1212e --- /dev/null +++ b/miner-api/Makefile @@ -0,0 +1,7 @@ +.PHONY: clean + +build: + GOBIN=$(PWD)/build/bin go build -o $(PWD)/build/bin/miner-api ./cmd + +clean: ## Empty out the bin folder + @rm -rf build/bin \ No newline at end of file From 2cc77ad275070945bf5bb03208cefb229c283334 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 16:58:42 +0800 Subject: [PATCH 05/68] swag doc --- go.work.sum | 7 +++- miner-api/cmd/docs/docs.go | 49 +++++++++++++++++++++++++ miner-api/cmd/docs/swagger.json | 24 ++++++++++++ miner-api/cmd/docs/swagger.yaml | 17 +++++++++ miner-api/go.mod | 26 +++++++++++-- miner-api/go.sum | 65 +++++++++++++++++++++++++++++++++ 6 files changed, 183 insertions(+), 5 deletions(-) create mode 100644 miner-api/cmd/docs/docs.go create mode 100644 miner-api/cmd/docs/swagger.json create mode 100644 miner-api/cmd/docs/swagger.yaml diff --git a/go.work.sum b/go.work.sum index fca783d194..370584b1f2 100644 --- a/go.work.sum +++ b/go.work.sum @@ -42,6 +42,7 @@ github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VY github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc= github.com/ClickHouse/clickhouse-go/v2 v2.2.0 h1:dj00TDKY+xwuTJdbpspCSmTLFyWzRJerTHwaBxut1C0= github.com/ClickHouse/clickhouse-go/v2 v2.2.0/go.mod h1:8f2XZUi7XoeU+uPIytSi1cvx8fmJxi7vIgqpvYTF1+o= @@ -455,7 +456,6 @@ github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636 h1:aSISeOcal5irEhJd1M+ github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk= github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 h1:pXY9qYc/MP5zdvqWEUH6SjNiu7VhSjuVFTFiTcphaLU= github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= @@ -512,6 +512,7 @@ golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/exp v0.0.0-20191227195350-da58074b4299 h1:zQpM52jfKHG6II1ISZY1ZcpygvuSFZpLwfluuF89XOg= golang.org/x/exp v0.0.0-20220426173459-3bcf042a4bf5 h1:rxKZ2gOnYxjfmakvUUqh9Gyb6KXfrj7JWTxORTYqb0E= golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4= @@ -522,6 +523,7 @@ golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57/go.mod h1:3p9vT2HGsQu2 golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -533,6 +535,8 @@ golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BG golang.org/x/oauth2 v0.3.0 h1:6l90koy8/LaBLmLu8jpHeHexzMwEita0zFfYlggy2F8= golang.org/x/oauth2 v0.3.0/go.mod h1:rQrIauxkUhJ6CuwEXwymO2/eh4xz2ZWF1nBkcxS+tGk= golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20201101102859-da207088b7d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -547,6 +551,7 @@ golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.9.0 h1:GRRCnKYhdQrD8kfRAdQ6Zcw1P0OcELxGLKJvtjVMZ28= golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo= +golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= diff --git a/miner-api/cmd/docs/docs.go b/miner-api/cmd/docs/docs.go new file mode 100644 index 0000000000..00a3c2d9dd --- /dev/null +++ b/miner-api/cmd/docs/docs.go @@ -0,0 +1,49 @@ +// Code generated by swaggo/swag. DO NOT EDIT. + +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "contact": { + "name": "Miner API Support", + "email": "Be Pending" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": {}, + "securityDefinitions": { + "BasicAuth": { + "type": "basic" + } + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "1.0", + Host: "localhost:8990", + BasePath: "/api/v1", + Schemes: []string{}, + Title: "Zero-knowledge Miners API", + Description: "This is an API server for Miners.", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/miner-api/cmd/docs/swagger.json b/miner-api/cmd/docs/swagger.json new file mode 100644 index 0000000000..e5666e377a --- /dev/null +++ b/miner-api/cmd/docs/swagger.json @@ -0,0 +1,24 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is an API server for Miners.", + "title": "Zero-knowledge Miners API", + "contact": { + "name": "Miner API Support", + "email": "Be Pending" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "1.0" + }, + "host": "localhost:8990", + "basePath": "/api/v1", + "paths": {}, + "securityDefinitions": { + "BasicAuth": { + "type": "basic" + } + } +} \ No newline at end of file diff --git a/miner-api/cmd/docs/swagger.yaml b/miner-api/cmd/docs/swagger.yaml new file mode 100644 index 0000000000..90548b9cd7 --- /dev/null +++ b/miner-api/cmd/docs/swagger.yaml @@ -0,0 +1,17 @@ +basePath: /api/v1 +host: localhost:8990 +info: + contact: + email: Be Pending + name: Miner API Support + description: This is an API server for Miners. + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + title: Zero-knowledge Miners API + version: "1.0" +paths: {} +securityDefinitions: + BasicAuth: + type: basic +swagger: "2.0" diff --git a/miner-api/go.mod b/miner-api/go.mod index e8f15e9773..3be7e09e7d 100644 --- a/miner-api/go.mod +++ b/miner-api/go.mod @@ -8,30 +8,48 @@ require ( ) require ( + github.com/KyleBanks/depth v1.2.1 // indirect + github.com/PuerkitoBio/purell v1.2.0 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-openapi/jsonpointer v0.19.6 // indirect + github.com/go-openapi/jsonreference v0.20.2 // indirect + github.com/go-openapi/spec v0.20.9 // indirect + github.com/go-openapi/swag v0.22.4 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect + github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/leodido/go-urn v1.2.4 // indirect + github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/swaggo/swag v1.16.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect + github.com/urfave/cli/v2 v2.25.7 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/arch v0.3.0 // indirect - golang.org/x/crypto v0.9.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect + golang.org/x/crypto v0.11.0 // indirect + golang.org/x/net v0.12.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect + golang.org/x/tools v0.11.0 // indirect google.golang.org/protobuf v1.30.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/miner-api/go.sum b/miner-api/go.sum index a1ab44ab40..9f1f55ada1 100644 --- a/miner-api/go.sum +++ b/miner-api/go.sum @@ -1,9 +1,18 @@ +github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= +github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49Ezig= +github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -13,6 +22,20 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= +github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= +github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo= +github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= +github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= +github.com/go-openapi/spec v0.20.9 h1:xnlYNQAwKd2VQRRfwTEI0DcK+2cbuvI/0c7jx3gA8/8= +github.com/go-openapi/spec v0.20.9/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= +github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= @@ -30,13 +53,25 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= 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= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -44,14 +79,20 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -59,23 +100,38 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/swaggo/swag v1.16.1 h1:fTNRhKstPKxcnoKsytm4sahr8FaYzUcT7i1/3nd/fBg= +github.com/swaggo/swag v1.16.1/go.mod h1:9/LMvHycG3NFHfR6LwvikHv5iFvmPADQ359cKikGxto= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +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= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= +golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= +golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= @@ -83,9 +139,18 @@ google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cn google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho= gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= +sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= From aa4df0e02a62074daee2b7c666ddd54b5a5ba78f Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 17:09:06 +0800 Subject: [PATCH 06/68] import swag --- miner-api/cmd/app/app.go | 6 ++++++ miner-api/go.mod | 12 +++++++----- miner-api/go.sum | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/miner-api/cmd/app/app.go b/miner-api/cmd/app/app.go index a249f4eb4e..eefa0c69c4 100644 --- a/miner-api/cmd/app/app.go +++ b/miner-api/cmd/app/app.go @@ -16,6 +16,11 @@ import ( "scroll-tech/common/database" "scroll-tech/common/utils" "scroll-tech/common/version" + + _ "scroll-tech/miner-api/cmd/docs" + + swaggerfiles "github.com/swaggo/files" + ginSwagger "github.com/swaggo/gin-swagger" ) var app *cli.App @@ -58,6 +63,7 @@ func action(ctx *cli.Context) error { taskService := service.NewProverTaskService(ptdb) r := gin.Default() + r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) router := r.Group("/api/v1") c := controller.NewProverTaskController(router, taskService) diff --git a/miner-api/go.mod b/miner-api/go.mod index 3be7e09e7d..ca613cbaac 100644 --- a/miner-api/go.mod +++ b/miner-api/go.mod @@ -11,7 +11,7 @@ require ( github.com/KyleBanks/depth v1.2.1 // indirect github.com/PuerkitoBio/purell v1.2.0 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect - github.com/bytedance/sonic v1.9.1 // indirect + github.com/bytedance/sonic v1.9.2 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect @@ -22,13 +22,13 @@ require ( github.com/go-openapi/swag v0.22.4 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/go-playground/validator/v10 v10.14.1 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.4 // indirect + github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-isatty v0.0.19 // indirect @@ -37,18 +37,20 @@ require ( github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/swaggo/files v1.0.1 // indirect + github.com/swaggo/gin-swagger v1.6.0 // indirect github.com/swaggo/swag v1.16.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect github.com/urfave/cli/v2 v2.25.7 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect - golang.org/x/arch v0.3.0 // indirect + golang.org/x/arch v0.4.0 // indirect golang.org/x/crypto v0.11.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.10.0 // indirect golang.org/x/text v0.11.0 // indirect golang.org/x/tools v0.11.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect + google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect sigs.k8s.io/yaml v1.3.0 // indirect diff --git a/miner-api/go.sum b/miner-api/go.sum index 9f1f55ada1..c145be3c10 100644 --- a/miner-api/go.sum +++ b/miner-api/go.sum @@ -7,6 +7,8 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/bytedance/sonic v1.9.2 h1:GDaNjuWSGu09guE9Oql0MSTNhNCLlWwO8y/xM5BzcbM= +github.com/bytedance/sonic v1.9.2/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= @@ -43,6 +45,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k= +github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= @@ -60,6 +64,8 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= +github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -100,6 +106,10 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= +github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg= +github.com/swaggo/gin-swagger v1.6.0 h1:y8sxvQ3E20/RCyrXeFfg60r6H0Z+SwpTjMYsMm+zy8M= +github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRdOqDkvq0uzo= github.com/swaggo/swag v1.16.1 h1:fTNRhKstPKxcnoKsytm4sahr8FaYzUcT7i1/3nd/fBg= github.com/swaggo/swag v1.16.1/go.mod h1:9/LMvHycG3NFHfR6LwvikHv5iFvmPADQ359cKikGxto= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= @@ -110,33 +120,65 @@ 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= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc= +golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/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 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 4df562b4871d7223d07c529573f04076bbfb60b7 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 21:49:09 +0800 Subject: [PATCH 07/68] add test and config --- miner-api/cmd/app/app.go | 30 ++++--- miner-api/cmd/app/app_test.go | 19 ----- miner-api/config.json | 8 ++ miner-api/controller/controller.go | 6 +- miner-api/service/service.go | 1 + miner-api/test/prover_task_test.go | 121 +++++++++++++++++++++++++++++ 6 files changed, 153 insertions(+), 32 deletions(-) delete mode 100644 miner-api/cmd/app/app_test.go create mode 100644 miner-api/config.json create mode 100644 miner-api/test/prover_task_test.go diff --git a/miner-api/cmd/app/app.go b/miner-api/cmd/app/app.go index eefa0c69c4..cd0a2e59c5 100644 --- a/miner-api/cmd/app/app.go +++ b/miner-api/cmd/app/app.go @@ -2,9 +2,12 @@ package app import ( "fmt" - "github.com/gin-gonic/gin" + "gorm.io/gorm" "os" "os/signal" + + "github.com/gin-gonic/gin" + "scroll-tech/miner-api/controller" "scroll-tech/miner-api/internal/config" "scroll-tech/miner-api/internal/orm" @@ -59,6 +62,20 @@ func action(ctx *cli.Context) error { }() // init miner api + port := ctx.String(httpPortFlag.Name) + RunMinerAPIs(db, port) + + // Catch CTRL-C to ensure a graceful shutdown. + interrupt := make(chan os.Signal, 1) + signal.Notify(interrupt, os.Interrupt) + + // Wait until the interrupt signal is received from an OS signal. + <-interrupt + + return nil +} + +func RunMinerAPIs(db *gorm.DB, port string) { ptdb := orm.NewProverTask(db) taskService := service.NewProverTaskService(ptdb) @@ -70,17 +87,8 @@ func action(ctx *cli.Context) error { c.Route() go func() { - r.Run(ctx.String(httpPortFlag.Name)) + r.Run(port) }() - - // Catch CTRL-C to ensure a graceful shutdown. - interrupt := make(chan os.Signal, 1) - signal.Notify(interrupt, os.Interrupt) - - // Wait until the interrupt signal is received from an OS signal. - <-interrupt - - return nil } // Run run miner-api. diff --git a/miner-api/cmd/app/app_test.go b/miner-api/cmd/app/app_test.go deleted file mode 100644 index 146fbc863c..0000000000 --- a/miner-api/cmd/app/app_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package app - -import ( - "fmt" - "testing" - "time" - - "scroll-tech/common/cmd" - "scroll-tech/common/version" -) - -func TestRunCoordinator(t *testing.T) { - coordinator := cmd.NewCmd("coordinator-test", "--version") - defer coordinator.WaitExit() - - // wait result - coordinator.ExpectWithTimeout(t, true, time.Second*3, fmt.Sprintf("coordinator version %s", version.Version)) - coordinator.RunApp(nil) -} diff --git a/miner-api/config.json b/miner-api/config.json new file mode 100644 index 0000000000..14bb73d85a --- /dev/null +++ b/miner-api/config.json @@ -0,0 +1,8 @@ +{ + "db_config": { + "driver_name": "postgres", + "dsn": "postgres://admin:123456@localhost/test?sslmode=disable", + "maxOpenNum": 200, + "maxIdleNum": 20 + } +} \ No newline at end of file diff --git a/miner-api/controller/controller.go b/miner-api/controller/controller.go index 9143fa047d..3ddd55ad57 100644 --- a/miner-api/controller/controller.go +++ b/miner-api/controller/controller.go @@ -1,8 +1,10 @@ package controller import ( - "github.com/gin-gonic/gin" "net/http" + + "github.com/gin-gonic/gin" + "scroll-tech/miner-api/service" ) @@ -77,7 +79,7 @@ func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { // @Success 200 {object} *orm.ProverTask // @Failure 404 {object} string // @Failure 500 {object} string -// @Router /prover_task/task/{pubkey} [get] +// @Router /prover_task/task/{task_id} [get] func (c *ProverTaskController) GetTask(ctx *gin.Context) { taskID := ctx.Param("task_id") task, err := c.service.GetTask(taskID) diff --git a/miner-api/service/service.go b/miner-api/service/service.go index bf956300bc..b5f87ce3f9 100644 --- a/miner-api/service/service.go +++ b/miner-api/service/service.go @@ -2,6 +2,7 @@ package service import ( "context" + "scroll-tech/miner-api/internal/orm" ) diff --git a/miner-api/test/prover_task_test.go b/miner-api/test/prover_task_test.go new file mode 100644 index 0000000000..1ba476b490 --- /dev/null +++ b/miner-api/test/prover_task_test.go @@ -0,0 +1,121 @@ +package test + +import ( + "context" + "crypto/rand" + "encoding/json" + "fmt" + "github.com/stretchr/testify/assert" + "gorm.io/gorm" + "io" + "math/big" + "net/http" + "scroll-tech/common/database" + "scroll-tech/common/docker" + "scroll-tech/miner-api/cmd/app" + "scroll-tech/miner-api/internal/config" + "scroll-tech/miner-api/internal/orm" + "testing" + "time" +) + +var ( + port string + addr = fmt.Sprintf("http://localhost%s", port) + basicPath = fmt.Sprintf("%s/api/v1/prover_task", addr) + + proverPubkey = "11111" +) + +func TestProverTaskAPIs(t *testing.T) { + // start database image + base := docker.NewDockerApp() + defer base.Free() + cfg, err := config.NewConfig("../config.json") + assert.NoError(t, err) + cfg.DBConfig.DSN = base.DBImg.Endpoint() + base.RunDBImage(t) + + db, err := database.InitDB(cfg.DBConfig) + assert.NoError(t, err) + + // insert some tasks + insertSomeProverTasks(t, db) + + portInt, _ := rand.Int(rand.Reader, big.NewInt(2000)) + port = fmt.Sprintf(":%s", portInt.String()) + + // run miner APIs + app.RunMinerAPIs(db, port) + + t.Run("testGetProverTasksByProver", testGetProverTasksByProver) + t.Run("testGetTotalRewards", testGetTotalRewards) + t.Run("testGetProverTask", testGetProverTask) +} + +func testGetProverTasksByProver(t *testing.T) { + var tasks []*orm.ProverTask + getResp(t, fmt.Sprintf("%s/tasks?pubkey=%s", basicPath, proverPubkey), &tasks) + assert.Equal(t, "2", tasks[0].TaskID) + assert.Equal(t, "1", tasks[1].TaskID) +} + +func testGetTotalRewards(t *testing.T) { + rewards := make(map[string]uint64) + getResp(t, fmt.Sprintf("%s/total_rewards?pubkey=%s", basicPath, proverPubkey), &rewards) + assert.Equal(t, 22, rewards["rewards"]) +} + +func testGetProverTask(t *testing.T) { + var task orm.ProverTask + getResp(t, fmt.Sprintf("%s/task?task_id=1", basicPath), &task) + assert.Equal(t, task1, task) +} + +func getResp(t *testing.T, url string, value interface{}) { + resp, err := http.Get(url) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) + byt, err := io.ReadAll(resp.Body) + assert.NoError(t, err) + err = json.Unmarshal(byt, value) + assert.NoError(t, err) +} + +var ( + task1 = orm.ProverTask{ + ID: 1, + TaskID: "1", + ProverPublicKey: proverPubkey, + ProverName: "prover", + TaskType: 0, + ProvingStatus: 0, + FailureType: 0, + Reward: 10, + Proof: nil, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + } + + task2 = orm.ProverTask{ + ID: 2, + TaskID: "2", + ProverPublicKey: proverPubkey, + ProverName: "prover", + TaskType: 0, + ProvingStatus: 0, + FailureType: 0, + Reward: 12, + Proof: nil, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + } +) + +func insertSomeProverTasks(t *testing.T, db *gorm.DB) { + ptdb := orm.NewProverTask(db) + err := ptdb.SetProverTask(context.Background(), &task1) + assert.NoError(t, err) + err = ptdb.SetProverTask(context.Background(), &task2) + assert.NoError(t, err) +} From 598ccc3df1ccd3ba4ecdcfb9a0b54a4276475d7f Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 21:52:30 +0800 Subject: [PATCH 08/68] make test --- .github/workflows/miner_api.yml | 2 +- miner-api/Makefile | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/miner_api.yml b/.github/workflows/miner_api.yml index bafbfa060d..80ad4bf5ca 100644 --- a/.github/workflows/miner_api.yml +++ b/.github/workflows/miner_api.yml @@ -18,7 +18,7 @@ on: - ready_for_review paths: - 'miner-api/**' - - '.github/workflows/bridge_history_api.yml' + - '.github/workflows/miner_api.yml' defaults: run: diff --git a/miner-api/Makefile b/miner-api/Makefile index 1d78a1212e..bb3e392d61 100644 --- a/miner-api/Makefile +++ b/miner-api/Makefile @@ -4,4 +4,7 @@ build: GOBIN=$(PWD)/build/bin go build -o $(PWD)/build/bin/miner-api ./cmd clean: ## Empty out the bin folder - @rm -rf build/bin \ No newline at end of file + @rm -rf build/bin + +test: + go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 $(PWD)/... \ No newline at end of file From e2fe3083301e016d447bba24771d6ffd26c990d4 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 22:34:18 +0800 Subject: [PATCH 09/68] gitignore --- go.work.sum | 4 +--- miner-api/.gitignore | 1 + miner-api/go.mod | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 miner-api/.gitignore diff --git a/go.work.sum b/go.work.sum index 370584b1f2..e809d37e43 100644 --- a/go.work.sum +++ b/go.work.sum @@ -443,6 +443,7 @@ github.com/scroll-tech/go-ethereum v1.10.14-0.20230210093343-bb26fa3e391d/go.mod github.com/scroll-tech/go-ethereum v1.10.14-0.20230220082843-ec9254b0b1c6/go.mod h1:eW+eyNdMoO0MyuczCc9xWSnW8dPJ0kOy5xsxgOKYEaA= github.com/scroll-tech/go-ethereum v1.10.14-0.20230306131930-03b4de32b78b/go.mod h1:f9ygxrxL7WRCTzuloV+t/UlcxMq3AL+gcNU60liiNNU= github.com/scroll-tech/go-ethereum v1.10.14-0.20230321020420-127af384ed04/go.mod h1:jH8c08L9K8Hieaf0r/ur2P/cpesn4dFhmLm2Mmoi8kI= +github.com/scroll-tech/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg= github.com/scroll-tech/zktrie v0.4.3/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk= github.com/scroll-tech/zktrie v0.5.2/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk= github.com/segmentio/kafka-go v0.2.0 h1:HtCSf6B4gN/87yc5qTl7WsxPKQIIGXLPPM1bMCPOsoY= @@ -450,8 +451,6 @@ github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil/v3 v3.23.2 h1:PAWSuiAszn7IhPMBtXsbSCafej7PqUOvY6YywlQUExU= github.com/shirou/gopsutil/v3 v3.23.2/go.mod h1:gv0aQw33GLo3pG8SiWKiQrbDzbRY1K80RyZJ7V4Th1M= -github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= -github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636 h1:aSISeOcal5irEhJd1M+IrApc0PdcN7e7Aj4yuEnOrfQ= github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk= @@ -512,7 +511,6 @@ golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/exp v0.0.0-20191227195350-da58074b4299 h1:zQpM52jfKHG6II1ISZY1ZcpygvuSFZpLwfluuF89XOg= golang.org/x/exp v0.0.0-20220426173459-3bcf042a4bf5 h1:rxKZ2gOnYxjfmakvUUqh9Gyb6KXfrj7JWTxORTYqb0E= golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4= diff --git a/miner-api/.gitignore b/miner-api/.gitignore new file mode 100644 index 0000000000..14cea4e5ea --- /dev/null +++ b/miner-api/.gitignore @@ -0,0 +1 @@ +/build/bin \ No newline at end of file diff --git a/miner-api/go.mod b/miner-api/go.mod index ca613cbaac..7072385a94 100644 --- a/miner-api/go.mod +++ b/miner-api/go.mod @@ -7,6 +7,9 @@ require ( gorm.io/gorm v1.25.2 ) +replace github.com/ethereum/go-ethereum/log => github.com/scroll-tech/go-ethereum v1.10.26 // indirect + + require ( github.com/KyleBanks/depth v1.2.1 // indirect github.com/PuerkitoBio/purell v1.2.0 // indirect From 5eddde038871b6be19a73067723afab989580986 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 22:40:44 +0800 Subject: [PATCH 10/68] fix --- miner-api/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miner-api/Makefile b/miner-api/Makefile index bb3e392d61..1ab8478aac 100644 --- a/miner-api/Makefile +++ b/miner-api/Makefile @@ -1,4 +1,4 @@ -.PHONY: clean +.PHONY: clean build build: GOBIN=$(PWD)/build/bin go build -o $(PWD)/build/bin/miner-api ./cmd From c04883efb5e97539984d847304f9049e44697bd1 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 22:49:08 +0800 Subject: [PATCH 11/68] fix --- .github/workflows/miner_api.yml | 1 - miner-api/Makefile | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/miner_api.yml b/.github/workflows/miner_api.yml index 80ad4bf5ca..9744092af0 100644 --- a/.github/workflows/miner_api.yml +++ b/.github/workflows/miner_api.yml @@ -51,7 +51,6 @@ jobs: uses: actions/checkout@v2 - name: Test run: | - go get ./... make test - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 diff --git a/miner-api/Makefile b/miner-api/Makefile index 1ab8478aac..31e29a148e 100644 --- a/miner-api/Makefile +++ b/miner-api/Makefile @@ -7,4 +7,4 @@ clean: ## Empty out the bin folder @rm -rf build/bin test: - go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 $(PWD)/... \ No newline at end of file + go test -v $(PWD)/... \ No newline at end of file From a2dfc39ec104709bad3127e0271ecdb0806e52bb Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 22:54:43 +0800 Subject: [PATCH 12/68] fix makefile --- miner-api/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miner-api/Makefile b/miner-api/Makefile index 31e29a148e..03f6cb158f 100644 --- a/miner-api/Makefile +++ b/miner-api/Makefile @@ -1,4 +1,4 @@ -.PHONY: clean build +.PHONY: clean build test build: GOBIN=$(PWD)/build/bin go build -o $(PWD)/build/bin/miner-api ./cmd From fcaa1ea9f78a32d68283af86ca95ca1796fb6fdd Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 23:07:03 +0800 Subject: [PATCH 13/68] fix --- .github/workflows/miner_api.yml | 2 +- miner-api/test/prover_task_test.go | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/miner_api.yml b/.github/workflows/miner_api.yml index 9744092af0..05635b7112 100644 --- a/.github/workflows/miner_api.yml +++ b/.github/workflows/miner_api.yml @@ -71,7 +71,7 @@ jobs: - name: Install goimports run: go install golang.org/x/tools/cmd/goimports - run: goimports -local scroll-tech/miner-api/ -w . - - run: go mod tidy + # - run: go mod tidy # If there are any diffs from goimports or go mod tidy, fail. - name: Verify no changes from goimports and go mod tidy run: | diff --git a/miner-api/test/prover_task_test.go b/miner-api/test/prover_task_test.go index 1ba476b490..e1c523bbb2 100644 --- a/miner-api/test/prover_task_test.go +++ b/miner-api/test/prover_task_test.go @@ -20,13 +20,19 @@ import ( ) var ( - port string - addr = fmt.Sprintf("http://localhost%s", port) - basicPath = fmt.Sprintf("%s/api/v1/prover_task", addr) + port, addr, basicPath string proverPubkey = "11111" ) +func init() { + portInt, _ := rand.Int(rand.Reader, big.NewInt(2000)) + + port = fmt.Sprintf(":%s", portInt.String()) + addr = fmt.Sprintf("http://localhost%s", port) + basicPath = fmt.Sprintf("%s/api/v1/prover_task", addr) +} + func TestProverTaskAPIs(t *testing.T) { // start database image base := docker.NewDockerApp() @@ -42,9 +48,6 @@ func TestProverTaskAPIs(t *testing.T) { // insert some tasks insertSomeProverTasks(t, db) - portInt, _ := rand.Int(rand.Reader, big.NewInt(2000)) - port = fmt.Sprintf(":%s", portInt.String()) - // run miner APIs app.RunMinerAPIs(db, port) @@ -113,8 +116,10 @@ var ( ) func insertSomeProverTasks(t *testing.T, db *gorm.DB) { + err := db.AutoMigrate(new(orm.ProverTask)) + assert.NoError(t, err) ptdb := orm.NewProverTask(db) - err := ptdb.SetProverTask(context.Background(), &task1) + err = ptdb.SetProverTask(context.Background(), &task1) assert.NoError(t, err) err = ptdb.SetProverTask(context.Background(), &task2) assert.NoError(t, err) From dc22675a38864f03055e92575dfcbc0f4ec86223 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 23:25:17 +0800 Subject: [PATCH 14/68] fix --- miner-api/controller/controller.go | 2 +- miner-api/go.mod | 2 +- miner-api/go.sum | 2 ++ miner-api/internal/orm/prover_task.go | 26 +++++++++++++----------- miner-api/service/service.go | 9 +++++---- miner-api/test/prover_task_test.go | 29 +++++++++------------------ 6 files changed, 32 insertions(+), 38 deletions(-) diff --git a/miner-api/controller/controller.go b/miner-api/controller/controller.go index 3ddd55ad57..4526ef86c5 100644 --- a/miner-api/controller/controller.go +++ b/miner-api/controller/controller.go @@ -55,7 +55,7 @@ func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) { // @Accept string // @Produce json // @Param pubkey path string true "prover public key" -// @Success 200 {object} map[string]uint64 +// @Success 200 {object} map[string]decimal.Decimal // @Failure 404 {object} string // @Failure 500 {object} string // @Router /prover_task/total_rewards/{pubkey} [get] diff --git a/miner-api/go.mod b/miner-api/go.mod index 7072385a94..17ed3810ee 100644 --- a/miner-api/go.mod +++ b/miner-api/go.mod @@ -9,7 +9,6 @@ require ( replace github.com/ethereum/go-ethereum/log => github.com/scroll-tech/go-ethereum v1.10.26 // indirect - require ( github.com/KyleBanks/depth v1.2.1 // indirect github.com/PuerkitoBio/purell v1.2.0 // indirect @@ -39,6 +38,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/shopspring/decimal v1.3.1 // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/swaggo/files v1.0.1 // indirect github.com/swaggo/gin-swagger v1.6.0 // indirect diff --git a/miner-api/go.sum b/miner-api/go.sum index c145be3c10..3cea0870bf 100644 --- a/miner-api/go.sum +++ b/miner-api/go.sum @@ -92,6 +92,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= +github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/miner-api/internal/orm/prover_task.go b/miner-api/internal/orm/prover_task.go index 84195e5410..0be0990f0c 100644 --- a/miner-api/internal/orm/prover_task.go +++ b/miner-api/internal/orm/prover_task.go @@ -8,6 +8,8 @@ import ( "gorm.io/gorm" "gorm.io/gorm/clause" + "github.com/shopspring/decimal" + "scroll-tech/common/types" "scroll-tech/common/types/message" ) @@ -16,18 +18,18 @@ import ( type ProverTask struct { db *gorm.DB `gorm:"column:-"` - ID int64 `json:"id" gorm:"column:id"` - TaskID string `json:"task_id" gorm:"column:task_id"` - ProverPublicKey string `json:"prover_public_key" gorm:"column:prover_public_key"` - ProverName string `json:"prover_name" gorm:"column:prover_name"` - TaskType int16 `json:"task_type" gorm:"column:task_type;default:0"` - ProvingStatus int16 `json:"proving_status" gorm:"column:proving_status;default:0"` - FailureType int16 `json:"failure_type" gorm:"column:failure_type;default:0"` - Reward uint64 `json:"reward" gorm:"column:reward;default:0"` - Proof []byte `json:"proof" gorm:"column:proof;default:NULL"` - CreatedAt time.Time `json:"created_at" gorm:"column:created_at"` - UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at"` - DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"column:deleted_at"` + ID int64 `json:"id" gorm:"column:id"` + TaskID string `json:"task_id" gorm:"column:task_id"` + ProverPublicKey string `json:"prover_public_key" gorm:"column:prover_public_key"` + ProverName string `json:"prover_name" gorm:"column:prover_name"` + TaskType int16 `json:"task_type" gorm:"column:task_type;default:0"` + ProvingStatus int16 `json:"proving_status" gorm:"column:proving_status;default:0"` + FailureType int16 `json:"failure_type" gorm:"column:failure_type;default:0"` + Reward decimal.Decimal `json:"reward" gorm:"column:reward;default:0;type:decimal(78)"` + Proof []byte `json:"proof" gorm:"column:proof;default:NULL"` + CreatedAt time.Time `json:"created_at" gorm:"column:created_at"` + UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at"` + DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"column:deleted_at"` } // NewProverTask creates a new ProverTask instance. diff --git a/miner-api/service/service.go b/miner-api/service/service.go index b5f87ce3f9..60c8cf5c8b 100644 --- a/miner-api/service/service.go +++ b/miner-api/service/service.go @@ -2,6 +2,7 @@ package service import ( "context" + "github.com/shopspring/decimal" "scroll-tech/miner-api/internal/orm" ) @@ -18,14 +19,14 @@ func (p *ProverTaskService) GetTasksByProver(pubkey string) ([]*orm.ProverTask, return p.db.GetProverTasksByProver(context.Background(), pubkey) } -func (p *ProverTaskService) GetTotalRewards(pubkey string) (uint64, error) { +func (p *ProverTaskService) GetTotalRewards(pubkey string) (decimal.Decimal, error) { tasks, err := p.db.GetProverTasksByProver(context.Background(), pubkey) if err != nil { - return 0, err + return decimal.Decimal{}, err } - var rewards uint64 + var rewards decimal.Decimal for _, task := range tasks { - rewards += task.Reward + rewards.Add(task.Reward) } return rewards, nil } diff --git a/miner-api/test/prover_task_test.go b/miner-api/test/prover_task_test.go index e1c523bbb2..f1c4a81182 100644 --- a/miner-api/test/prover_task_test.go +++ b/miner-api/test/prover_task_test.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "encoding/json" "fmt" + "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" "gorm.io/gorm" "io" @@ -12,11 +13,11 @@ import ( "net/http" "scroll-tech/common/database" "scroll-tech/common/docker" + "scroll-tech/common/types" "scroll-tech/miner-api/cmd/app" "scroll-tech/miner-api/internal/config" "scroll-tech/miner-api/internal/orm" "testing" - "time" ) var ( @@ -66,7 +67,7 @@ func testGetProverTasksByProver(t *testing.T) { func testGetTotalRewards(t *testing.T) { rewards := make(map[string]uint64) getResp(t, fmt.Sprintf("%s/total_rewards?pubkey=%s", basicPath, proverPubkey), &rewards) - assert.Equal(t, 22, rewards["rewards"]) + assert.Equal(t, decimal.NewFromInt(22), rewards["rewards"]) } func testGetProverTask(t *testing.T) { @@ -87,31 +88,19 @@ func getResp(t *testing.T, url string, value interface{}) { var ( task1 = orm.ProverTask{ - ID: 1, TaskID: "1", ProverPublicKey: proverPubkey, - ProverName: "prover", - TaskType: 0, - ProvingStatus: 0, - FailureType: 0, - Reward: 10, - Proof: nil, - CreatedAt: time.Now(), - UpdatedAt: time.Now(), + ProverName: "prover-0", + ProvingStatus: int16(types.RollerAssigned), + Reward: decimal.NewFromInt(10), } task2 = orm.ProverTask{ - ID: 2, TaskID: "2", ProverPublicKey: proverPubkey, - ProverName: "prover", - TaskType: 0, - ProvingStatus: 0, - FailureType: 0, - Reward: 12, - Proof: nil, - CreatedAt: time.Now(), - UpdatedAt: time.Now(), + ProverName: "prover-1", + ProvingStatus: int16(types.RollerAssigned), + Reward: decimal.NewFromInt(12), } ) From 18b332a358cd88d1075be6d98ab41a7face80ed1 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 23:39:08 +0800 Subject: [PATCH 15/68] add orm test --- miner-api/internal/orm/orm_test.go | 121 +++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 miner-api/internal/orm/orm_test.go diff --git a/miner-api/internal/orm/orm_test.go b/miner-api/internal/orm/orm_test.go new file mode 100644 index 0000000000..1def2e13c4 --- /dev/null +++ b/miner-api/internal/orm/orm_test.go @@ -0,0 +1,121 @@ +package orm + +import ( + "context" + "math/big" + "testing" + + "github.com/shopspring/decimal" + "github.com/stretchr/testify/assert" + "gorm.io/gorm" + + "scroll-tech/common/database" + "scroll-tech/common/docker" + "scroll-tech/common/types" + + "scroll-tech/database/migrate" +) + +var ( + base *docker.App + + db *gorm.DB + proverTaskOrm *ProverTask +) + +func TestMain(m *testing.M) { + t := &testing.T{} + setupEnv(t) + defer tearDownEnv(t) + m.Run() +} + +func setupEnv(t *testing.T) { + base = docker.NewDockerApp() + base.RunDBImage(t) + var err error + db, err = database.InitDB( + &database.Config{ + DSN: base.DBConfig.DSN, + DriverName: base.DBConfig.DriverName, + MaxOpenNum: base.DBConfig.MaxOpenNum, + MaxIdleNum: base.DBConfig.MaxIdleNum, + }, + ) + assert.NoError(t, err) + sqlDB, err := db.DB() + assert.NoError(t, err) + assert.NoError(t, migrate.ResetDB(sqlDB)) + + proverTaskOrm = NewProverTask(db) +} + +func tearDownEnv(t *testing.T) { + sqlDB, err := db.DB() + assert.NoError(t, err) + sqlDB.Close() + base.Free() +} + +func TestProverTaskOrm(t *testing.T) { + sqlDB, err := db.DB() + assert.NoError(t, err) + assert.NoError(t, migrate.ResetDB(sqlDB)) + + reward := big.NewInt(0) + reward.SetString("18446744073709551616", 10) // 1 << 64, uint64 maximum 1<<64 -1 + + proverTask := ProverTask{ + TaskID: "test-hash", + ProverName: "roller-0", + ProverPublicKey: "0", + ProvingStatus: int16(types.RollerAssigned), + Reward: decimal.NewFromBigInt(reward, 0), + } + + err = proverTaskOrm.SetProverTask(context.Background(), &proverTask) + assert.NoError(t, err) + proverTasks, err := proverTaskOrm.GetProverTasksByHashes(context.Background(), []string{"test-hash"}) + assert.NoError(t, err) + assert.Equal(t, 1, len(proverTasks)) + assert.Equal(t, proverTask.ProverName, proverTasks[0].ProverName) + + // test decimal reward, get reward + resultReward := proverTasks[0].Reward.BigInt() + assert.Equal(t, resultReward, reward) + assert.Equal(t, resultReward.String(), "18446744073709551616") + + proverTask.ProvingStatus = int16(types.RollerProofValid) + err = proverTaskOrm.SetProverTask(context.Background(), &proverTask) + assert.NoError(t, err) + proverTasks, err = proverTaskOrm.GetProverTasksByHashes(context.Background(), []string{"test-hash"}) + assert.NoError(t, err) + assert.Equal(t, 1, len(proverTasks)) + assert.Equal(t, proverTask.ProvingStatus, proverTasks[0].ProvingStatus) +} + +func TestProverTaskOrmUint256(t *testing.T) { + sqlDB, err := db.DB() + assert.NoError(t, err) + assert.NoError(t, migrate.ResetDB(sqlDB)) + + // test reward for uint256 maximum 1 << 256 -1 :115792089237316195423570985008687907853269984665640564039457584007913129639935 + rewardUint256 := big.NewInt(0) + rewardUint256.SetString("115792089237316195423570985008687907853269984665640564039457584007913129639935", 10) + proverTask := ProverTask{ + TaskID: "test-hash", + ProverName: "roller-0", + ProverPublicKey: "0", + ProvingStatus: int16(types.RollerAssigned), + Reward: decimal.NewFromBigInt(rewardUint256, 0), + } + + err = proverTaskOrm.SetProverTask(context.Background(), &proverTask) + assert.NoError(t, err) + proverTasksUint256, err := proverTaskOrm.GetProverTasksByHashes(context.Background(), []string{"test-hash"}) + assert.NoError(t, err) + assert.Equal(t, 1, len(proverTasksUint256)) + resultRewardUint256 := proverTasksUint256[0].Reward.BigInt() + assert.Equal(t, resultRewardUint256, rewardUint256) + assert.Equal(t, resultRewardUint256.String(), "115792089237316195423570985008687907853269984665640564039457584007913129639935") +} From b443aa9ca19734af19e1b0ac9b64d6a74d36a4f0 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 11 Jul 2023 23:48:48 +0800 Subject: [PATCH 16/68] fix --- miner-api/test/prover_task_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/miner-api/test/prover_task_test.go b/miner-api/test/prover_task_test.go index f1c4a81182..dc94758ee5 100644 --- a/miner-api/test/prover_task_test.go +++ b/miner-api/test/prover_task_test.go @@ -14,6 +14,7 @@ import ( "scroll-tech/common/database" "scroll-tech/common/docker" "scroll-tech/common/types" + "scroll-tech/database/migrate" "scroll-tech/miner-api/cmd/app" "scroll-tech/miner-api/internal/config" "scroll-tech/miner-api/internal/orm" @@ -105,11 +106,14 @@ var ( ) func insertSomeProverTasks(t *testing.T, db *gorm.DB) { - err := db.AutoMigrate(new(orm.ProverTask)) + sqlDB, err := db.DB() assert.NoError(t, err) + assert.NoError(t, migrate.ResetDB(sqlDB)) + ptdb := orm.NewProverTask(db) err = ptdb.SetProverTask(context.Background(), &task1) assert.NoError(t, err) + err = ptdb.SetProverTask(context.Background(), &task2) assert.NoError(t, err) } From f294cdcc5770350e994cd8409c89c346051565ef Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 00:06:04 +0800 Subject: [PATCH 17/68] some modify --- miner-api/controller/controller.go | 1 - miner-api/internal/orm/prover_task.go | 2 +- miner-api/test/prover_task_test.go | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/miner-api/controller/controller.go b/miner-api/controller/controller.go index 4526ef86c5..66f3778479 100644 --- a/miner-api/controller/controller.go +++ b/miner-api/controller/controller.go @@ -88,5 +88,4 @@ func (c *ProverTaskController) GetTask(ctx *gin.Context) { return } ctx.JSON(http.StatusOK, task) - } diff --git a/miner-api/internal/orm/prover_task.go b/miner-api/internal/orm/prover_task.go index 0be0990f0c..08633614c2 100644 --- a/miner-api/internal/orm/prover_task.go +++ b/miner-api/internal/orm/prover_task.go @@ -63,7 +63,7 @@ func (o *ProverTask) GetProverTasksByHashes(ctx context.Context, hashes []string func (o *ProverTask) GetProverTasksByProver(ctx context.Context, pubkey string) ([]*ProverTask, error) { var proverTasks []*ProverTask - err := o.db.WithContext(ctx).Model(&ProverTask{}).Where(&ProverTask{ProverPublicKey: pubkey}).Order("id asc").Find(&proverTasks).Error + err := o.db.WithContext(ctx).Model(&ProverTask{}).Where(&ProverTask{ProverPublicKey: pubkey}).Order("created_at asc").Find(&proverTasks).Error if err != nil { return nil, fmt.Errorf("ProverTask.GetProverTasksByProver error: %w, prover %s", err, pubkey) } diff --git a/miner-api/test/prover_task_test.go b/miner-api/test/prover_task_test.go index dc94758ee5..d1edbef1de 100644 --- a/miner-api/test/prover_task_test.go +++ b/miner-api/test/prover_task_test.go @@ -66,7 +66,7 @@ func testGetProverTasksByProver(t *testing.T) { } func testGetTotalRewards(t *testing.T) { - rewards := make(map[string]uint64) + rewards := make(map[string]decimal.Decimal) getResp(t, fmt.Sprintf("%s/total_rewards?pubkey=%s", basicPath, proverPubkey), &rewards) assert.Equal(t, decimal.NewFromInt(22), rewards["rewards"]) } From a8b31bb7dcfdefad175ce2b976e55fdf38beee03 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 00:14:47 +0800 Subject: [PATCH 18/68] try fix --- miner-api/internal/orm/prover_task.go | 4 ++-- miner-api/test/prover_task_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/miner-api/internal/orm/prover_task.go b/miner-api/internal/orm/prover_task.go index 08633614c2..2ea635c910 100644 --- a/miner-api/internal/orm/prover_task.go +++ b/miner-api/internal/orm/prover_task.go @@ -61,14 +61,14 @@ func (o *ProverTask) GetProverTasksByHashes(ctx context.Context, hashes []string return proverTasks, nil } +// GetProverTasksByProver returns prover-tasks by the given prover's public key. func (o *ProverTask) GetProverTasksByProver(ctx context.Context, pubkey string) ([]*ProverTask, error) { var proverTasks []*ProverTask - err := o.db.WithContext(ctx).Model(&ProverTask{}).Where(&ProverTask{ProverPublicKey: pubkey}).Order("created_at asc").Find(&proverTasks).Error + err := o.db.WithContext(ctx).Model(&ProverTask{}).Where(&ProverTask{ProverPublicKey: pubkey}).Order("id asc").Find(&proverTasks).Error if err != nil { return nil, fmt.Errorf("ProverTask.GetProverTasksByProver error: %w, prover %s", err, pubkey) } return proverTasks, nil - } // SetProverTask updates or inserts a ProverTask record. diff --git a/miner-api/test/prover_task_test.go b/miner-api/test/prover_task_test.go index d1edbef1de..4271bce38a 100644 --- a/miner-api/test/prover_task_test.go +++ b/miner-api/test/prover_task_test.go @@ -61,14 +61,14 @@ func TestProverTaskAPIs(t *testing.T) { func testGetProverTasksByProver(t *testing.T) { var tasks []*orm.ProverTask getResp(t, fmt.Sprintf("%s/tasks?pubkey=%s", basicPath, proverPubkey), &tasks) - assert.Equal(t, "2", tasks[0].TaskID) - assert.Equal(t, "1", tasks[1].TaskID) + assert.Equal(t, task2, *tasks[0]) + assert.Equal(t, task1, *tasks[1]) } func testGetTotalRewards(t *testing.T) { - rewards := make(map[string]decimal.Decimal) + rewards := make(map[string]int) getResp(t, fmt.Sprintf("%s/total_rewards?pubkey=%s", basicPath, proverPubkey), &rewards) - assert.Equal(t, decimal.NewFromInt(22), rewards["rewards"]) + assert.Equal(t, 22, rewards["rewards"]) } func testGetProverTask(t *testing.T) { From 2ef214c34a2094b6ab9f9faffec90109c6e18256 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 00:43:53 +0800 Subject: [PATCH 19/68] try fix --- miner-api/controller/controller.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/miner-api/controller/controller.go b/miner-api/controller/controller.go index 66f3778479..11b2450f61 100644 --- a/miner-api/controller/controller.go +++ b/miner-api/controller/controller.go @@ -39,7 +39,7 @@ func (c *ProverTaskController) Route() { // @Failure 500 {object} string // @Router /prover_task/tasks/{pubkey} [get] func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) { - pubkey := ctx.Param("pubkey") + pubkey := ctx.Query("pubkey") tasks, err := c.service.GetTasksByProver(pubkey) if err != nil { ctx.String(http.StatusNotFound, err.Error()) @@ -60,7 +60,7 @@ func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) { // @Failure 500 {object} string // @Router /prover_task/total_rewards/{pubkey} [get] func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { - pubkey := ctx.Param("pubkey") + pubkey := ctx.Query("pubkey") rewards, err := c.service.GetTotalRewards(pubkey) if err != nil { ctx.String(http.StatusNotFound, err.Error()) @@ -81,7 +81,7 @@ func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { // @Failure 500 {object} string // @Router /prover_task/task/{task_id} [get] func (c *ProverTaskController) GetTask(ctx *gin.Context) { - taskID := ctx.Param("task_id") + taskID := ctx.Query("task_id") task, err := c.service.GetTask(taskID) if err != nil { ctx.String(http.StatusNotFound, err.Error()) From 23db3bf09f0534833ba90dc7e92be1ce3ce21188 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 00:59:06 +0800 Subject: [PATCH 20/68] port --- miner-api/test/prover_task_test.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/miner-api/test/prover_task_test.go b/miner-api/test/prover_task_test.go index 4271bce38a..fe34f59c13 100644 --- a/miner-api/test/prover_task_test.go +++ b/miner-api/test/prover_task_test.go @@ -2,14 +2,12 @@ package test import ( "context" - "crypto/rand" "encoding/json" "fmt" "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" "gorm.io/gorm" "io" - "math/big" "net/http" "scroll-tech/common/database" "scroll-tech/common/docker" @@ -22,18 +20,14 @@ import ( ) var ( - port, addr, basicPath string - proverPubkey = "11111" ) -func init() { - portInt, _ := rand.Int(rand.Reader, big.NewInt(2000)) - - port = fmt.Sprintf(":%s", portInt.String()) - addr = fmt.Sprintf("http://localhost%s", port) +var ( + port = ":8990" + addr = fmt.Sprintf("http://localhost%s", port) basicPath = fmt.Sprintf("%s/api/v1/prover_task", addr) -} +) func TestProverTaskAPIs(t *testing.T) { // start database image From cd807da18650aad04a42edb4ce7254cf606df7e8 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 10:41:50 +0800 Subject: [PATCH 21/68] service tests --- miner-api/service/service_test.go | 92 +++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 miner-api/service/service_test.go diff --git a/miner-api/service/service_test.go b/miner-api/service/service_test.go new file mode 100644 index 0000000000..369b3847e2 --- /dev/null +++ b/miner-api/service/service_test.go @@ -0,0 +1,92 @@ +package service + +import ( + "context" + "github.com/shopspring/decimal" + "github.com/stretchr/testify/assert" + "gorm.io/gorm" + "scroll-tech/common/database" + "scroll-tech/common/docker" + "scroll-tech/common/types" + "scroll-tech/database/migrate" + "scroll-tech/miner-api/internal/config" + "scroll-tech/miner-api/internal/orm" + "testing" +) + +var ( + proverPubkey = "key" + + task1 = orm.ProverTask{ + TaskID: "1", + ProverPublicKey: proverPubkey, + ProverName: "prover-0", + ProvingStatus: int16(types.RollerAssigned), + Reward: decimal.NewFromInt(10), + } + + task2 = orm.ProverTask{ + TaskID: "2", + ProverPublicKey: proverPubkey, + ProverName: "prover-1", + ProvingStatus: int16(types.RollerAssigned), + Reward: decimal.NewFromInt(12), + } + + service *ProverTaskService +) + +func insertSomeProverTasks(t *testing.T, db *gorm.DB) { + sqlDB, err := db.DB() + assert.NoError(t, err) + assert.NoError(t, migrate.ResetDB(sqlDB)) + + ptdb := orm.NewProverTask(db) + err = ptdb.SetProverTask(context.Background(), &task1) + assert.NoError(t, err) + + err = ptdb.SetProverTask(context.Background(), &task2) + assert.NoError(t, err) +} + +func TestProverTaskService(t *testing.T) { + // start database image + base := docker.NewDockerApp() + defer base.Free() + cfg, err := config.NewConfig("../config.json") + assert.NoError(t, err) + cfg.DBConfig.DSN = base.DBImg.Endpoint() + base.RunDBImage(t) + + db, err := database.InitDB(cfg.DBConfig) + assert.NoError(t, err) + + // insert some tasks + insertSomeProverTasks(t, db) + + ptdb := orm.NewProverTask(db) + service = NewProverTaskService(ptdb) + + t.Run("testGetTasksByProver", testGetTasksByProver) + t.Run("testGetTotalRewards", testGetTotalRewards) + t.Run("testGetTask", testGetTask) +} + +func testGetTasksByProver(t *testing.T) { + tasks, err := service.GetTasksByProver(proverPubkey) + assert.NoError(t, err) + assert.Equal(t, task2, *tasks[0]) + assert.Equal(t, task1, *tasks[1]) +} + +func testGetTotalRewards(t *testing.T) { + rewards, err := service.GetTotalRewards(proverPubkey) + assert.NoError(t, err) + assert.Equal(t, decimal.NewFromInt(22), rewards) +} + +func testGetTask(t *testing.T) { + task, err := service.GetTask("2") + assert.NoError(t, err) + assert.Equal(t, task2, *task) +} From 2c8f4f33ce75379e5b9680ae89a5362910908dac Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 10:54:40 +0800 Subject: [PATCH 22/68] .taskID --- miner-api/service/service_test.go | 6 +++--- miner-api/test/prover_task_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/miner-api/service/service_test.go b/miner-api/service/service_test.go index 369b3847e2..0be1bdd1fe 100644 --- a/miner-api/service/service_test.go +++ b/miner-api/service/service_test.go @@ -75,8 +75,8 @@ func TestProverTaskService(t *testing.T) { func testGetTasksByProver(t *testing.T) { tasks, err := service.GetTasksByProver(proverPubkey) assert.NoError(t, err) - assert.Equal(t, task2, *tasks[0]) - assert.Equal(t, task1, *tasks[1]) + assert.Equal(t, task2.TaskID, tasks[0].TaskID) + assert.Equal(t, task1.TaskID, tasks[1].TaskID) } func testGetTotalRewards(t *testing.T) { @@ -88,5 +88,5 @@ func testGetTotalRewards(t *testing.T) { func testGetTask(t *testing.T) { task, err := service.GetTask("2") assert.NoError(t, err) - assert.Equal(t, task2, *task) + assert.Equal(t, task2.TaskID, task.TaskID) } diff --git a/miner-api/test/prover_task_test.go b/miner-api/test/prover_task_test.go index fe34f59c13..b53f7fd33f 100644 --- a/miner-api/test/prover_task_test.go +++ b/miner-api/test/prover_task_test.go @@ -55,8 +55,8 @@ func TestProverTaskAPIs(t *testing.T) { func testGetProverTasksByProver(t *testing.T) { var tasks []*orm.ProverTask getResp(t, fmt.Sprintf("%s/tasks?pubkey=%s", basicPath, proverPubkey), &tasks) - assert.Equal(t, task2, *tasks[0]) - assert.Equal(t, task1, *tasks[1]) + assert.Equal(t, task2.TaskID, tasks[0].TaskID) + assert.Equal(t, task1.TaskID, tasks[1].TaskID) } func testGetTotalRewards(t *testing.T) { @@ -68,7 +68,7 @@ func testGetTotalRewards(t *testing.T) { func testGetProverTask(t *testing.T) { var task orm.ProverTask getResp(t, fmt.Sprintf("%s/task?task_id=1", basicPath), &task) - assert.Equal(t, task1, task) + assert.Equal(t, task1.TaskID, task.TaskID) } func getResp(t *testing.T, url string, value interface{}) { From 97d6c277c0e88061402d646bc9fc18bac271a369 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 11:04:15 +0800 Subject: [PATCH 23/68] desc --- miner-api/internal/orm/prover_task.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miner-api/internal/orm/prover_task.go b/miner-api/internal/orm/prover_task.go index 2ea635c910..18204472a7 100644 --- a/miner-api/internal/orm/prover_task.go +++ b/miner-api/internal/orm/prover_task.go @@ -64,7 +64,7 @@ func (o *ProverTask) GetProverTasksByHashes(ctx context.Context, hashes []string // GetProverTasksByProver returns prover-tasks by the given prover's public key. func (o *ProverTask) GetProverTasksByProver(ctx context.Context, pubkey string) ([]*ProverTask, error) { var proverTasks []*ProverTask - err := o.db.WithContext(ctx).Model(&ProverTask{}).Where(&ProverTask{ProverPublicKey: pubkey}).Order("id asc").Find(&proverTasks).Error + err := o.db.WithContext(ctx).Model(&ProverTask{}).Where(&ProverTask{ProverPublicKey: pubkey}).Order("id desc").Find(&proverTasks).Error if err != nil { return nil, fmt.Errorf("ProverTask.GetProverTasksByProver error: %w, prover %s", err, pubkey) } From 4c86e2f3ad87528bbd178276f043fa83588b119b Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 11:35:40 +0800 Subject: [PATCH 24/68] try fix --- miner-api/service/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miner-api/service/service.go b/miner-api/service/service.go index 60c8cf5c8b..55de9ce51f 100644 --- a/miner-api/service/service.go +++ b/miner-api/service/service.go @@ -24,7 +24,7 @@ func (p *ProverTaskService) GetTotalRewards(pubkey string) (decimal.Decimal, err if err != nil { return decimal.Decimal{}, err } - var rewards decimal.Decimal + rewards := decimal.New(0, 0) for _, task := range tasks { rewards.Add(task.Reward) } From 78ee95255571762d82e4ac7ee93096dfc0964dcf Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 12:08:35 +0800 Subject: [PATCH 25/68] big.Int --- miner-api/controller/controller.go | 2 +- miner-api/service/service.go | 10 +++++----- miner-api/service/service_test.go | 3 ++- miner-api/test/prover_task_test.go | 5 +++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/miner-api/controller/controller.go b/miner-api/controller/controller.go index 11b2450f61..5a1fc6b4a1 100644 --- a/miner-api/controller/controller.go +++ b/miner-api/controller/controller.go @@ -55,7 +55,7 @@ func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) { // @Accept string // @Produce json // @Param pubkey path string true "prover public key" -// @Success 200 {object} map[string]decimal.Decimal +// @Success 200 {object} map[string]*big.Int // @Failure 404 {object} string // @Failure 500 {object} string // @Router /prover_task/total_rewards/{pubkey} [get] diff --git a/miner-api/service/service.go b/miner-api/service/service.go index 55de9ce51f..7b6cc72b79 100644 --- a/miner-api/service/service.go +++ b/miner-api/service/service.go @@ -2,7 +2,7 @@ package service import ( "context" - "github.com/shopspring/decimal" + "math/big" "scroll-tech/miner-api/internal/orm" ) @@ -19,14 +19,14 @@ func (p *ProverTaskService) GetTasksByProver(pubkey string) ([]*orm.ProverTask, return p.db.GetProverTasksByProver(context.Background(), pubkey) } -func (p *ProverTaskService) GetTotalRewards(pubkey string) (decimal.Decimal, error) { +func (p *ProverTaskService) GetTotalRewards(pubkey string) (*big.Int, error) { tasks, err := p.db.GetProverTasksByProver(context.Background(), pubkey) if err != nil { - return decimal.Decimal{}, err + return nil, err } - rewards := decimal.New(0, 0) + rewards := new(big.Int) for _, task := range tasks { - rewards.Add(task.Reward) + rewards.Add(rewards, task.Reward.BigInt()) } return rewards, nil } diff --git a/miner-api/service/service_test.go b/miner-api/service/service_test.go index 0be1bdd1fe..df9d6d1141 100644 --- a/miner-api/service/service_test.go +++ b/miner-api/service/service_test.go @@ -5,6 +5,7 @@ import ( "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" "gorm.io/gorm" + "math/big" "scroll-tech/common/database" "scroll-tech/common/docker" "scroll-tech/common/types" @@ -82,7 +83,7 @@ func testGetTasksByProver(t *testing.T) { func testGetTotalRewards(t *testing.T) { rewards, err := service.GetTotalRewards(proverPubkey) assert.NoError(t, err) - assert.Equal(t, decimal.NewFromInt(22), rewards) + assert.Equal(t, big.NewInt(22), rewards) } func testGetTask(t *testing.T) { diff --git a/miner-api/test/prover_task_test.go b/miner-api/test/prover_task_test.go index b53f7fd33f..9028a42090 100644 --- a/miner-api/test/prover_task_test.go +++ b/miner-api/test/prover_task_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" "gorm.io/gorm" "io" + "math/big" "net/http" "scroll-tech/common/database" "scroll-tech/common/docker" @@ -60,9 +61,9 @@ func testGetProverTasksByProver(t *testing.T) { } func testGetTotalRewards(t *testing.T) { - rewards := make(map[string]int) + rewards := make(map[string]*big.Int) getResp(t, fmt.Sprintf("%s/total_rewards?pubkey=%s", basicPath, proverPubkey), &rewards) - assert.Equal(t, 22, rewards["rewards"]) + assert.Equal(t, big.NewInt(22), rewards["rewards"]) } func testGetProverTask(t *testing.T) { From e0679b2387b99963daf7cf614f585f8bab8fc3a2 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 12:09:15 +0800 Subject: [PATCH 26/68] ignore go mod tidy --- .github/workflows/miner_api.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/miner_api.yml b/.github/workflows/miner_api.yml index 05635b7112..f44f65978c 100644 --- a/.github/workflows/miner_api.yml +++ b/.github/workflows/miner_api.yml @@ -73,8 +73,8 @@ jobs: - run: goimports -local scroll-tech/miner-api/ -w . # - run: go mod tidy # If there are any diffs from goimports or go mod tidy, fail. - - name: Verify no changes from goimports and go mod tidy - run: | - if [ -n "$(git status --porcelain)" ]; then - exit 1 - fi +# - name: Verify no changes from goimports and go mod tidy +# run: | +# if [ -n "$(git status --porcelain)" ]; then +# exit 1 +# fi From b472f30b3608de0ea3336731644be39c06f8e583 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 12:13:07 +0800 Subject: [PATCH 27/68] change port --- miner-api/test/prover_task_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miner-api/test/prover_task_test.go b/miner-api/test/prover_task_test.go index 9028a42090..8cb7f1a595 100644 --- a/miner-api/test/prover_task_test.go +++ b/miner-api/test/prover_task_test.go @@ -25,7 +25,7 @@ var ( ) var ( - port = ":8990" + port = ":12990" addr = fmt.Sprintf("http://localhost%s", port) basicPath = fmt.Sprintf("%s/api/v1/prover_task", addr) ) From 6d3e15c262b8fb47e68fd969b2c8e73a73ff1aff Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 14:57:07 +0800 Subject: [PATCH 28/68] fix ci --- .github/workflows/miner_api.yml | 12 +++++----- go.work.sum | 5 ++++- miner-api/go.mod | 25 +++++++++++---------- miner-api/go.sum | 39 +++++++++------------------------ 4 files changed, 34 insertions(+), 47 deletions(-) diff --git a/.github/workflows/miner_api.yml b/.github/workflows/miner_api.yml index f44f65978c..9744092af0 100644 --- a/.github/workflows/miner_api.yml +++ b/.github/workflows/miner_api.yml @@ -71,10 +71,10 @@ jobs: - name: Install goimports run: go install golang.org/x/tools/cmd/goimports - run: goimports -local scroll-tech/miner-api/ -w . - # - run: go mod tidy + - run: go mod tidy # If there are any diffs from goimports or go mod tidy, fail. -# - name: Verify no changes from goimports and go mod tidy -# run: | -# if [ -n "$(git status --porcelain)" ]; then -# exit 1 -# fi + - name: Verify no changes from goimports and go mod tidy + run: | + if [ -n "$(git status --porcelain)" ]; then + exit 1 + fi diff --git a/go.work.sum b/go.work.sum index e809d37e43..026e0c6a6f 100644 --- a/go.work.sum +++ b/go.work.sum @@ -189,7 +189,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d h1:Q github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A= github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/ethereum/go-ethereum v1.10.13/go.mod h1:W3yfrFyL9C1pHcwY5hmRHVDaorTiQxhYBkKyu5mEDHw= -github.com/ethereum/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg= github.com/ethereum/go-ethereum v1.11.1/go.mod h1:DuefStAgaxoaYGLR0FueVcVbehmn5n9QUcVrMCuOvuc= github.com/ethereum/go-ethereum v1.11.4/go.mod h1:it7x0DWnTDMfVFdXcU6Ti4KEFQynLHVRarcSlPr0HBo= github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 h1:DddqAaWDpywytcG8w/qoQ5sAN8X12d3Z3koB0C3Rxsc= @@ -472,6 +471,7 @@ github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/supranational/blst v0.3.8-0.20220526154634-513d2456b344/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/tinylib/msgp v1.0.2 h1:DfdQrzQa7Yh2es9SuLkixqxuXS2SxsdYn0KbdrOGWD8= github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= @@ -482,6 +482,7 @@ github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= +github.com/urfave/cli/v2 v2.10.2/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo= github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc= github.com/valyala/fasthttp v1.40.0 h1:CRq/00MfruPGFLTQKY8b+8SfdK60TxNztjRMnH0t1Yc= github.com/valyala/fasthttp v1.40.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= @@ -527,6 +528,7 @@ golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= @@ -554,6 +556,7 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= gonum.org/v1/gonum v0.6.0 h1:DJy6UzXbahnGUf1ujUNkh/NEtK14qMo2nvlBPs4U5yw= diff --git a/miner-api/go.mod b/miner-api/go.mod index 17ed3810ee..95a6dfaf3b 100644 --- a/miner-api/go.mod +++ b/miner-api/go.mod @@ -4,18 +4,27 @@ go 1.19 require ( github.com/gin-gonic/gin v1.9.1 + github.com/scroll-tech/go-ethereum v0.0.0-00010101000000-000000000000 + github.com/shopspring/decimal v1.3.1 + github.com/stretchr/testify v1.8.3 + github.com/swaggo/files v1.0.1 + github.com/swaggo/gin-swagger v1.6.0 + github.com/swaggo/swag v1.16.1 + github.com/urfave/cli/v2 v2.25.7 gorm.io/gorm v1.25.2 ) -replace github.com/ethereum/go-ethereum/log => github.com/scroll-tech/go-ethereum v1.10.26 // indirect +replace ( + github.com/ethereum/go-ethereum => github.com/scroll-tech/go-ethereum v1.10.26 // indirect + github.com/scroll-tech/go-ethereum => github.com/ethereum/go-ethereum v1.10.26 // indirect +) require ( github.com/KyleBanks/depth v1.2.1 // indirect - github.com/PuerkitoBio/purell v1.2.0 // indirect - github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/bytedance/sonic v1.9.2 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect @@ -25,6 +34,7 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.1 // indirect + github.com/go-stack/stack v1.8.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect @@ -37,15 +47,10 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/shopspring/decimal v1.3.1 // indirect - github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect - github.com/swaggo/files v1.0.1 // indirect - github.com/swaggo/gin-swagger v1.6.0 // indirect - github.com/swaggo/swag v1.16.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect - github.com/urfave/cli/v2 v2.25.7 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/arch v0.4.0 // indirect golang.org/x/crypto v0.11.0 // indirect @@ -54,7 +59,5 @@ require ( golang.org/x/text v0.11.0 // indirect golang.org/x/tools v0.11.0 // indirect google.golang.org/protobuf v1.31.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/miner-api/go.sum b/miner-api/go.sum index 3cea0870bf..f35c7def56 100644 --- a/miner-api/go.sum +++ b/miner-api/go.sum @@ -1,12 +1,6 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= -github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49Ezig= -github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= -github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/bytedance/sonic v1.9.2 h1:GDaNjuWSGu09guE9Oql0MSTNhNCLlWwO8y/xM5BzcbM= github.com/bytedance/sonic v1.9.2/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= @@ -18,8 +12,11 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/ethereum/go-ethereum v1.10.26 h1:i/7d9RBBwiXCEuyduBQzJw/mKmnvzsN14jqBmytw72s= +github.com/ethereum/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= @@ -43,10 +40,10 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= -github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k= github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= @@ -62,14 +59,14 @@ github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFF github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= -github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= @@ -94,8 +91,6 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -124,23 +119,18 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRT github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= -golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc= golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -149,12 +139,9 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/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 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -164,8 +151,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -174,17 +159,15 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df h1:5Pf6pFKu98ODmgnpvkJ3kFUOQGGLIzLIkbzUHp47618= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= @@ -196,5 +179,3 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho= gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= From 9d22a49cd6172b81c7bc480bf56f826fffb5493f Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 14:59:43 +0800 Subject: [PATCH 29/68] Revert "fix ci" This reverts commit 6d3e15c262b8fb47e68fd969b2c8e73a73ff1aff. --- .github/workflows/miner_api.yml | 12 +++++----- go.work.sum | 5 +---- miner-api/go.mod | 25 ++++++++++----------- miner-api/go.sum | 39 ++++++++++++++++++++++++--------- 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/.github/workflows/miner_api.yml b/.github/workflows/miner_api.yml index 9744092af0..f44f65978c 100644 --- a/.github/workflows/miner_api.yml +++ b/.github/workflows/miner_api.yml @@ -71,10 +71,10 @@ jobs: - name: Install goimports run: go install golang.org/x/tools/cmd/goimports - run: goimports -local scroll-tech/miner-api/ -w . - - run: go mod tidy + # - run: go mod tidy # If there are any diffs from goimports or go mod tidy, fail. - - name: Verify no changes from goimports and go mod tidy - run: | - if [ -n "$(git status --porcelain)" ]; then - exit 1 - fi +# - name: Verify no changes from goimports and go mod tidy +# run: | +# if [ -n "$(git status --porcelain)" ]; then +# exit 1 +# fi diff --git a/go.work.sum b/go.work.sum index 026e0c6a6f..e809d37e43 100644 --- a/go.work.sum +++ b/go.work.sum @@ -189,6 +189,7 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d h1:Q github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A= github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/ethereum/go-ethereum v1.10.13/go.mod h1:W3yfrFyL9C1pHcwY5hmRHVDaorTiQxhYBkKyu5mEDHw= +github.com/ethereum/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg= github.com/ethereum/go-ethereum v1.11.1/go.mod h1:DuefStAgaxoaYGLR0FueVcVbehmn5n9QUcVrMCuOvuc= github.com/ethereum/go-ethereum v1.11.4/go.mod h1:it7x0DWnTDMfVFdXcU6Ti4KEFQynLHVRarcSlPr0HBo= github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 h1:DddqAaWDpywytcG8w/qoQ5sAN8X12d3Z3koB0C3Rxsc= @@ -471,7 +472,6 @@ github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/supranational/blst v0.3.8-0.20220526154634-513d2456b344/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/tinylib/msgp v1.0.2 h1:DfdQrzQa7Yh2es9SuLkixqxuXS2SxsdYn0KbdrOGWD8= github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= @@ -482,7 +482,6 @@ github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= -github.com/urfave/cli/v2 v2.10.2/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo= github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc= github.com/valyala/fasthttp v1.40.0 h1:CRq/00MfruPGFLTQKY8b+8SfdK60TxNztjRMnH0t1Yc= github.com/valyala/fasthttp v1.40.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= @@ -528,7 +527,6 @@ golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= @@ -556,7 +554,6 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= gonum.org/v1/gonum v0.6.0 h1:DJy6UzXbahnGUf1ujUNkh/NEtK14qMo2nvlBPs4U5yw= diff --git a/miner-api/go.mod b/miner-api/go.mod index 95a6dfaf3b..17ed3810ee 100644 --- a/miner-api/go.mod +++ b/miner-api/go.mod @@ -4,27 +4,18 @@ go 1.19 require ( github.com/gin-gonic/gin v1.9.1 - github.com/scroll-tech/go-ethereum v0.0.0-00010101000000-000000000000 - github.com/shopspring/decimal v1.3.1 - github.com/stretchr/testify v1.8.3 - github.com/swaggo/files v1.0.1 - github.com/swaggo/gin-swagger v1.6.0 - github.com/swaggo/swag v1.16.1 - github.com/urfave/cli/v2 v2.25.7 gorm.io/gorm v1.25.2 ) -replace ( - github.com/ethereum/go-ethereum => github.com/scroll-tech/go-ethereum v1.10.26 // indirect - github.com/scroll-tech/go-ethereum => github.com/ethereum/go-ethereum v1.10.26 // indirect -) +replace github.com/ethereum/go-ethereum/log => github.com/scroll-tech/go-ethereum v1.10.26 // indirect require ( github.com/KyleBanks/depth v1.2.1 // indirect + github.com/PuerkitoBio/purell v1.2.0 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/bytedance/sonic v1.9.2 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect @@ -34,7 +25,6 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.1 // indirect - github.com/go-stack/stack v1.8.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect @@ -47,10 +37,15 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/shopspring/decimal v1.3.1 // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/swaggo/files v1.0.1 // indirect + github.com/swaggo/gin-swagger v1.6.0 // indirect + github.com/swaggo/swag v1.16.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect + github.com/urfave/cli/v2 v2.25.7 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/arch v0.4.0 // indirect golang.org/x/crypto v0.11.0 // indirect @@ -59,5 +54,7 @@ require ( golang.org/x/text v0.11.0 // indirect golang.org/x/tools v0.11.0 // indirect google.golang.org/protobuf v1.31.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/miner-api/go.sum b/miner-api/go.sum index f35c7def56..3cea0870bf 100644 --- a/miner-api/go.sum +++ b/miner-api/go.sum @@ -1,6 +1,12 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49Ezig= +github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= +github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/bytedance/sonic v1.9.2 h1:GDaNjuWSGu09guE9Oql0MSTNhNCLlWwO8y/xM5BzcbM= github.com/bytedance/sonic v1.9.2/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= @@ -12,11 +18,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/ethereum/go-ethereum v1.10.26 h1:i/7d9RBBwiXCEuyduBQzJw/mKmnvzsN14jqBmytw72s= -github.com/ethereum/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= -github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= @@ -40,10 +43,10 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= +github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k= github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= -github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= @@ -59,14 +62,14 @@ github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFF github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= +github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= @@ -91,6 +94,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -119,18 +124,23 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRT github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= +golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc= golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -139,9 +149,12 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/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 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -151,6 +164,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -159,15 +174,17 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df h1:5Pf6pFKu98ODmgnpvkJ3kFUOQGGLIzLIkbzUHp47618= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= @@ -179,3 +196,5 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho= gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= +sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= From e642c91cb56e30365733b07bb3a5982f4bca8692 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 12 Jul 2023 15:05:11 +0800 Subject: [PATCH 30/68] trigger ci From 8588d4d70185d640b64a14cbf459d13d2f5863f5 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 10:41:26 +0800 Subject: [PATCH 31/68] rename to prover_stats_api --- .../{miner_api.yml => prover_stats_api.yml} | 10 ++++---- go.work | 2 +- {miner-api => prover-stats-api}/.gitignore | 0 {miner-api => prover-stats-api}/Makefile | 2 +- .../cmd/app/app.go | 25 ++++++++++--------- .../cmd/app/flags.go | 0 .../cmd/docs/docs.go | 6 ++--- .../cmd/docs/swagger.json | 6 ++--- .../cmd/docs/swagger.yaml | 6 ++--- {miner-api => prover-stats-api}/cmd/main.go | 8 +++--- {miner-api => prover-stats-api}/config.json | 0 .../controller/controller.go | 2 +- {miner-api => prover-stats-api}/go.mod | 2 +- {miner-api => prover-stats-api}/go.sum | 0 .../internal/config/config.go | 0 .../internal/orm/orm_test.go | 0 .../internal/orm/prover_task.go | 0 .../service/service.go | 2 +- .../service/service_test.go | 12 +++++---- .../test/prover_task_test.go | 16 ++++++------ 20 files changed, 52 insertions(+), 47 deletions(-) rename .github/workflows/{miner_api.yml => prover_stats_api.yml} (89%) rename {miner-api => prover-stats-api}/.gitignore (100%) rename {miner-api => prover-stats-api}/Makefile (60%) rename {miner-api => prover-stats-api}/cmd/app/app.go (81%) rename {miner-api => prover-stats-api}/cmd/app/flags.go (100%) rename {miner-api => prover-stats-api}/cmd/docs/docs.go (87%) rename {miner-api => prover-stats-api}/cmd/docs/swagger.json (73%) rename {miner-api => prover-stats-api}/cmd/docs/swagger.yaml (67%) rename {miner-api => prover-stats-api}/cmd/main.go (59%) rename {miner-api => prover-stats-api}/config.json (100%) rename {miner-api => prover-stats-api}/controller/controller.go (98%) rename {miner-api => prover-stats-api}/go.mod (98%) rename {miner-api => prover-stats-api}/go.sum (100%) rename {miner-api => prover-stats-api}/internal/config/config.go (100%) rename {miner-api => prover-stats-api}/internal/orm/orm_test.go (100%) rename {miner-api => prover-stats-api}/internal/orm/prover_task.go (100%) rename {miner-api => prover-stats-api}/service/service.go (95%) rename {miner-api => prover-stats-api}/service/service_test.go (95%) rename {miner-api => prover-stats-api}/test/prover_task_test.go (94%) diff --git a/.github/workflows/miner_api.yml b/.github/workflows/prover_stats_api.yml similarity index 89% rename from .github/workflows/miner_api.yml rename to .github/workflows/prover_stats_api.yml index f44f65978c..f65e2a6960 100644 --- a/.github/workflows/miner_api.yml +++ b/.github/workflows/prover_stats_api.yml @@ -8,7 +8,7 @@ on: - develop - alpha paths: - - 'miner-api/**' + - 'prover-stats-api/**' - '.github/workflows/miner_api.yml' pull_request: types: @@ -17,12 +17,12 @@ on: - synchronize - ready_for_review paths: - - 'miner-api/**' + - 'prover-stats-api/**' - '.github/workflows/miner_api.yml' defaults: run: - working-directory: 'miner-api' + working-directory: 'prover-stats-api' jobs: # check: @@ -57,7 +57,7 @@ jobs: env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - flags: miner-api + flags: prover-stats-api goimports-lint: if: github.event.pull_request.draft == false runs-on: ubuntu-latest @@ -70,7 +70,7 @@ jobs: uses: actions/checkout@v2 - name: Install goimports run: go install golang.org/x/tools/cmd/goimports - - run: goimports -local scroll-tech/miner-api/ -w . + - run: goimports -local scroll-tech/prover-stats-api/ -w . # - run: go mod tidy # If there are any diffs from goimports or go mod tidy, fail. # - name: Verify no changes from goimports and go mod tidy diff --git a/go.work b/go.work index 4e8dc9b38d..ee5bf7df71 100644 --- a/go.work +++ b/go.work @@ -8,5 +8,5 @@ use ( ./database ./roller ./tests/integration-test - ./miner-api + ./prover-stats-api ) diff --git a/miner-api/.gitignore b/prover-stats-api/.gitignore similarity index 100% rename from miner-api/.gitignore rename to prover-stats-api/.gitignore diff --git a/miner-api/Makefile b/prover-stats-api/Makefile similarity index 60% rename from miner-api/Makefile rename to prover-stats-api/Makefile index 03f6cb158f..81307cf200 100644 --- a/miner-api/Makefile +++ b/prover-stats-api/Makefile @@ -1,7 +1,7 @@ .PHONY: clean build test build: - GOBIN=$(PWD)/build/bin go build -o $(PWD)/build/bin/miner-api ./cmd + GOBIN=$(PWD)/build/bin go build -o $(PWD)/build/bin/prover-stats-api ./cmd clean: ## Empty out the bin folder @rm -rf build/bin diff --git a/miner-api/cmd/app/app.go b/prover-stats-api/cmd/app/app.go similarity index 81% rename from miner-api/cmd/app/app.go rename to prover-stats-api/cmd/app/app.go index cd0a2e59c5..f3569bf953 100644 --- a/miner-api/cmd/app/app.go +++ b/prover-stats-api/cmd/app/app.go @@ -2,16 +2,17 @@ package app import ( "fmt" - "gorm.io/gorm" "os" "os/signal" + "gorm.io/gorm" + "github.com/gin-gonic/gin" - "scroll-tech/miner-api/controller" - "scroll-tech/miner-api/internal/config" - "scroll-tech/miner-api/internal/orm" - "scroll-tech/miner-api/service" + "scroll-tech/prover-stats-api/controller" + "scroll-tech/prover-stats-api/internal/config" + "scroll-tech/prover-stats-api/internal/orm" + "scroll-tech/prover-stats-api/service" "github.com/scroll-tech/go-ethereum/log" "github.com/urfave/cli/v2" @@ -20,7 +21,7 @@ import ( "scroll-tech/common/utils" "scroll-tech/common/version" - _ "scroll-tech/miner-api/cmd/docs" + _ "scroll-tech/prover-stats-api/cmd/docs" swaggerfiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" @@ -29,11 +30,11 @@ import ( var app *cli.App func init() { - // Set up miner-api info. + // Set up prover-stats-api info. app = cli.NewApp() app.Action = action - app.Name = "Miner API" - app.Usage = "The Scroll L2 ZK Miner API" + app.Name = "Prover Stats API" + app.Usage = "The Scroll L2 ZK Prover Stats API" app.Version = version.Version app.Flags = append(app.Flags, utils.CommonFlags...) app.Flags = append(app.Flags, apiFlags...) @@ -61,7 +62,7 @@ func action(ctx *cli.Context) error { } }() - // init miner api + // init Prover Stats API port := ctx.String(httpPortFlag.Name) RunMinerAPIs(db, port) @@ -91,9 +92,9 @@ func RunMinerAPIs(db *gorm.DB, port string) { }() } -// Run run miner-api. +// Run run prover-stats-api. func Run() { - // RunApp the miner-api. + // RunApp the prover-stats-api. if err := app.Run(os.Args); err != nil { _, _ = fmt.Fprintln(os.Stderr, err) os.Exit(1) diff --git a/miner-api/cmd/app/flags.go b/prover-stats-api/cmd/app/flags.go similarity index 100% rename from miner-api/cmd/app/flags.go rename to prover-stats-api/cmd/app/flags.go diff --git a/miner-api/cmd/docs/docs.go b/prover-stats-api/cmd/docs/docs.go similarity index 87% rename from miner-api/cmd/docs/docs.go rename to prover-stats-api/cmd/docs/docs.go index 00a3c2d9dd..dcc32a0557 100644 --- a/miner-api/cmd/docs/docs.go +++ b/prover-stats-api/cmd/docs/docs.go @@ -11,7 +11,7 @@ const docTemplate = `{ "description": "{{escape .Description}}", "title": "{{.Title}}", "contact": { - "name": "Miner API Support", + "name": "Prover Stats API Support", "email": "Be Pending" }, "license": { @@ -36,8 +36,8 @@ var SwaggerInfo = &swag.Spec{ Host: "localhost:8990", BasePath: "/api/v1", Schemes: []string{}, - Title: "Zero-knowledge Miners API", - Description: "This is an API server for Miners.", + Title: "Zero-knowledge Prover Stats API", + Description: "This is an API server for Provers.", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, LeftDelim: "{{", diff --git a/miner-api/cmd/docs/swagger.json b/prover-stats-api/cmd/docs/swagger.json similarity index 73% rename from miner-api/cmd/docs/swagger.json rename to prover-stats-api/cmd/docs/swagger.json index e5666e377a..960c088226 100644 --- a/miner-api/cmd/docs/swagger.json +++ b/prover-stats-api/cmd/docs/swagger.json @@ -1,10 +1,10 @@ { "swagger": "2.0", "info": { - "description": "This is an API server for Miners.", - "title": "Zero-knowledge Miners API", + "description": "This is an API server for Provers.", + "title": "Zero-knowledge Prover Stats API", "contact": { - "name": "Miner API Support", + "name": "Prover Stats API Support", "email": "Be Pending" }, "license": { diff --git a/miner-api/cmd/docs/swagger.yaml b/prover-stats-api/cmd/docs/swagger.yaml similarity index 67% rename from miner-api/cmd/docs/swagger.yaml rename to prover-stats-api/cmd/docs/swagger.yaml index 90548b9cd7..36129305d9 100644 --- a/miner-api/cmd/docs/swagger.yaml +++ b/prover-stats-api/cmd/docs/swagger.yaml @@ -3,12 +3,12 @@ host: localhost:8990 info: contact: email: Be Pending - name: Miner API Support - description: This is an API server for Miners. + name: Prover Stats API Support + description: This is an API server for Provers. license: name: Apache 2.0 url: http://www.apache.org/licenses/LICENSE-2.0.html - title: Zero-knowledge Miners API + title: Zero-knowledge Prover Stats API version: "1.0" paths: {} securityDefinitions: diff --git a/miner-api/cmd/main.go b/prover-stats-api/cmd/main.go similarity index 59% rename from miner-api/cmd/main.go rename to prover-stats-api/cmd/main.go index 76b4a6ec25..5e309f3c33 100644 --- a/miner-api/cmd/main.go +++ b/prover-stats-api/cmd/main.go @@ -1,12 +1,12 @@ package main -import "scroll-tech/miner-api/cmd/app" +import "scroll-tech/prover-stats-api/cmd/app" -// @title Zero-knowledge Miners API +// @title Zero-knowledge Prover Stats API // @version 1.0 -// @description This is an API server for Miners. +// @description This is an API server for Provers. -// @contact.name Miner API Support +// @contact.name Prover Stats API Support // @contact.email Be Pending // @license.name Apache 2.0 diff --git a/miner-api/config.json b/prover-stats-api/config.json similarity index 100% rename from miner-api/config.json rename to prover-stats-api/config.json diff --git a/miner-api/controller/controller.go b/prover-stats-api/controller/controller.go similarity index 98% rename from miner-api/controller/controller.go rename to prover-stats-api/controller/controller.go index 5a1fc6b4a1..bf0ac0891f 100644 --- a/miner-api/controller/controller.go +++ b/prover-stats-api/controller/controller.go @@ -5,7 +5,7 @@ import ( "github.com/gin-gonic/gin" - "scroll-tech/miner-api/service" + "scroll-tech/prover-stats-api/service" ) type ProverTaskController struct { diff --git a/miner-api/go.mod b/prover-stats-api/go.mod similarity index 98% rename from miner-api/go.mod rename to prover-stats-api/go.mod index 17ed3810ee..0da1cc4089 100644 --- a/miner-api/go.mod +++ b/prover-stats-api/go.mod @@ -1,4 +1,4 @@ -module scroll-tech/miner-api +module scroll-tech/prover-stats-api go 1.19 diff --git a/miner-api/go.sum b/prover-stats-api/go.sum similarity index 100% rename from miner-api/go.sum rename to prover-stats-api/go.sum diff --git a/miner-api/internal/config/config.go b/prover-stats-api/internal/config/config.go similarity index 100% rename from miner-api/internal/config/config.go rename to prover-stats-api/internal/config/config.go diff --git a/miner-api/internal/orm/orm_test.go b/prover-stats-api/internal/orm/orm_test.go similarity index 100% rename from miner-api/internal/orm/orm_test.go rename to prover-stats-api/internal/orm/orm_test.go diff --git a/miner-api/internal/orm/prover_task.go b/prover-stats-api/internal/orm/prover_task.go similarity index 100% rename from miner-api/internal/orm/prover_task.go rename to prover-stats-api/internal/orm/prover_task.go diff --git a/miner-api/service/service.go b/prover-stats-api/service/service.go similarity index 95% rename from miner-api/service/service.go rename to prover-stats-api/service/service.go index 7b6cc72b79..9d20c603ef 100644 --- a/miner-api/service/service.go +++ b/prover-stats-api/service/service.go @@ -4,7 +4,7 @@ import ( "context" "math/big" - "scroll-tech/miner-api/internal/orm" + "scroll-tech/prover-stats-api/internal/orm" ) type ProverTaskService struct { diff --git a/miner-api/service/service_test.go b/prover-stats-api/service/service_test.go similarity index 95% rename from miner-api/service/service_test.go rename to prover-stats-api/service/service_test.go index df9d6d1141..f2ccf2d2ae 100644 --- a/miner-api/service/service_test.go +++ b/prover-stats-api/service/service_test.go @@ -2,17 +2,19 @@ package service import ( "context" - "github.com/shopspring/decimal" - "github.com/stretchr/testify/assert" - "gorm.io/gorm" "math/big" "scroll-tech/common/database" "scroll-tech/common/docker" "scroll-tech/common/types" "scroll-tech/database/migrate" - "scroll-tech/miner-api/internal/config" - "scroll-tech/miner-api/internal/orm" "testing" + + "github.com/shopspring/decimal" + "github.com/stretchr/testify/assert" + "gorm.io/gorm" + + "scroll-tech/prover-stats-api/internal/config" + "scroll-tech/prover-stats-api/internal/orm" ) var ( diff --git a/miner-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go similarity index 94% rename from miner-api/test/prover_task_test.go rename to prover-stats-api/test/prover_task_test.go index 8cb7f1a595..d387f043f6 100644 --- a/miner-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -4,9 +4,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/shopspring/decimal" - "github.com/stretchr/testify/assert" - "gorm.io/gorm" "io" "math/big" "net/http" @@ -14,10 +11,15 @@ import ( "scroll-tech/common/docker" "scroll-tech/common/types" "scroll-tech/database/migrate" - "scroll-tech/miner-api/cmd/app" - "scroll-tech/miner-api/internal/config" - "scroll-tech/miner-api/internal/orm" "testing" + + "github.com/shopspring/decimal" + "github.com/stretchr/testify/assert" + "gorm.io/gorm" + + "scroll-tech/prover-stats-api/cmd/app" + "scroll-tech/prover-stats-api/internal/config" + "scroll-tech/prover-stats-api/internal/orm" ) var ( @@ -45,7 +47,7 @@ func TestProverTaskAPIs(t *testing.T) { // insert some tasks insertSomeProverTasks(t, db) - // run miner APIs + // run Prover Stats APIs app.RunMinerAPIs(db, port) t.Run("testGetProverTasksByProver", testGetProverTasksByProver) From 9bbf0f692ea8562928b12290e396e0716d79ad39 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 11:03:52 +0800 Subject: [PATCH 32/68] modify ci --- .github/workflows/prover_stats_api.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prover_stats_api.yml b/.github/workflows/prover_stats_api.yml index f65e2a6960..e8e8a802ff 100644 --- a/.github/workflows/prover_stats_api.yml +++ b/.github/workflows/prover_stats_api.yml @@ -9,7 +9,7 @@ on: - alpha paths: - 'prover-stats-api/**' - - '.github/workflows/miner_api.yml' + - '.github/workflows/prover_stats_api.yml' pull_request: types: - opened @@ -18,7 +18,7 @@ on: - ready_for_review paths: - 'prover-stats-api/**' - - '.github/workflows/miner_api.yml' + - '.github/workflows/prover_stats_api.yml' defaults: run: From e47e020ece311659dbcf4597c0076e809f8a020f Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 11:09:39 +0800 Subject: [PATCH 33/68] tidy layout --- prover-stats-api/cmd/app/app.go | 11 +++++------ prover-stats-api/{ => conf}/config.json | 0 .../{ => internal}/controller/controller.go | 4 ++-- prover-stats-api/{ => internal}/service/service.go | 0 .../{ => internal}/service/service_test.go | 2 +- prover-stats-api/test/prover_task_test.go | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-) rename prover-stats-api/{ => conf}/config.json (100%) rename prover-stats-api/{ => internal}/controller/controller.go (98%) rename prover-stats-api/{ => internal}/service/service.go (100%) rename prover-stats-api/{ => internal}/service/service_test.go (97%) diff --git a/prover-stats-api/cmd/app/app.go b/prover-stats-api/cmd/app/app.go index f3569bf953..b429c00cfd 100644 --- a/prover-stats-api/cmd/app/app.go +++ b/prover-stats-api/cmd/app/app.go @@ -5,17 +5,16 @@ import ( "os" "os/signal" + "github.com/gin-gonic/gin" "gorm.io/gorm" - "github.com/gin-gonic/gin" + "github.com/scroll-tech/go-ethereum/log" + "github.com/urfave/cli/v2" - "scroll-tech/prover-stats-api/controller" "scroll-tech/prover-stats-api/internal/config" + "scroll-tech/prover-stats-api/internal/controller" "scroll-tech/prover-stats-api/internal/orm" - "scroll-tech/prover-stats-api/service" - - "github.com/scroll-tech/go-ethereum/log" - "github.com/urfave/cli/v2" + "scroll-tech/prover-stats-api/internal/service" "scroll-tech/common/database" "scroll-tech/common/utils" diff --git a/prover-stats-api/config.json b/prover-stats-api/conf/config.json similarity index 100% rename from prover-stats-api/config.json rename to prover-stats-api/conf/config.json diff --git a/prover-stats-api/controller/controller.go b/prover-stats-api/internal/controller/controller.go similarity index 98% rename from prover-stats-api/controller/controller.go rename to prover-stats-api/internal/controller/controller.go index bf0ac0891f..8e62d9621d 100644 --- a/prover-stats-api/controller/controller.go +++ b/prover-stats-api/internal/controller/controller.go @@ -3,9 +3,9 @@ package controller import ( "net/http" - "github.com/gin-gonic/gin" + "scroll-tech/prover-stats-api/internal/service" - "scroll-tech/prover-stats-api/service" + "github.com/gin-gonic/gin" ) type ProverTaskController struct { diff --git a/prover-stats-api/service/service.go b/prover-stats-api/internal/service/service.go similarity index 100% rename from prover-stats-api/service/service.go rename to prover-stats-api/internal/service/service.go diff --git a/prover-stats-api/service/service_test.go b/prover-stats-api/internal/service/service_test.go similarity index 97% rename from prover-stats-api/service/service_test.go rename to prover-stats-api/internal/service/service_test.go index f2ccf2d2ae..bf962795eb 100644 --- a/prover-stats-api/service/service_test.go +++ b/prover-stats-api/internal/service/service_test.go @@ -56,7 +56,7 @@ func TestProverTaskService(t *testing.T) { // start database image base := docker.NewDockerApp() defer base.Free() - cfg, err := config.NewConfig("../config.json") + cfg, err := config.NewConfig("../conf/config.json") assert.NoError(t, err) cfg.DBConfig.DSN = base.DBImg.Endpoint() base.RunDBImage(t) diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index d387f043f6..9b189be002 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -36,7 +36,7 @@ func TestProverTaskAPIs(t *testing.T) { // start database image base := docker.NewDockerApp() defer base.Free() - cfg, err := config.NewConfig("../config.json") + cfg, err := config.NewConfig("../conf/config.json") assert.NoError(t, err) cfg.DBConfig.DSN = base.DBImg.Endpoint() base.RunDBImage(t) From 08d4ee292d0424e7df6c758756d1d2e241231b95 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 11:16:06 +0800 Subject: [PATCH 34/68] fix test path --- prover-stats-api/internal/service/service_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prover-stats-api/internal/service/service_test.go b/prover-stats-api/internal/service/service_test.go index bf962795eb..839a965e50 100644 --- a/prover-stats-api/internal/service/service_test.go +++ b/prover-stats-api/internal/service/service_test.go @@ -56,7 +56,7 @@ func TestProverTaskService(t *testing.T) { // start database image base := docker.NewDockerApp() defer base.Free() - cfg, err := config.NewConfig("../conf/config.json") + cfg, err := config.NewConfig("../../conf/config.json") assert.NoError(t, err) cfg.DBConfig.DSN = base.DBImg.Endpoint() base.RunDBImage(t) From cbe66b85bc84e9e9461a1ef1399a0bf3db3940fb Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 11:43:50 +0800 Subject: [PATCH 35/68] rename to logic --- prover-stats-api/cmd/app/app.go | 4 ++-- prover-stats-api/internal/controller/controller.go | 6 +++--- .../internal/{service/service.go => logic/logic.go} | 2 +- .../{service/service_test.go => logic/logic_test.go} | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename prover-stats-api/internal/{service/service.go => logic/logic.go} (98%) rename prover-stats-api/internal/{service/service_test.go => logic/logic_test.go} (99%) diff --git a/prover-stats-api/cmd/app/app.go b/prover-stats-api/cmd/app/app.go index b429c00cfd..407e86e494 100644 --- a/prover-stats-api/cmd/app/app.go +++ b/prover-stats-api/cmd/app/app.go @@ -13,8 +13,8 @@ import ( "scroll-tech/prover-stats-api/internal/config" "scroll-tech/prover-stats-api/internal/controller" + "scroll-tech/prover-stats-api/internal/logic" "scroll-tech/prover-stats-api/internal/orm" - "scroll-tech/prover-stats-api/internal/service" "scroll-tech/common/database" "scroll-tech/common/utils" @@ -77,7 +77,7 @@ func action(ctx *cli.Context) error { func RunMinerAPIs(db *gorm.DB, port string) { ptdb := orm.NewProverTask(db) - taskService := service.NewProverTaskService(ptdb) + taskService := logic.NewProverTaskService(ptdb) r := gin.Default() r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) diff --git a/prover-stats-api/internal/controller/controller.go b/prover-stats-api/internal/controller/controller.go index 8e62d9621d..b48a3fc0e6 100644 --- a/prover-stats-api/internal/controller/controller.go +++ b/prover-stats-api/internal/controller/controller.go @@ -3,17 +3,17 @@ package controller import ( "net/http" - "scroll-tech/prover-stats-api/internal/service" + "scroll-tech/prover-stats-api/internal/logic" "github.com/gin-gonic/gin" ) type ProverTaskController struct { router *gin.RouterGroup - service *service.ProverTaskService + service *logic.ProverTaskService } -func NewProverTaskController(r *gin.RouterGroup, taskService *service.ProverTaskService) *ProverTaskController { +func NewProverTaskController(r *gin.RouterGroup, taskService *logic.ProverTaskService) *ProverTaskController { router := r.Group("/prover_task") return &ProverTaskController{ router: router, diff --git a/prover-stats-api/internal/service/service.go b/prover-stats-api/internal/logic/logic.go similarity index 98% rename from prover-stats-api/internal/service/service.go rename to prover-stats-api/internal/logic/logic.go index 9d20c603ef..c35e3a24ea 100644 --- a/prover-stats-api/internal/service/service.go +++ b/prover-stats-api/internal/logic/logic.go @@ -1,4 +1,4 @@ -package service +package logic import ( "context" diff --git a/prover-stats-api/internal/service/service_test.go b/prover-stats-api/internal/logic/logic_test.go similarity index 99% rename from prover-stats-api/internal/service/service_test.go rename to prover-stats-api/internal/logic/logic_test.go index 839a965e50..b7b6ed3f0e 100644 --- a/prover-stats-api/internal/service/service_test.go +++ b/prover-stats-api/internal/logic/logic_test.go @@ -1,4 +1,4 @@ -package service +package logic import ( "context" From e67448c0126dcba580ff092e3ee9fa16ef0f3be6 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 14:35:07 +0800 Subject: [PATCH 36/68] fix ci name --- .github/workflows/prover_stats_api.yml | 2 +- prover-stats-api/internal/middleware/jwt.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 prover-stats-api/internal/middleware/jwt.go diff --git a/.github/workflows/prover_stats_api.yml b/.github/workflows/prover_stats_api.yml index e8e8a802ff..4606356c2b 100644 --- a/.github/workflows/prover_stats_api.yml +++ b/.github/workflows/prover_stats_api.yml @@ -1,4 +1,4 @@ -name: MinerAPI +name: ProverStatsAPI on: push: diff --git a/prover-stats-api/internal/middleware/jwt.go b/prover-stats-api/internal/middleware/jwt.go new file mode 100644 index 0000000000..c870d7c164 --- /dev/null +++ b/prover-stats-api/internal/middleware/jwt.go @@ -0,0 +1 @@ +package middleware From a5c50ada8df4d649df695219a37e5792d9bb1c05 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 16:04:24 +0800 Subject: [PATCH 37/68] add jwt --- prover-stats-api/cmd/app/app.go | 9 ++- prover-stats-api/conf/config.json | 3 +- prover-stats-api/go.mod | 1 + prover-stats-api/go.sum | 2 + prover-stats-api/internal/config/config.go | 3 +- .../internal/controller/controller.go | 35 +++++++--- prover-stats-api/internal/logic/logic.go | 12 ++-- prover-stats-api/internal/logic/logic_test.go | 4 +- prover-stats-api/internal/middleware/jwt.go | 66 +++++++++++++++++++ prover-stats-api/test/prover_task_test.go | 16 ++++- 10 files changed, 128 insertions(+), 23 deletions(-) diff --git a/prover-stats-api/cmd/app/app.go b/prover-stats-api/cmd/app/app.go index 407e86e494..b234752fdf 100644 --- a/prover-stats-api/cmd/app/app.go +++ b/prover-stats-api/cmd/app/app.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "os/signal" + "scroll-tech/prover-stats-api/internal/middleware" "github.com/gin-gonic/gin" "gorm.io/gorm" @@ -63,7 +64,7 @@ func action(ctx *cli.Context) error { // init Prover Stats API port := ctx.String(httpPortFlag.Name) - RunMinerAPIs(db, port) + RunMinerAPIs(db, port, cfg) // Catch CTRL-C to ensure a graceful shutdown. interrupt := make(chan os.Signal, 1) @@ -75,11 +76,13 @@ func action(ctx *cli.Context) error { return nil } -func RunMinerAPIs(db *gorm.DB, port string) { +func RunMinerAPIs(db *gorm.DB, port string, cfg *config.Config) { ptdb := orm.NewProverTask(db) - taskService := logic.NewProverTaskService(ptdb) + taskService := logic.NewProverTaskLogic(ptdb) r := gin.Default() + middleware.Secret = cfg.ApiSecret + r.Use(middleware.JWTAuthMiddleware()) r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) router := r.Group("/api/v1") diff --git a/prover-stats-api/conf/config.json b/prover-stats-api/conf/config.json index 14bb73d85a..3b4bef80f7 100644 --- a/prover-stats-api/conf/config.json +++ b/prover-stats-api/conf/config.json @@ -4,5 +4,6 @@ "dsn": "postgres://admin:123456@localhost/test?sslmode=disable", "maxOpenNum": 200, "maxIdleNum": 20 - } + }, + "api_secret": "test-api" } \ No newline at end of file diff --git a/prover-stats-api/go.mod b/prover-stats-api/go.mod index 0da1cc4089..1b4eee3f6d 100644 --- a/prover-stats-api/go.mod +++ b/prover-stats-api/go.mod @@ -16,6 +16,7 @@ require ( github.com/bytedance/sonic v1.9.2 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect diff --git a/prover-stats-api/go.sum b/prover-stats-api/go.sum index 3cea0870bf..62fe1e3314 100644 --- a/prover-stats-api/go.sum +++ b/prover-stats-api/go.sum @@ -18,6 +18,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= diff --git a/prover-stats-api/internal/config/config.go b/prover-stats-api/internal/config/config.go index 5ef2056412..00bf45390e 100644 --- a/prover-stats-api/internal/config/config.go +++ b/prover-stats-api/internal/config/config.go @@ -8,7 +8,8 @@ import ( ) type Config struct { - DBConfig *database.Config `json:"db_config"` + DBConfig *database.Config `json:"db_config"` + ApiSecret string `json:"api_secret"` } // NewConfig returns a new instance of Config. diff --git a/prover-stats-api/internal/controller/controller.go b/prover-stats-api/internal/controller/controller.go index b48a3fc0e6..ed47c8f913 100644 --- a/prover-stats-api/internal/controller/controller.go +++ b/prover-stats-api/internal/controller/controller.go @@ -2,6 +2,7 @@ package controller import ( "net/http" + "scroll-tech/prover-stats-api/internal/middleware" "scroll-tech/prover-stats-api/internal/logic" @@ -9,24 +10,42 @@ import ( ) type ProverTaskController struct { - router *gin.RouterGroup - service *logic.ProverTaskService + router *gin.RouterGroup + logic *logic.ProverTaskLogic } -func NewProverTaskController(r *gin.RouterGroup, taskService *logic.ProverTaskService) *ProverTaskController { +func NewProverTaskController(r *gin.RouterGroup, taskLogic *logic.ProverTaskLogic) *ProverTaskController { router := r.Group("/prover_task") return &ProverTaskController{ - router: router, - service: taskService, + router: router, + logic: taskLogic, } } func (c *ProverTaskController) Route() { + c.router.GET("/request_token", c.RequestToken) c.router.GET("/tasks", c.GetTasksByProver) c.router.GET("/total_rewards", c.GetTotalRewards) c.router.GET("/task", c.GetTask) } +// RequestToken godoc +// @Summary request token +// @Description generate token for the client +// @Tags prover_task +// @Produce json +// @Success 200 {object} string +// @Failure 401 {object} string +// @Router /prover_task/request_token [get] +func (c *ProverTaskController) RequestToken(ctx *gin.Context) { + token, err := middleware.GenToken() + if err != nil { + ctx.String(http.StatusBadRequest, err.Error()) + return + } + ctx.JSON(http.StatusOK, gin.H{"token": token}) +} + // GetTasksByProver godoc // @Summary give the proverTasks // @Description get []*ProverTask by prover public key @@ -40,7 +59,7 @@ func (c *ProverTaskController) Route() { // @Router /prover_task/tasks/{pubkey} [get] func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) { pubkey := ctx.Query("pubkey") - tasks, err := c.service.GetTasksByProver(pubkey) + tasks, err := c.logic.GetTasksByProver(pubkey) if err != nil { ctx.String(http.StatusNotFound, err.Error()) return @@ -61,7 +80,7 @@ func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) { // @Router /prover_task/total_rewards/{pubkey} [get] func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { pubkey := ctx.Query("pubkey") - rewards, err := c.service.GetTotalRewards(pubkey) + rewards, err := c.logic.GetTotalRewards(pubkey) if err != nil { ctx.String(http.StatusNotFound, err.Error()) return @@ -82,7 +101,7 @@ func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { // @Router /prover_task/task/{task_id} [get] func (c *ProverTaskController) GetTask(ctx *gin.Context) { taskID := ctx.Query("task_id") - task, err := c.service.GetTask(taskID) + task, err := c.logic.GetTask(taskID) if err != nil { ctx.String(http.StatusNotFound, err.Error()) return diff --git a/prover-stats-api/internal/logic/logic.go b/prover-stats-api/internal/logic/logic.go index c35e3a24ea..b6a76f90c1 100644 --- a/prover-stats-api/internal/logic/logic.go +++ b/prover-stats-api/internal/logic/logic.go @@ -7,19 +7,19 @@ import ( "scroll-tech/prover-stats-api/internal/orm" ) -type ProverTaskService struct { +type ProverTaskLogic struct { db *orm.ProverTask } -func NewProverTaskService(db *orm.ProverTask) *ProverTaskService { - return &ProverTaskService{db: db} +func NewProverTaskLogic(db *orm.ProverTask) *ProverTaskLogic { + return &ProverTaskLogic{db: db} } -func (p *ProverTaskService) GetTasksByProver(pubkey string) ([]*orm.ProverTask, error) { +func (p *ProverTaskLogic) GetTasksByProver(pubkey string) ([]*orm.ProverTask, error) { return p.db.GetProverTasksByProver(context.Background(), pubkey) } -func (p *ProverTaskService) GetTotalRewards(pubkey string) (*big.Int, error) { +func (p *ProverTaskLogic) GetTotalRewards(pubkey string) (*big.Int, error) { tasks, err := p.db.GetProverTasksByProver(context.Background(), pubkey) if err != nil { return nil, err @@ -31,7 +31,7 @@ func (p *ProverTaskService) GetTotalRewards(pubkey string) (*big.Int, error) { return rewards, nil } -func (p *ProverTaskService) GetTask(taskID string) (*orm.ProverTask, error) { +func (p *ProverTaskLogic) GetTask(taskID string) (*orm.ProverTask, error) { tasks, err := p.db.GetProverTasksByHashes(context.Background(), []string{taskID}) if err != nil { return nil, err diff --git a/prover-stats-api/internal/logic/logic_test.go b/prover-stats-api/internal/logic/logic_test.go index b7b6ed3f0e..08c2a7e00c 100644 --- a/prover-stats-api/internal/logic/logic_test.go +++ b/prover-stats-api/internal/logic/logic_test.go @@ -36,7 +36,7 @@ var ( Reward: decimal.NewFromInt(12), } - service *ProverTaskService + service *ProverTaskLogic ) func insertSomeProverTasks(t *testing.T, db *gorm.DB) { @@ -68,7 +68,7 @@ func TestProverTaskService(t *testing.T) { insertSomeProverTasks(t, db) ptdb := orm.NewProverTask(db) - service = NewProverTaskService(ptdb) + service = NewProverTaskLogic(ptdb) t.Run("testGetTasksByProver", testGetTasksByProver) t.Run("testGetTotalRewards", testGetTotalRewards) diff --git a/prover-stats-api/internal/middleware/jwt.go b/prover-stats-api/internal/middleware/jwt.go index c870d7c164..922c6cfd96 100644 --- a/prover-stats-api/internal/middleware/jwt.go +++ b/prover-stats-api/internal/middleware/jwt.go @@ -1 +1,67 @@ package middleware + +import ( + "errors" + "fmt" + "github.com/dgrijalva/jwt-go" + "github.com/gin-gonic/gin" + "net/http" + "time" +) + +const TokenExpireDuration = time.Minute * 10 + +var ( + Secret string + skipPaths = []string{"/request_token"} +) + +type ApiClaims struct { + jwt.StandardClaims +} + +func GenToken() (string, error) { + c := ApiClaims{ + jwt.StandardClaims{ + ExpiresAt: time.Now().Add(TokenExpireDuration).Unix(), + }, + } + token := jwt.NewWithClaims(jwt.SigningMethodHS256, c) + return token.SignedString(Secret) +} + +func ParseToken(tokenStr string) (*ApiClaims, error) { + token, err := jwt.ParseWithClaims(tokenStr, &ApiClaims{}, func(token *jwt.Token) (interface{}, error) { + return Secret, nil + }) + if err != nil { + return nil, err + } + if claims, ok := token.Claims.(*ApiClaims); ok && token.Valid { + return claims, nil + } + return nil, errors.New("invalid token") +} + +func JWTAuthMiddleware() gin.HandlerFunc { + return func(c *gin.Context) { + for _, path := range skipPaths { + if path == c.FullPath() { + c.Next() + return + } + } + tokenString := c.Request.Header.Get("Authorization") + if tokenString == "" { + c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Null token"}) + return + } + + _, err := ParseToken(tokenString) + if err != nil { + c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": fmt.Sprintf("Unauthorized: %v", err)}) + return + } + c.Next() + } +} diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index 9b189be002..10a4484fb4 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -30,6 +30,7 @@ var ( port = ":12990" addr = fmt.Sprintf("http://localhost%s", port) basicPath = fmt.Sprintf("%s/api/v1/prover_task", addr) + token string ) func TestProverTaskAPIs(t *testing.T) { @@ -48,13 +49,20 @@ func TestProverTaskAPIs(t *testing.T) { insertSomeProverTasks(t, db) // run Prover Stats APIs - app.RunMinerAPIs(db, port) + app.RunMinerAPIs(db, port, cfg) + t.Run("testRequestToken", testRequestToken) t.Run("testGetProverTasksByProver", testGetProverTasksByProver) t.Run("testGetTotalRewards", testGetTotalRewards) t.Run("testGetProverTask", testGetProverTask) } +func testRequestToken(t *testing.T) { + var tokenMap map[string]string + getResp(t, fmt.Sprintf("%s/request_token", basicPath), &tokenMap) + token = tokenMap["token"] +} + func testGetProverTasksByProver(t *testing.T) { var tasks []*orm.ProverTask getResp(t, fmt.Sprintf("%s/tasks?pubkey=%s", basicPath, proverPubkey), &tasks) @@ -75,7 +83,11 @@ func testGetProverTask(t *testing.T) { } func getResp(t *testing.T, url string, value interface{}) { - resp, err := http.Get(url) + req, err := http.NewRequest(http.MethodGet, url, nil) + assert.NoError(t, err) + req.Header.Set("Authorization", token) + + resp, err := http.DefaultClient.Do(req) assert.NoError(t, err) assert.Equal(t, resp.StatusCode, http.StatusOK) byt, err := io.ReadAll(resp.Body) From c1bf3c17e10b8ac66816c13556e94d951a7e45e8 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 16:12:48 +0800 Subject: [PATCH 38/68] fix skip paths --- prover-stats-api/internal/middleware/jwt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prover-stats-api/internal/middleware/jwt.go b/prover-stats-api/internal/middleware/jwt.go index 922c6cfd96..772bb8232d 100644 --- a/prover-stats-api/internal/middleware/jwt.go +++ b/prover-stats-api/internal/middleware/jwt.go @@ -13,7 +13,7 @@ const TokenExpireDuration = time.Minute * 10 var ( Secret string - skipPaths = []string{"/request_token"} + skipPaths = []string{"/api/v1/prover_task/request_token"} ) type ApiClaims struct { From 30171c2958c89df618e56ef5bc9157b1858dc9a2 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 16:17:50 +0800 Subject: [PATCH 39/68] debug --- prover-stats-api/test/prover_task_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index 10a4484fb4..6261cb30c3 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -89,7 +89,7 @@ func getResp(t *testing.T, url string, value interface{}) { resp, err := http.DefaultClient.Do(req) assert.NoError(t, err) - assert.Equal(t, resp.StatusCode, http.StatusOK) + assert.Equal(t, resp.StatusCode, http.StatusOK, err.Error()) byt, err := io.ReadAll(resp.Body) assert.NoError(t, err) err = json.Unmarshal(byt, value) From 10ab92ae348a2f4ed491d24625a0a3bc35249b50 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 16:20:58 +0800 Subject: [PATCH 40/68] trigger ci From 60f0ed9a7c478e36c908c1d7f9192cf2b8cfe5fe Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 17:34:20 +0800 Subject: [PATCH 41/68] fix tests --- prover-stats-api/cmd/app/app.go | 1 + prover-stats-api/internal/controller/controller.go | 1 + prover-stats-api/internal/middleware/jwt.go | 9 +++++---- prover-stats-api/test/prover_task_test.go | 11 ++++++----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/prover-stats-api/cmd/app/app.go b/prover-stats-api/cmd/app/app.go index b234752fdf..48052308f7 100644 --- a/prover-stats-api/cmd/app/app.go +++ b/prover-stats-api/cmd/app/app.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "os/signal" + "scroll-tech/prover-stats-api/internal/middleware" "github.com/gin-gonic/gin" diff --git a/prover-stats-api/internal/controller/controller.go b/prover-stats-api/internal/controller/controller.go index ed47c8f913..7e7269c9b6 100644 --- a/prover-stats-api/internal/controller/controller.go +++ b/prover-stats-api/internal/controller/controller.go @@ -2,6 +2,7 @@ package controller import ( "net/http" + "scroll-tech/prover-stats-api/internal/middleware" "scroll-tech/prover-stats-api/internal/logic" diff --git a/prover-stats-api/internal/middleware/jwt.go b/prover-stats-api/internal/middleware/jwt.go index 772bb8232d..aa13f26539 100644 --- a/prover-stats-api/internal/middleware/jwt.go +++ b/prover-stats-api/internal/middleware/jwt.go @@ -3,10 +3,11 @@ package middleware import ( "errors" "fmt" - "github.com/dgrijalva/jwt-go" - "github.com/gin-gonic/gin" "net/http" "time" + + "github.com/dgrijalva/jwt-go" + "github.com/gin-gonic/gin" ) const TokenExpireDuration = time.Minute * 10 @@ -27,12 +28,12 @@ func GenToken() (string, error) { }, } token := jwt.NewWithClaims(jwt.SigningMethodHS256, c) - return token.SignedString(Secret) + return token.SignedString([]byte(Secret)) } func ParseToken(tokenStr string) (*ApiClaims, error) { token, err := jwt.ParseWithClaims(tokenStr, &ApiClaims{}, func(token *jwt.Token) (interface{}, error) { - return Secret, nil + return []byte(Secret), nil }) if err != nil { return nil, err diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index 6261cb30c3..48257a3428 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -58,9 +58,10 @@ func TestProverTaskAPIs(t *testing.T) { } func testRequestToken(t *testing.T) { - var tokenMap map[string]string + tokenMap := make(map[string]string) getResp(t, fmt.Sprintf("%s/request_token", basicPath), &tokenMap) token = tokenMap["token"] + t.Log("token: ", token) } func testGetProverTasksByProver(t *testing.T) { @@ -85,15 +86,15 @@ func testGetProverTask(t *testing.T) { func getResp(t *testing.T, url string, value interface{}) { req, err := http.NewRequest(http.MethodGet, url, nil) assert.NoError(t, err) - req.Header.Set("Authorization", token) + req.Header.Add("Authorization", token) resp, err := http.DefaultClient.Do(req) assert.NoError(t, err) - assert.Equal(t, resp.StatusCode, http.StatusOK, err.Error()) + assert.Equal(t, resp.StatusCode, http.StatusOK) + byt, err := io.ReadAll(resp.Body) assert.NoError(t, err) - err = json.Unmarshal(byt, value) - assert.NoError(t, err) + assert.NoError(t, json.Unmarshal(byt, value)) } var ( From c8ef6a17784d1ab867ae1993c73d7f2c20f9f28a Mon Sep 17 00:00:00 2001 From: xinran chen Date: Thu, 13 Jul 2023 17:56:54 +0800 Subject: [PATCH 42/68] add metrics --- prover-stats-api/cmd/app/app.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/prover-stats-api/cmd/app/app.go b/prover-stats-api/cmd/app/app.go index 48052308f7..b86814c503 100644 --- a/prover-stats-api/cmd/app/app.go +++ b/prover-stats-api/cmd/app/app.go @@ -1,9 +1,11 @@ package app import ( + "context" "fmt" "os" "os/signal" + "scroll-tech/common/metrics" "scroll-tech/prover-stats-api/internal/middleware" @@ -63,10 +65,19 @@ func action(ctx *cli.Context) error { } }() + subCtx, cancel := context.WithCancel(ctx.Context) + // init Prover Stats API port := ctx.String(httpPortFlag.Name) RunMinerAPIs(db, port, cfg) + defer func() { + cancel() + }() + + // Start metrics server. + metrics.Serve(subCtx, ctx) + // Catch CTRL-C to ensure a graceful shutdown. interrupt := make(chan os.Signal, 1) signal.Notify(interrupt, os.Interrupt) From 28d61aaf6a285b4643702a1b2d03c0a1d667fce8 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Fri, 14 Jul 2023 10:17:32 +0800 Subject: [PATCH 43/68] fix go mod tidy --- .github/workflows/prover_stats_api.yml | 12 ++++----- prover-stats-api/go.mod | 25 ++++++++--------- prover-stats-api/go.sum | 37 +++++++------------------- 3 files changed, 28 insertions(+), 46 deletions(-) diff --git a/.github/workflows/prover_stats_api.yml b/.github/workflows/prover_stats_api.yml index 4606356c2b..2550d78f7c 100644 --- a/.github/workflows/prover_stats_api.yml +++ b/.github/workflows/prover_stats_api.yml @@ -71,10 +71,10 @@ jobs: - name: Install goimports run: go install golang.org/x/tools/cmd/goimports - run: goimports -local scroll-tech/prover-stats-api/ -w . - # - run: go mod tidy + - run: go mod tidy # If there are any diffs from goimports or go mod tidy, fail. -# - name: Verify no changes from goimports and go mod tidy -# run: | -# if [ -n "$(git status --porcelain)" ]; then -# exit 1 -# fi + - name: Verify no changes from goimports and go mod tidy + run: | + if [ -n "$(git status --porcelain)" ]; then + exit 1 + fi diff --git a/prover-stats-api/go.mod b/prover-stats-api/go.mod index 1b4eee3f6d..a90fddd2d1 100644 --- a/prover-stats-api/go.mod +++ b/prover-stats-api/go.mod @@ -4,19 +4,22 @@ go 1.19 require ( github.com/gin-gonic/gin v1.9.1 + github.com/stretchr/testify v1.8.3 gorm.io/gorm v1.25.2 ) -replace github.com/ethereum/go-ethereum/log => github.com/scroll-tech/go-ethereum v1.10.26 // indirect +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/go-stack/stack v1.8.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect +) require ( github.com/KyleBanks/depth v1.2.1 // indirect - github.com/PuerkitoBio/purell v1.2.0 // indirect - github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/bytedance/sonic v1.9.2 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect - github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect + github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect @@ -39,14 +42,14 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/shopspring/decimal v1.3.1 // indirect - github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect - github.com/swaggo/files v1.0.1 // indirect - github.com/swaggo/gin-swagger v1.6.0 // indirect - github.com/swaggo/swag v1.16.1 // indirect + github.com/scroll-tech/go-ethereum v1.10.14-0.20230613025759-f055f50f9d56 + github.com/shopspring/decimal v1.3.1 + github.com/swaggo/files v1.0.1 + github.com/swaggo/gin-swagger v1.6.0 + github.com/swaggo/swag v1.16.1 github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect - github.com/urfave/cli/v2 v2.25.7 // indirect + github.com/urfave/cli/v2 v2.25.7 github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/arch v0.4.0 // indirect golang.org/x/crypto v0.11.0 // indirect @@ -55,7 +58,5 @@ require ( golang.org/x/text v0.11.0 // indirect golang.org/x/tools v0.11.0 // indirect google.golang.org/protobuf v1.31.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/prover-stats-api/go.sum b/prover-stats-api/go.sum index 62fe1e3314..f1f50c2d43 100644 --- a/prover-stats-api/go.sum +++ b/prover-stats-api/go.sum @@ -1,12 +1,6 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= -github.com/PuerkitoBio/purell v1.2.0 h1:/Jdm5QfyM8zdlqT6WVZU4cfP23sot6CEHA4CS49Ezig= -github.com/PuerkitoBio/purell v1.2.0/go.mod h1:OhLRTaaIzhvIyofkJfB24gokC7tM42Px5UhoT32THBk= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= -github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/bytedance/sonic v1.9.2 h1:GDaNjuWSGu09guE9Oql0MSTNhNCLlWwO8y/xM5BzcbM= github.com/bytedance/sonic v1.9.2/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= @@ -22,6 +16,7 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumC github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= @@ -45,10 +40,10 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= -github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k= github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= @@ -64,14 +59,14 @@ github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFF github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= -github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= @@ -94,10 +89,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/scroll-tech/go-ethereum v1.10.14-0.20230613025759-f055f50f9d56 h1:Cqj7haxwvzI2O4n9ZZ25helShzFGCy7Z/B+FFSBFHNI= +github.com/scroll-tech/go-ethereum v1.10.14-0.20230613025759-f055f50f9d56/go.mod h1:45PZqlQCqV0dU4o4+SE8LoJLEvXkK5j45ligvbih9QY= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -126,23 +121,18 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRT github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= -golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc= golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -151,12 +141,9 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/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 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -166,8 +153,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -179,14 +164,12 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= @@ -198,5 +181,3 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho= gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= From 1f7b698c54afff8c65e7128fe91fa97b78b736de Mon Sep 17 00:00:00 2001 From: xinran chen Date: Fri, 14 Jul 2023 10:43:36 +0800 Subject: [PATCH 44/68] fix --- prover-stats-api/internal/controller/route.go | 1 + 1 file changed, 1 insertion(+) create mode 100644 prover-stats-api/internal/controller/route.go diff --git a/prover-stats-api/internal/controller/route.go b/prover-stats-api/internal/controller/route.go new file mode 100644 index 0000000000..b0b429f899 --- /dev/null +++ b/prover-stats-api/internal/controller/route.go @@ -0,0 +1 @@ +package controller From b5195b7c8249926171d24ee0bd75633921a90fb8 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Fri, 14 Jul 2023 10:44:30 +0800 Subject: [PATCH 45/68] fix --- prover-stats-api/cmd/app/app.go | 36 ++----------------- prover-stats-api/internal/controller/route.go | 27 ++++++++++++++ prover-stats-api/internal/logic/logic.go | 5 +-- prover-stats-api/test/prover_task_test.go | 4 +-- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/prover-stats-api/cmd/app/app.go b/prover-stats-api/cmd/app/app.go index b86814c503..43a116876e 100644 --- a/prover-stats-api/cmd/app/app.go +++ b/prover-stats-api/cmd/app/app.go @@ -7,27 +7,15 @@ import ( "os/signal" "scroll-tech/common/metrics" - "scroll-tech/prover-stats-api/internal/middleware" - - "github.com/gin-gonic/gin" - "gorm.io/gorm" - "github.com/scroll-tech/go-ethereum/log" "github.com/urfave/cli/v2" - "scroll-tech/prover-stats-api/internal/config" - "scroll-tech/prover-stats-api/internal/controller" - "scroll-tech/prover-stats-api/internal/logic" - "scroll-tech/prover-stats-api/internal/orm" - "scroll-tech/common/database" "scroll-tech/common/utils" "scroll-tech/common/version" - _ "scroll-tech/prover-stats-api/cmd/docs" - - swaggerfiles "github.com/swaggo/files" - ginSwagger "github.com/swaggo/gin-swagger" + "scroll-tech/prover-stats-api/internal/config" + "scroll-tech/prover-stats-api/internal/controller" ) var app *cli.App @@ -69,7 +57,7 @@ func action(ctx *cli.Context) error { // init Prover Stats API port := ctx.String(httpPortFlag.Name) - RunMinerAPIs(db, port, cfg) + controller.Route(db, port, cfg) defer func() { cancel() @@ -88,24 +76,6 @@ func action(ctx *cli.Context) error { return nil } -func RunMinerAPIs(db *gorm.DB, port string, cfg *config.Config) { - ptdb := orm.NewProverTask(db) - taskService := logic.NewProverTaskLogic(ptdb) - - r := gin.Default() - middleware.Secret = cfg.ApiSecret - r.Use(middleware.JWTAuthMiddleware()) - r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) - router := r.Group("/api/v1") - - c := controller.NewProverTaskController(router, taskService) - c.Route() - - go func() { - r.Run(port) - }() -} - // Run run prover-stats-api. func Run() { // RunApp the prover-stats-api. diff --git a/prover-stats-api/internal/controller/route.go b/prover-stats-api/internal/controller/route.go index b0b429f899..7dacef500b 100644 --- a/prover-stats-api/internal/controller/route.go +++ b/prover-stats-api/internal/controller/route.go @@ -1 +1,28 @@ package controller + +import ( + "github.com/gin-gonic/gin" + swaggerfiles "github.com/swaggo/files" + ginSwagger "github.com/swaggo/gin-swagger" + "gorm.io/gorm" + "scroll-tech/prover-stats-api/internal/config" + "scroll-tech/prover-stats-api/internal/logic" + "scroll-tech/prover-stats-api/internal/middleware" +) + +func Route(db *gorm.DB, port string, cfg *config.Config) { + taskService := logic.NewProverTaskLogic(db) + + r := gin.Default() + middleware.Secret = cfg.ApiSecret + r.Use(middleware.JWTAuthMiddleware()) + r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) + router := r.Group("/api/v1") + + c := NewProverTaskController(router, taskService) + c.Route() + + go func() { + r.Run(port) + }() +} diff --git a/prover-stats-api/internal/logic/logic.go b/prover-stats-api/internal/logic/logic.go index b6a76f90c1..727a268a4a 100644 --- a/prover-stats-api/internal/logic/logic.go +++ b/prover-stats-api/internal/logic/logic.go @@ -2,6 +2,7 @@ package logic import ( "context" + "gorm.io/gorm" "math/big" "scroll-tech/prover-stats-api/internal/orm" @@ -11,8 +12,8 @@ type ProverTaskLogic struct { db *orm.ProverTask } -func NewProverTaskLogic(db *orm.ProverTask) *ProverTaskLogic { - return &ProverTaskLogic{db: db} +func NewProverTaskLogic(db *gorm.DB) *ProverTaskLogic { + return &ProverTaskLogic{db: orm.NewProverTask(db)} } func (p *ProverTaskLogic) GetTasksByProver(pubkey string) ([]*orm.ProverTask, error) { diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index 48257a3428..f2db33cf4e 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -11,13 +11,13 @@ import ( "scroll-tech/common/docker" "scroll-tech/common/types" "scroll-tech/database/migrate" + "scroll-tech/prover-stats-api/internal/controller" "testing" "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" "gorm.io/gorm" - "scroll-tech/prover-stats-api/cmd/app" "scroll-tech/prover-stats-api/internal/config" "scroll-tech/prover-stats-api/internal/orm" ) @@ -49,7 +49,7 @@ func TestProverTaskAPIs(t *testing.T) { insertSomeProverTasks(t, db) // run Prover Stats APIs - app.RunMinerAPIs(db, port, cfg) + controller.Route(db, port, cfg) t.Run("testRequestToken", testRequestToken) t.Run("testGetProverTasksByProver", testGetProverTasksByProver) From c850e77773969d36a51d569ef8eaf8ce608cde98 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Fri, 14 Jul 2023 10:48:49 +0800 Subject: [PATCH 46/68] fix test --- prover-stats-api/internal/logic/logic_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/prover-stats-api/internal/logic/logic_test.go b/prover-stats-api/internal/logic/logic_test.go index 08c2a7e00c..9dc6ef59db 100644 --- a/prover-stats-api/internal/logic/logic_test.go +++ b/prover-stats-api/internal/logic/logic_test.go @@ -67,8 +67,7 @@ func TestProverTaskService(t *testing.T) { // insert some tasks insertSomeProverTasks(t, db) - ptdb := orm.NewProverTask(db) - service = NewProverTaskLogic(ptdb) + service = NewProverTaskLogic(db) t.Run("testGetTasksByProver", testGetTasksByProver) t.Run("testGetTotalRewards", testGetTotalRewards) From 3332ef34161ac941c2cff1fa238dfa7b5654b871 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Fri, 14 Jul 2023 10:54:01 +0800 Subject: [PATCH 47/68] fix lint --- prover-stats-api/cmd/app/app.go | 1 + prover-stats-api/internal/controller/route.go | 1 + prover-stats-api/internal/logic/logic.go | 3 ++- prover-stats-api/test/prover_task_test.go | 3 ++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/prover-stats-api/cmd/app/app.go b/prover-stats-api/cmd/app/app.go index 43a116876e..0c001f39f7 100644 --- a/prover-stats-api/cmd/app/app.go +++ b/prover-stats-api/cmd/app/app.go @@ -13,6 +13,7 @@ import ( "scroll-tech/common/database" "scroll-tech/common/utils" "scroll-tech/common/version" + _ "scroll-tech/prover-stats-api/cmd/docs" "scroll-tech/prover-stats-api/internal/config" "scroll-tech/prover-stats-api/internal/controller" diff --git a/prover-stats-api/internal/controller/route.go b/prover-stats-api/internal/controller/route.go index 7dacef500b..2bb8d65bce 100644 --- a/prover-stats-api/internal/controller/route.go +++ b/prover-stats-api/internal/controller/route.go @@ -5,6 +5,7 @@ import ( swaggerfiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" "gorm.io/gorm" + "scroll-tech/prover-stats-api/internal/config" "scroll-tech/prover-stats-api/internal/logic" "scroll-tech/prover-stats-api/internal/middleware" diff --git a/prover-stats-api/internal/logic/logic.go b/prover-stats-api/internal/logic/logic.go index 727a268a4a..d09807deda 100644 --- a/prover-stats-api/internal/logic/logic.go +++ b/prover-stats-api/internal/logic/logic.go @@ -2,9 +2,10 @@ package logic import ( "context" - "gorm.io/gorm" "math/big" + "gorm.io/gorm" + "scroll-tech/prover-stats-api/internal/orm" ) diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index f2db33cf4e..96fce1b214 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -11,9 +11,10 @@ import ( "scroll-tech/common/docker" "scroll-tech/common/types" "scroll-tech/database/migrate" - "scroll-tech/prover-stats-api/internal/controller" "testing" + "scroll-tech/prover-stats-api/internal/controller" + "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" "gorm.io/gorm" From a7b3c07e6b706e305ec9a5728c9744057f48341d Mon Sep 17 00:00:00 2001 From: xinran chen Date: Mon, 17 Jul 2023 10:19:56 +0800 Subject: [PATCH 48/68] wrap resp --- .../internal/controller/controller.go | 17 ++++++------- prover-stats-api/internal/controller/types.go | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 prover-stats-api/internal/controller/types.go diff --git a/prover-stats-api/internal/controller/controller.go b/prover-stats-api/internal/controller/controller.go index 7e7269c9b6..8e9b88c432 100644 --- a/prover-stats-api/internal/controller/controller.go +++ b/prover-stats-api/internal/controller/controller.go @@ -41,10 +41,10 @@ func (c *ProverTaskController) Route() { func (c *ProverTaskController) RequestToken(ctx *gin.Context) { token, err := middleware.GenToken() if err != nil { - ctx.String(http.StatusBadRequest, err.Error()) + ctx.JSON(http.StatusOK, Err(err)) return } - ctx.JSON(http.StatusOK, gin.H{"token": token}) + ctx.JSON(http.StatusOK, Ok(token)) } // GetTasksByProver godoc @@ -62,10 +62,10 @@ func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) { pubkey := ctx.Query("pubkey") tasks, err := c.logic.GetTasksByProver(pubkey) if err != nil { - ctx.String(http.StatusNotFound, err.Error()) + ctx.JSON(http.StatusOK, Err(err)) return } - ctx.JSON(http.StatusOK, tasks) + ctx.JSON(http.StatusOK, Ok(tasks)) } // GetTotalRewards godoc @@ -83,10 +83,10 @@ func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { pubkey := ctx.Query("pubkey") rewards, err := c.logic.GetTotalRewards(pubkey) if err != nil { - ctx.String(http.StatusNotFound, err.Error()) + ctx.JSON(http.StatusOK, Err(err)) return } - ctx.JSON(http.StatusOK, gin.H{"rewards": rewards}) + ctx.JSON(http.StatusOK, Ok(rewards)) } // GetTask godoc @@ -97,15 +97,14 @@ func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { // @Produce json // @Param task_id path string true "prover task hash" // @Success 200 {object} *orm.ProverTask -// @Failure 404 {object} string // @Failure 500 {object} string // @Router /prover_task/task/{task_id} [get] func (c *ProverTaskController) GetTask(ctx *gin.Context) { taskID := ctx.Query("task_id") task, err := c.logic.GetTask(taskID) if err != nil { - ctx.String(http.StatusNotFound, err.Error()) + ctx.JSON(http.StatusOK, Err(err)) return } - ctx.JSON(http.StatusOK, task) + ctx.JSON(http.StatusOK, Ok(task)) } diff --git a/prover-stats-api/internal/controller/types.go b/prover-stats-api/internal/controller/types.go new file mode 100644 index 0000000000..7093675296 --- /dev/null +++ b/prover-stats-api/internal/controller/types.go @@ -0,0 +1,25 @@ +package controller + +type Resp struct { + Code int `json:"code"` + Object any `json:"object"` +} + +const ( + OK = 1000 + ERR = 1001 +) + +func Ok(obj any) *Resp { + return &Resp{ + Code: OK, + Object: obj, + } +} + +func Err(obj any) *Resp { + return &Resp{ + Code: ERR, + Object: obj, + } +} From 7d2d922d842aa5c2257e3f328160f7ee38d94625 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Mon, 17 Jul 2023 11:03:28 +0800 Subject: [PATCH 49/68] fix test --- .../internal/controller/controller.go | 19 +++++++++++---- prover-stats-api/internal/controller/types.go | 13 +++++----- prover-stats-api/test/prover_task_test.go | 24 +++++++++++-------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/prover-stats-api/internal/controller/controller.go b/prover-stats-api/internal/controller/controller.go index 8e9b88c432..1ae890a6b2 100644 --- a/prover-stats-api/internal/controller/controller.go +++ b/prover-stats-api/internal/controller/controller.go @@ -1,6 +1,7 @@ package controller import ( + "encoding/json" "net/http" "scroll-tech/prover-stats-api/internal/middleware" @@ -44,7 +45,7 @@ func (c *ProverTaskController) RequestToken(ctx *gin.Context) { ctx.JSON(http.StatusOK, Err(err)) return } - ctx.JSON(http.StatusOK, Ok(token)) + ctx.JSON(http.StatusOK, Ok([]byte(token))) } // GetTasksByProver godoc @@ -65,7 +66,12 @@ func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) { ctx.JSON(http.StatusOK, Err(err)) return } - ctx.JSON(http.StatusOK, Ok(tasks)) + byt, err := json.Marshal(tasks) + if err != nil { + ctx.JSON(http.StatusInternalServerError, Err(err)) + return + } + ctx.JSON(http.StatusOK, Ok(byt)) } // GetTotalRewards godoc @@ -86,7 +92,7 @@ func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { ctx.JSON(http.StatusOK, Err(err)) return } - ctx.JSON(http.StatusOK, Ok(rewards)) + ctx.JSON(http.StatusOK, Ok(rewards.Bytes())) } // GetTask godoc @@ -106,5 +112,10 @@ func (c *ProverTaskController) GetTask(ctx *gin.Context) { ctx.JSON(http.StatusOK, Err(err)) return } - ctx.JSON(http.StatusOK, Ok(task)) + byt, err := json.Marshal(task) + if err != nil { + ctx.JSON(http.StatusInternalServerError, Err(err)) + return + } + ctx.JSON(http.StatusOK, Ok(byt)) } diff --git a/prover-stats-api/internal/controller/types.go b/prover-stats-api/internal/controller/types.go index 7093675296..297546c643 100644 --- a/prover-stats-api/internal/controller/types.go +++ b/prover-stats-api/internal/controller/types.go @@ -1,8 +1,9 @@ package controller type Resp struct { - Code int `json:"code"` - Object any `json:"object"` + Code int `json:"code"` + Object []byte `json:"object"` + Error error `json:"error"` } const ( @@ -10,16 +11,16 @@ const ( ERR = 1001 ) -func Ok(obj any) *Resp { +func Ok(obj []byte) *Resp { return &Resp{ Code: OK, Object: obj, } } -func Err(obj any) *Resp { +func Err(err error) *Resp { return &Resp{ - Code: ERR, - Object: obj, + Code: ERR, + Error: err, } } diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index 96fce1b214..dfe3e7f95b 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -59,32 +59,32 @@ func TestProverTaskAPIs(t *testing.T) { } func testRequestToken(t *testing.T) { - tokenMap := make(map[string]string) - getResp(t, fmt.Sprintf("%s/request_token", basicPath), &tokenMap) - token = tokenMap["token"] + tokenByt := getResp(t, fmt.Sprintf("%s/request_token", basicPath)) + token = string(tokenByt) t.Log("token: ", token) } func testGetProverTasksByProver(t *testing.T) { var tasks []*orm.ProverTask - getResp(t, fmt.Sprintf("%s/tasks?pubkey=%s", basicPath, proverPubkey), &tasks) + byt := getResp(t, fmt.Sprintf("%s/tasks?pubkey=%s", basicPath, proverPubkey)) + assert.NoError(t, json.Unmarshal(byt, &tasks)) assert.Equal(t, task2.TaskID, tasks[0].TaskID) assert.Equal(t, task1.TaskID, tasks[1].TaskID) } func testGetTotalRewards(t *testing.T) { - rewards := make(map[string]*big.Int) - getResp(t, fmt.Sprintf("%s/total_rewards?pubkey=%s", basicPath, proverPubkey), &rewards) - assert.Equal(t, big.NewInt(22), rewards["rewards"]) + rewards := getResp(t, fmt.Sprintf("%s/total_rewards?pubkey=%s", basicPath, proverPubkey)) + assert.Equal(t, big.NewInt(22), new(big.Int).SetBytes(rewards)) } func testGetProverTask(t *testing.T) { var task orm.ProverTask - getResp(t, fmt.Sprintf("%s/task?task_id=1", basicPath), &task) + byt := getResp(t, fmt.Sprintf("%s/task?task_id=1", basicPath)) + assert.NoError(t, json.Unmarshal(byt, &task)) assert.Equal(t, task1.TaskID, task.TaskID) } -func getResp(t *testing.T, url string, value interface{}) { +func getResp(t *testing.T, url string) []byte { req, err := http.NewRequest(http.MethodGet, url, nil) assert.NoError(t, err) req.Header.Add("Authorization", token) @@ -95,7 +95,11 @@ func getResp(t *testing.T, url string, value interface{}) { byt, err := io.ReadAll(resp.Body) assert.NoError(t, err) - assert.NoError(t, json.Unmarshal(byt, value)) + + res := new(controller.Resp) + assert.NoError(t, json.Unmarshal(byt, res)) + assert.Equal(t, controller.OK, res.Code) + return res.Object } var ( From d3af1cdcf3741647806ddd67d2531140794662d8 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Mon, 17 Jul 2023 11:15:20 +0800 Subject: [PATCH 50/68] statusOK --- prover-stats-api/internal/controller/controller.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prover-stats-api/internal/controller/controller.go b/prover-stats-api/internal/controller/controller.go index 1ae890a6b2..61f5d699a3 100644 --- a/prover-stats-api/internal/controller/controller.go +++ b/prover-stats-api/internal/controller/controller.go @@ -68,7 +68,7 @@ func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) { } byt, err := json.Marshal(tasks) if err != nil { - ctx.JSON(http.StatusInternalServerError, Err(err)) + ctx.JSON(http.StatusOK, Err(err)) return } ctx.JSON(http.StatusOK, Ok(byt)) @@ -114,7 +114,7 @@ func (c *ProverTaskController) GetTask(ctx *gin.Context) { } byt, err := json.Marshal(task) if err != nil { - ctx.JSON(http.StatusInternalServerError, Err(err)) + ctx.JSON(http.StatusOK, Err(err)) return } ctx.JSON(http.StatusOK, Ok(byt)) From 56399ad0540135cd9bdbfde4d647c6e7f6fb5025 Mon Sep 17 00:00:00 2001 From: georgehao Date: Tue, 18 Jul 2023 16:56:21 +0800 Subject: [PATCH 51/68] feat: update prover stats api some files --- go.work.sum | 11 +- prover-stats-api/Makefile | 3 + prover-stats-api/README | 23 ++ prover-stats-api/cmd/app/app.go | 23 +- prover-stats-api/cmd/docs/docs.go | 49 ---- prover-stats-api/cmd/docs/swagger.json | 24 -- prover-stats-api/cmd/docs/swagger.yaml | 17 -- prover-stats-api/cmd/main.go | 5 +- prover-stats-api/conf/config.json | 7 +- prover-stats-api/docs/docs.go | 263 ++++++++++++++++++ prover-stats-api/docs/swagger.json | 238 ++++++++++++++++ prover-stats-api/docs/swagger.yaml | 157 +++++++++++ prover-stats-api/go.mod | 3 +- prover-stats-api/go.sum | 54 +++- prover-stats-api/internal/config/config.go | 9 +- prover-stats-api/internal/controller/auth.go | 54 ++++ .../internal/controller/controller.go | 120 +------- .../internal/controller/prover_task.go | 127 +++++++++ prover-stats-api/internal/controller/route.go | 29 -- prover-stats-api/internal/controller/types.go | 26 -- prover-stats-api/internal/logic/logic.go | 45 --- .../internal/logic/prover_task.go | 42 +++ .../{logic_test.go => prover_task_test.go} | 0 prover-stats-api/internal/middleware/jwt.go | 91 +++--- prover-stats-api/internal/orm/prover_task.go | 69 ++--- prover-stats-api/internal/route/route.go | 34 +++ prover-stats-api/internal/types/auth.go | 12 + prover-stats-api/internal/types/errno.go | 7 + .../internal/types/prover_task.go | 31 +++ prover-stats-api/internal/types/response.go | 27 ++ 30 files changed, 1179 insertions(+), 421 deletions(-) create mode 100644 prover-stats-api/README delete mode 100644 prover-stats-api/cmd/docs/docs.go delete mode 100644 prover-stats-api/cmd/docs/swagger.json delete mode 100644 prover-stats-api/cmd/docs/swagger.yaml create mode 100644 prover-stats-api/docs/docs.go create mode 100644 prover-stats-api/docs/swagger.json create mode 100644 prover-stats-api/docs/swagger.yaml create mode 100644 prover-stats-api/internal/controller/auth.go create mode 100644 prover-stats-api/internal/controller/prover_task.go delete mode 100644 prover-stats-api/internal/controller/route.go delete mode 100644 prover-stats-api/internal/controller/types.go delete mode 100644 prover-stats-api/internal/logic/logic.go create mode 100644 prover-stats-api/internal/logic/prover_task.go rename prover-stats-api/internal/logic/{logic_test.go => prover_task_test.go} (100%) create mode 100644 prover-stats-api/internal/route/route.go create mode 100644 prover-stats-api/internal/types/auth.go create mode 100644 prover-stats-api/internal/types/errno.go create mode 100644 prover-stats-api/internal/types/prover_task.go create mode 100644 prover-stats-api/internal/types/response.go diff --git a/go.work.sum b/go.work.sum index e809d37e43..b58146e172 100644 --- a/go.work.sum +++ b/go.work.sum @@ -155,7 +155,6 @@ github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdw github.com/dgraph-io/badger/v2 v2.2007.4/go.mod h1:vSw/ax2qojzbN6eXHIx6KPKtCSHJN/Uz0X0VPruTIhk= github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de h1:t0UHb5vdojIDUqktM6+xJAfScFBsVpXZmqC9dsgJmeA= github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgryski/go-bitstream v0.0.0-20180413035011-3522498ce2c8 h1:akOQj8IVgoeFfBTzGOEQakCYshWD6RNo1M5pivFXt70= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= @@ -211,7 +210,6 @@ github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9 h1:r5GgOLGbza2wVHR github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= -github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd h1:r04MMPyLHj/QwZuMJ5+7tJcBr1AQjpiAK/rZWRrQT7o= github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31 h1:gclg6gY70GLy3PbkQ1AERPfmLMMagS60DKF78eWwLn8= github.com/go-check/check v0.0.0-20180628173108-788fd7840127 h1:0gkP6mzaMqkmpcJYCFOLkIBwI7xFExG03bbkOkCvUPI= @@ -229,11 +227,8 @@ github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dT github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= -github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= -github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= -github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU= @@ -368,7 +363,6 @@ github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= @@ -479,8 +473,8 @@ github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZF github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= +github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= -github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc= github.com/valyala/fasthttp v1.40.0 h1:CRq/00MfruPGFLTQKY8b+8SfdK60TxNztjRMnH0t1Yc= @@ -526,7 +520,6 @@ golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= @@ -568,9 +561,7 @@ google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84 h1:R1r5J0u6Cx+RNl/ google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0= google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= diff --git a/prover-stats-api/Makefile b/prover-stats-api/Makefile index 81307cf200..856427ebf7 100644 --- a/prover-stats-api/Makefile +++ b/prover-stats-api/Makefile @@ -6,5 +6,8 @@ build: clean: ## Empty out the bin folder @rm -rf build/bin +swag: + swag init -g ./cmd/main.go + test: go test -v $(PWD)/... \ No newline at end of file diff --git a/prover-stats-api/README b/prover-stats-api/README new file mode 100644 index 0000000000..47ef34b0b1 --- /dev/null +++ b/prover-stats-api/README @@ -0,0 +1,23 @@ +# prover-stats-api + +## how to get the prover-stats-api docs + +### 1. start the prover-stats-api server + +``` +cd ./prover-stats-api +go build -o prover-stats ./cmd/ +./prover-stats --config=./conf/config.json +``` + +you will get server run log +``` +Listening and serving HTTP on :8990 +``` + +### 2. browse the documents + +open this documents in your browser +``` +http://localhost:8990/swagger/index.html +``` \ No newline at end of file diff --git a/prover-stats-api/cmd/app/app.go b/prover-stats-api/cmd/app/app.go index 0c001f39f7..e31849abf2 100644 --- a/prover-stats-api/cmd/app/app.go +++ b/prover-stats-api/cmd/app/app.go @@ -5,18 +5,19 @@ import ( "fmt" "os" "os/signal" - "scroll-tech/common/metrics" + "github.com/gin-gonic/gin" "github.com/scroll-tech/go-ethereum/log" "github.com/urfave/cli/v2" "scroll-tech/common/database" + "scroll-tech/common/metrics" "scroll-tech/common/utils" "scroll-tech/common/version" - _ "scroll-tech/prover-stats-api/cmd/docs" "scroll-tech/prover-stats-api/internal/config" "scroll-tech/prover-stats-api/internal/controller" + "scroll-tech/prover-stats-api/internal/route" ) var app *cli.App @@ -55,11 +56,6 @@ func action(ctx *cli.Context) error { }() subCtx, cancel := context.WithCancel(ctx.Context) - - // init Prover Stats API - port := ctx.String(httpPortFlag.Name) - controller.Route(db, port, cfg) - defer func() { cancel() }() @@ -67,6 +63,19 @@ func action(ctx *cli.Context) error { // Start metrics server. metrics.Serve(subCtx, ctx) + // init Prover Stats API + port := ctx.String(httpPortFlag.Name) + + router := gin.Default() + controller.InitController(db) + route.Route(router, cfg) + + go func() { + if runServerErr := router.Run(fmt.Sprintf(":%s", port)); runServerErr != nil { + log.Crit("run http server failure", "error", runServerErr) + } + }() + // Catch CTRL-C to ensure a graceful shutdown. interrupt := make(chan os.Signal, 1) signal.Notify(interrupt, os.Interrupt) diff --git a/prover-stats-api/cmd/docs/docs.go b/prover-stats-api/cmd/docs/docs.go deleted file mode 100644 index dcc32a0557..0000000000 --- a/prover-stats-api/cmd/docs/docs.go +++ /dev/null @@ -1,49 +0,0 @@ -// Code generated by swaggo/swag. DO NOT EDIT. - -package docs - -import "github.com/swaggo/swag" - -const docTemplate = `{ - "schemes": {{ marshal .Schemes }}, - "swagger": "2.0", - "info": { - "description": "{{escape .Description}}", - "title": "{{.Title}}", - "contact": { - "name": "Prover Stats API Support", - "email": "Be Pending" - }, - "license": { - "name": "Apache 2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - }, - "version": "{{.Version}}" - }, - "host": "{{.Host}}", - "basePath": "{{.BasePath}}", - "paths": {}, - "securityDefinitions": { - "BasicAuth": { - "type": "basic" - } - } -}` - -// SwaggerInfo holds exported Swagger Info so clients can modify it -var SwaggerInfo = &swag.Spec{ - Version: "1.0", - Host: "localhost:8990", - BasePath: "/api/v1", - Schemes: []string{}, - Title: "Zero-knowledge Prover Stats API", - Description: "This is an API server for Provers.", - InfoInstanceName: "swagger", - SwaggerTemplate: docTemplate, - LeftDelim: "{{", - RightDelim: "}}", -} - -func init() { - swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) -} diff --git a/prover-stats-api/cmd/docs/swagger.json b/prover-stats-api/cmd/docs/swagger.json deleted file mode 100644 index 960c088226..0000000000 --- a/prover-stats-api/cmd/docs/swagger.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "description": "This is an API server for Provers.", - "title": "Zero-knowledge Prover Stats API", - "contact": { - "name": "Prover Stats API Support", - "email": "Be Pending" - }, - "license": { - "name": "Apache 2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - }, - "version": "1.0" - }, - "host": "localhost:8990", - "basePath": "/api/v1", - "paths": {}, - "securityDefinitions": { - "BasicAuth": { - "type": "basic" - } - } -} \ No newline at end of file diff --git a/prover-stats-api/cmd/docs/swagger.yaml b/prover-stats-api/cmd/docs/swagger.yaml deleted file mode 100644 index 36129305d9..0000000000 --- a/prover-stats-api/cmd/docs/swagger.yaml +++ /dev/null @@ -1,17 +0,0 @@ -basePath: /api/v1 -host: localhost:8990 -info: - contact: - email: Be Pending - name: Prover Stats API Support - description: This is an API server for Provers. - license: - name: Apache 2.0 - url: http://www.apache.org/licenses/LICENSE-2.0.html - title: Zero-knowledge Prover Stats API - version: "1.0" -paths: {} -securityDefinitions: - BasicAuth: - type: basic -swagger: "2.0" diff --git a/prover-stats-api/cmd/main.go b/prover-stats-api/cmd/main.go index 5e309f3c33..fe7f50d9f1 100644 --- a/prover-stats-api/cmd/main.go +++ b/prover-stats-api/cmd/main.go @@ -1,6 +1,9 @@ package main -import "scroll-tech/prover-stats-api/cmd/app" +import ( + "scroll-tech/prover-stats-api/cmd/app" + _ "scroll-tech/prover-stats-api/docs" +) // @title Zero-knowledge Prover Stats API // @version 1.0 diff --git a/prover-stats-api/conf/config.json b/prover-stats-api/conf/config.json index 3b4bef80f7..d4c7dd0e99 100644 --- a/prover-stats-api/conf/config.json +++ b/prover-stats-api/conf/config.json @@ -1,9 +1,12 @@ { "db_config": { "driver_name": "postgres", - "dsn": "postgres://admin:123456@localhost/test?sslmode=disable", + "dsn": "postgres://localhost/scroll?sslmode=disable", "maxOpenNum": 200, "maxIdleNum": 20 }, - "api_secret": "test-api" + "auth": { + "secret": "prover secret key", + "token_expire_duration": 3600 + } } \ No newline at end of file diff --git a/prover-stats-api/docs/docs.go b/prover-stats-api/docs/docs.go new file mode 100644 index 0000000000..bfe9469301 --- /dev/null +++ b/prover-stats-api/docs/docs.go @@ -0,0 +1,263 @@ +// Code generated by swaggo/swag. DO NOT EDIT. + +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "contact": { + "name": "Prover Stats API Support", + "email": "Be Pending" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/api/prover_task/v1/request_token": { + "get": { + "description": "login with prover public key", + "consumes": [ + "text/plain" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "prover_task" + ], + "summary": "login with prover public key", + "parameters": [ + { + "type": "string", + "description": "prover public key", + "name": "pubkey", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/types.LoginSchema" + } + } + } + } + } + }, + "/api/prover_task/v1/task": { + "get": { + "description": "get prover task by task id", + "consumes": [ + "text/plain" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "prover_task" + ], + "summary": "give the specific prover task", + "parameters": [ + { + "type": "string", + "description": "prover task hash", + "name": "task_id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Bearer license", + "name": "Authorization", + "in": "header" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/types.ProverTaskSchema" + } + } + } + } + }, + "/api/prover_task/v1/tasks": { + "get": { + "description": "get all the prover task by prover public key", + "consumes": [ + "text/plain" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "prover_task" + ], + "summary": "get all the prover task by prover public key", + "parameters": [ + { + "type": "string", + "description": "prover public key", + "name": "pubkey", + "in": "query", + "required": true + }, + { + "type": "integer", + "description": "page", + "name": "page", + "in": "query", + "required": true + }, + { + "type": "integer", + "description": "page_size", + "name": "page_size", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "Bearer license", + "name": "Authorization", + "in": "header" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/types.ProverTaskSchema" + } + } + } + } + } + }, + "/api/prover_task/v1/total_rewards": { + "get": { + "description": "get uint64 by prover public key", + "consumes": [ + "text/plain" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "prover_task" + ], + "summary": "give the total rewards of a prover", + "parameters": [ + { + "type": "string", + "description": "prover public key", + "name": "pubkey", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Bearer license", + "name": "Authorization", + "in": "header" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/types.ProverTotalRewardsSchema" + } + } + } + } + } + }, + "definitions": { + "types.LoginSchema": { + "type": "object", + "properties": { + "time": { + "type": "string" + }, + "token": { + "type": "string" + } + } + }, + "types.ProverTaskSchema": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "failure_type": { + "type": "string" + }, + "prover_name": { + "type": "string" + }, + "proving_status": { + "type": "string" + }, + "reward": { + "type": "string" + }, + "task_id": { + "type": "string" + }, + "task_type": { + "type": "string" + } + } + }, + "types.ProverTotalRewardsSchema": { + "type": "object", + "properties": { + "rewards": { + "type": "string" + } + } + } + }, + "securityDefinitions": { + "BasicAuth": { + "type": "basic" + } + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "1.0", + Host: "localhost:8990", + BasePath: "/api/v1", + Schemes: []string{}, + Title: "Zero-knowledge Prover Stats API", + Description: "This is an API server for Provers.", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/prover-stats-api/docs/swagger.json b/prover-stats-api/docs/swagger.json new file mode 100644 index 0000000000..fbfa1a83d2 --- /dev/null +++ b/prover-stats-api/docs/swagger.json @@ -0,0 +1,238 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is an API server for Provers.", + "title": "Zero-knowledge Prover Stats API", + "contact": { + "name": "Prover Stats API Support", + "email": "Be Pending" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "1.0" + }, + "host": "localhost:8990", + "basePath": "/api/v1", + "paths": { + "/api/prover_task/v1/request_token": { + "get": { + "description": "login with prover public key", + "consumes": [ + "text/plain" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "prover_task" + ], + "summary": "login with prover public key", + "parameters": [ + { + "type": "string", + "description": "prover public key", + "name": "pubkey", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/types.LoginSchema" + } + } + } + } + } + }, + "/api/prover_task/v1/task": { + "get": { + "description": "get prover task by task id", + "consumes": [ + "text/plain" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "prover_task" + ], + "summary": "give the specific prover task", + "parameters": [ + { + "type": "string", + "description": "prover task hash", + "name": "task_id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Bearer license", + "name": "Authorization", + "in": "header" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/types.ProverTaskSchema" + } + } + } + } + }, + "/api/prover_task/v1/tasks": { + "get": { + "description": "get all the prover task by prover public key", + "consumes": [ + "text/plain" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "prover_task" + ], + "summary": "get all the prover task by prover public key", + "parameters": [ + { + "type": "string", + "description": "prover public key", + "name": "pubkey", + "in": "query", + "required": true + }, + { + "type": "integer", + "description": "page", + "name": "page", + "in": "query", + "required": true + }, + { + "type": "integer", + "description": "page_size", + "name": "page_size", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "Bearer license", + "name": "Authorization", + "in": "header" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/types.ProverTaskSchema" + } + } + } + } + } + }, + "/api/prover_task/v1/total_rewards": { + "get": { + "description": "get uint64 by prover public key", + "consumes": [ + "text/plain" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "prover_task" + ], + "summary": "give the total rewards of a prover", + "parameters": [ + { + "type": "string", + "description": "prover public key", + "name": "pubkey", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Bearer license", + "name": "Authorization", + "in": "header" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/types.ProverTotalRewardsSchema" + } + } + } + } + } + }, + "definitions": { + "types.LoginSchema": { + "type": "object", + "properties": { + "time": { + "type": "string" + }, + "token": { + "type": "string" + } + } + }, + "types.ProverTaskSchema": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "failure_type": { + "type": "string" + }, + "prover_name": { + "type": "string" + }, + "proving_status": { + "type": "string" + }, + "reward": { + "type": "string" + }, + "task_id": { + "type": "string" + }, + "task_type": { + "type": "string" + } + } + }, + "types.ProverTotalRewardsSchema": { + "type": "object", + "properties": { + "rewards": { + "type": "string" + } + } + } + }, + "securityDefinitions": { + "BasicAuth": { + "type": "basic" + } + } +} \ No newline at end of file diff --git a/prover-stats-api/docs/swagger.yaml b/prover-stats-api/docs/swagger.yaml new file mode 100644 index 0000000000..0d083f5e3d --- /dev/null +++ b/prover-stats-api/docs/swagger.yaml @@ -0,0 +1,157 @@ +basePath: /api/v1 +definitions: + types.LoginSchema: + properties: + time: + type: string + token: + type: string + type: object + types.ProverTaskSchema: + properties: + created_at: + type: string + failure_type: + type: string + prover_name: + type: string + proving_status: + type: string + reward: + type: string + task_id: + type: string + task_type: + type: string + type: object + types.ProverTotalRewardsSchema: + properties: + rewards: + type: string + type: object +host: localhost:8990 +info: + contact: + email: Be Pending + name: Prover Stats API Support + description: This is an API server for Provers. + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + title: Zero-knowledge Prover Stats API + version: "1.0" +paths: + /api/prover_task/v1/request_token: + get: + consumes: + - text/plain + description: login with prover public key + parameters: + - description: prover public key + in: query + name: pubkey + required: true + type: string + produces: + - text/plain + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/types.LoginSchema' + type: array + summary: login with prover public key + tags: + - prover_task + /api/prover_task/v1/task: + get: + consumes: + - text/plain + description: get prover task by task id + parameters: + - description: prover task hash + in: path + name: task_id + required: true + type: string + - description: Bearer license + in: header + name: Authorization + type: string + produces: + - text/plain + responses: + "200": + description: OK + schema: + $ref: '#/definitions/types.ProverTaskSchema' + summary: give the specific prover task + tags: + - prover_task + /api/prover_task/v1/tasks: + get: + consumes: + - text/plain + description: get all the prover task by prover public key + parameters: + - description: prover public key + in: query + name: pubkey + required: true + type: string + - description: page + in: query + name: page + required: true + type: integer + - description: page_size + in: query + name: page_size + required: true + type: integer + - description: Bearer license + in: header + name: Authorization + type: string + produces: + - text/plain + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/types.ProverTaskSchema' + type: array + summary: get all the prover task by prover public key + tags: + - prover_task + /api/prover_task/v1/total_rewards: + get: + consumes: + - text/plain + description: get uint64 by prover public key + parameters: + - description: prover public key + in: path + name: pubkey + required: true + type: string + - description: Bearer license + in: header + name: Authorization + type: string + produces: + - text/plain + responses: + "200": + description: OK + schema: + $ref: '#/definitions/types.ProverTotalRewardsSchema' + summary: give the total rewards of a prover + tags: + - prover_task +securityDefinitions: + BasicAuth: + type: basic +swagger: "2.0" diff --git a/prover-stats-api/go.mod b/prover-stats-api/go.mod index a90fddd2d1..ad36b003d2 100644 --- a/prover-stats-api/go.mod +++ b/prover-stats-api/go.mod @@ -3,6 +3,7 @@ module scroll-tech/prover-stats-api go 1.19 require ( + github.com/appleboy/gin-jwt/v2 v2.9.1 github.com/gin-gonic/gin v1.9.1 github.com/stretchr/testify v1.8.3 gorm.io/gorm v1.25.2 @@ -11,6 +12,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-stack/stack v1.8.0 // indirect + github.com/golang-jwt/jwt/v4 v4.4.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect ) @@ -19,7 +21,6 @@ require ( github.com/bytedance/sonic v1.9.2 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect - github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect diff --git a/prover-stats-api/go.sum b/prover-stats-api/go.sum index f1f50c2d43..544a0b9c26 100644 --- a/prover-stats-api/go.sum +++ b/prover-stats-api/go.sum @@ -1,5 +1,9 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/appleboy/gin-jwt/v2 v2.9.1 h1:l29et8iLW6omcHltsOP6LLk4s3v4g2FbFs0koxGWVZs= +github.com/appleboy/gin-jwt/v2 v2.9.1/go.mod h1:jwcPZJ92uoC9nOUTOKWoN/f6JZOgMSKlFSHw5/FrRUk= +github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4= +github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.2 h1:GDaNjuWSGu09guE9Oql0MSTNhNCLlWwO8y/xM5BzcbM= github.com/bytedance/sonic v1.9.2/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= @@ -12,13 +16,12 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -35,17 +38,26 @@ github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/ github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= +github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k= github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/golang-jwt/jwt/v4 v4.4.3 h1:Hxl6lhQFj4AnOX6MLrsCb/+7tCj7DxP7VA+2rDIq5AU= +github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -62,12 +74,14 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -75,6 +89,8 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 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= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -83,10 +99,16 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= +github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/scroll-tech/go-ethereum v1.10.14-0.20230613025759-f055f50f9d56 h1:Cqj7haxwvzI2O4n9ZZ25helShzFGCy7Z/B+FFSBFHNI= @@ -111,8 +133,16 @@ github.com/swaggo/gin-swagger v1.6.0 h1:y8sxvQ3E20/RCyrXeFfg60r6H0Z+SwpTjMYsMm+z github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRdOqDkvq0uzo= github.com/swaggo/swag v1.16.1 h1:fTNRhKstPKxcnoKsytm4sahr8FaYzUcT7i1/3nd/fBg= github.com/swaggo/swag v1.16.1/go.mod h1:9/LMvHycG3NFHfR6LwvikHv5iFvmPADQ359cKikGxto= +github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw= +github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= +github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= @@ -124,14 +154,20 @@ golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUu golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc= golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80= golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= @@ -139,19 +175,27 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/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-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/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.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= @@ -164,6 +208,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -171,11 +217,13 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho= diff --git a/prover-stats-api/internal/config/config.go b/prover-stats-api/internal/config/config.go index 00bf45390e..3bae47c3c4 100644 --- a/prover-stats-api/internal/config/config.go +++ b/prover-stats-api/internal/config/config.go @@ -8,8 +8,13 @@ import ( ) type Config struct { - DBConfig *database.Config `json:"db_config"` - ApiSecret string `json:"api_secret"` + DBConfig *database.Config `json:"db_config"` + Auth Auth `json:"auth"` +} + +type Auth struct { + Secret string `json:"secret"` + TokenExpireDuration int `json:"token_expire_duration"` // unit: seconds } // NewConfig returns a new instance of Config. diff --git a/prover-stats-api/internal/controller/auth.go b/prover-stats-api/internal/controller/auth.go new file mode 100644 index 0000000000..994894aa65 --- /dev/null +++ b/prover-stats-api/internal/controller/auth.go @@ -0,0 +1,54 @@ +package controller + +import ( + "errors" + "fmt" + "time" + + "github.com/gin-gonic/gin" + + "scroll-tech/prover-stats-api/internal/types" +) + +type AuthController struct { +} + +func NewAuthController() *AuthController { + return &AuthController{} +} + +// Login godoc +// @Summary login with prover public key +// @Description login with prover public key +// @Tags prover_task +// @Accept plain +// @Produce plain +// @Param pubkey query string true "prover public key" +// @Success 200 {array} types.LoginSchema +// @Router /api/prover_task/v1/request_token [get] +func (a *AuthController) Login(c *gin.Context) (interface{}, error) { + var login types.LoginParameter + if err := c.ShouldBindQuery(&login); err != nil { + return "", fmt.Errorf("missing the public_key, err:%w", err) + } + + // TODO check public key is exist + + if a.checkValidPublicKey() { + return types.LoginParameter{PublicKey: login.PublicKey}, nil + } + + return nil, errors.New("incorrect public_key") +} + +func (a *AuthController) checkValidPublicKey() bool { + return true +} + +func (a *AuthController) LoginResponse(c *gin.Context, code int, message string, time time.Time) { + resp := types.LoginSchema{ + Time: time, + Token: message, + } + types.RenderJson(c, code, nil, resp) +} diff --git a/prover-stats-api/internal/controller/controller.go b/prover-stats-api/internal/controller/controller.go index 61f5d699a3..f74b254588 100644 --- a/prover-stats-api/internal/controller/controller.go +++ b/prover-stats-api/internal/controller/controller.go @@ -1,121 +1,11 @@ package controller -import ( - "encoding/json" - "net/http" +import "gorm.io/gorm" - "scroll-tech/prover-stats-api/internal/middleware" - - "scroll-tech/prover-stats-api/internal/logic" - - "github.com/gin-gonic/gin" +var ( + ProverTask *ProverTaskController ) -type ProverTaskController struct { - router *gin.RouterGroup - logic *logic.ProverTaskLogic -} - -func NewProverTaskController(r *gin.RouterGroup, taskLogic *logic.ProverTaskLogic) *ProverTaskController { - router := r.Group("/prover_task") - return &ProverTaskController{ - router: router, - logic: taskLogic, - } -} - -func (c *ProverTaskController) Route() { - c.router.GET("/request_token", c.RequestToken) - c.router.GET("/tasks", c.GetTasksByProver) - c.router.GET("/total_rewards", c.GetTotalRewards) - c.router.GET("/task", c.GetTask) -} - -// RequestToken godoc -// @Summary request token -// @Description generate token for the client -// @Tags prover_task -// @Produce json -// @Success 200 {object} string -// @Failure 401 {object} string -// @Router /prover_task/request_token [get] -func (c *ProverTaskController) RequestToken(ctx *gin.Context) { - token, err := middleware.GenToken() - if err != nil { - ctx.JSON(http.StatusOK, Err(err)) - return - } - ctx.JSON(http.StatusOK, Ok([]byte(token))) -} - -// GetTasksByProver godoc -// @Summary give the proverTasks -// @Description get []*ProverTask by prover public key -// @Tags prover_task -// @Accept string -// @Produce json -// @Param pubkey path string true "prover public key" -// @Success 200 {object} []*orm.ProverTask -// @Failure 404 {object} string -// @Failure 500 {object} string -// @Router /prover_task/tasks/{pubkey} [get] -func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) { - pubkey := ctx.Query("pubkey") - tasks, err := c.logic.GetTasksByProver(pubkey) - if err != nil { - ctx.JSON(http.StatusOK, Err(err)) - return - } - byt, err := json.Marshal(tasks) - if err != nil { - ctx.JSON(http.StatusOK, Err(err)) - return - } - ctx.JSON(http.StatusOK, Ok(byt)) -} - -// GetTotalRewards godoc -// @Summary give the total rewards of a prover -// @Description get uint64 by prover public key -// @Tags prover_task -// @Accept string -// @Produce json -// @Param pubkey path string true "prover public key" -// @Success 200 {object} map[string]*big.Int -// @Failure 404 {object} string -// @Failure 500 {object} string -// @Router /prover_task/total_rewards/{pubkey} [get] -func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { - pubkey := ctx.Query("pubkey") - rewards, err := c.logic.GetTotalRewards(pubkey) - if err != nil { - ctx.JSON(http.StatusOK, Err(err)) - return - } - ctx.JSON(http.StatusOK, Ok(rewards.Bytes())) -} - -// GetTask godoc -// @Summary give the specific prover task -// @Description get prover task by task id -// @Tags prover_task -// @Accept string -// @Produce json -// @Param task_id path string true "prover task hash" -// @Success 200 {object} *orm.ProverTask -// @Failure 500 {object} string -// @Router /prover_task/task/{task_id} [get] -func (c *ProverTaskController) GetTask(ctx *gin.Context) { - taskID := ctx.Query("task_id") - task, err := c.logic.GetTask(taskID) - if err != nil { - ctx.JSON(http.StatusOK, Err(err)) - return - } - byt, err := json.Marshal(task) - if err != nil { - ctx.JSON(http.StatusOK, Err(err)) - return - } - ctx.JSON(http.StatusOK, Ok(byt)) +func InitController(db *gorm.DB) { + ProverTask = NewProverTaskController(db) } diff --git a/prover-stats-api/internal/controller/prover_task.go b/prover-stats-api/internal/controller/prover_task.go new file mode 100644 index 0000000000..95b623ef1a --- /dev/null +++ b/prover-stats-api/internal/controller/prover_task.go @@ -0,0 +1,127 @@ +package controller + +import ( + "fmt" + + "github.com/gin-gonic/gin" + "gorm.io/gorm" + + ctype "scroll-tech/common/types" + "scroll-tech/common/types/message" + + "scroll-tech/prover-stats-api/internal/logic" + "scroll-tech/prover-stats-api/internal/types" +) + +type ProverTaskController struct { + logic *logic.ProverTaskLogic +} + +func NewProverTaskController(db *gorm.DB) *ProverTaskController { + return &ProverTaskController{ + logic: logic.NewProverTaskLogic(db), + } +} + +// ProverTasks godoc +// @Summary get all the prover task by prover public key +// @Description get all the prover task by prover public key +// @Tags prover_task +// @Accept plain +// @Produce plain +// @Param pubkey query string true "prover public key" +// @Param page query int true "page" +// @Param page_size query int true "page_size" +// @Param Authorization header string false "Bearer license" +// @Success 200 {array} types.ProverTaskSchema +// @Router /api/prover_task/v1/tasks [get] +func (c *ProverTaskController) ProverTasks(ctx *gin.Context) { + var pp types.ProverTasksPaginationParameter + if err := ctx.ShouldBind(&pp); err != nil { + nerr := fmt.Errorf("parameter invalid, err:%w", err) + types.RenderJson(ctx, types.ErrParameterInvalidNo, nerr, nil) + return + } + + tasks, err := c.logic.GetTasksByProver(ctx, pp.PublicKey, pp.Page, pp.PageSize) + if err != nil { + nerr := fmt.Errorf("controller.ProverTasks err:%w", err) + types.RenderJson(ctx, types.ErrProverTaskFailure, nerr, nil) + return + } + + var proverTaskSchemas []types.ProverTaskSchema + for _, task := range tasks { + proverTaskSchema := types.ProverTaskSchema{ + TaskID: task.TaskID, + ProverName: task.ProverName, + TaskType: message.ProofType(task.TaskType).String(), + ProvingStatus: ctype.ProvingStatus(task.ProvingStatus).String(), + Reward: task.Reward.String(), + CreatedAt: task.CreatedAt, + } + proverTaskSchemas = append(proverTaskSchemas, proverTaskSchema) + } + + types.RenderJson(ctx, 0, nil, proverTaskSchemas) +} + +// GetTotalRewards godoc +// @Summary give the total rewards of a prover +// @Description get uint64 by prover public key +// @Tags prover_task +// @Accept plain +// @Produce plain +// @Param pubkey path string true "prover public key" +// @Param Authorization header string false "Bearer license" +// @Success 200 {object} types.ProverTotalRewardsSchema +// @Router /api/prover_task/v1/total_rewards [get] +func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { + var pp types.ProverTotalRewardsParameter + if err := ctx.ShouldBind(&pp); err != nil { + nerr := fmt.Errorf("parameter invalid, err:%w", err) + types.RenderJson(ctx, types.ErrParameterInvalidNo, nerr, nil) + return + } + + rewards, err := c.logic.GetTotalRewards(ctx, pp.PublicKey) + if err != nil { + nerr := fmt.Errorf("controller.GetTotalRewards, err:%w", err) + types.RenderJson(ctx, types.ErrProverTotalRewardFailure, nerr, nil) + return + } + + resp := types.ProverTotalRewardsSchema{ + Rewards: rewards.String(), + } + + types.RenderJson(ctx, 0, nil, resp) +} + +// GetTask godoc +// @Summary give the specific prover task +// @Description get prover task by task id +// @Tags prover_task +// @Accept plain +// @Produce plain +// @Param task_id path string true "prover task hash" +// @Param Authorization header string false "Bearer license" +// @Success 200 {object} types.ProverTaskSchema +// @Router /api/prover_task/v1/task [get] +func (c *ProverTaskController) GetTask(ctx *gin.Context) { + var pp types.ProverTaskParameter + if err := ctx.ShouldBind(&pp); err != nil { + nerr := fmt.Errorf("parameter invalid, err:%w", err) + types.RenderJson(ctx, types.ErrParameterInvalidNo, nerr, nil) + return + } + + task, err := c.logic.GetTask(ctx, pp.TaskID) + if err != nil { + nerr := fmt.Errorf("controller.GetTask, err:%w", err) + types.RenderJson(ctx, types.ErrProverTotalRewardFailure, nerr, nil) + return + } + + types.RenderJson(ctx, 0, nil, task) +} diff --git a/prover-stats-api/internal/controller/route.go b/prover-stats-api/internal/controller/route.go deleted file mode 100644 index 2bb8d65bce..0000000000 --- a/prover-stats-api/internal/controller/route.go +++ /dev/null @@ -1,29 +0,0 @@ -package controller - -import ( - "github.com/gin-gonic/gin" - swaggerfiles "github.com/swaggo/files" - ginSwagger "github.com/swaggo/gin-swagger" - "gorm.io/gorm" - - "scroll-tech/prover-stats-api/internal/config" - "scroll-tech/prover-stats-api/internal/logic" - "scroll-tech/prover-stats-api/internal/middleware" -) - -func Route(db *gorm.DB, port string, cfg *config.Config) { - taskService := logic.NewProverTaskLogic(db) - - r := gin.Default() - middleware.Secret = cfg.ApiSecret - r.Use(middleware.JWTAuthMiddleware()) - r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) - router := r.Group("/api/v1") - - c := NewProverTaskController(router, taskService) - c.Route() - - go func() { - r.Run(port) - }() -} diff --git a/prover-stats-api/internal/controller/types.go b/prover-stats-api/internal/controller/types.go deleted file mode 100644 index 297546c643..0000000000 --- a/prover-stats-api/internal/controller/types.go +++ /dev/null @@ -1,26 +0,0 @@ -package controller - -type Resp struct { - Code int `json:"code"` - Object []byte `json:"object"` - Error error `json:"error"` -} - -const ( - OK = 1000 - ERR = 1001 -) - -func Ok(obj []byte) *Resp { - return &Resp{ - Code: OK, - Object: obj, - } -} - -func Err(err error) *Resp { - return &Resp{ - Code: ERR, - Error: err, - } -} diff --git a/prover-stats-api/internal/logic/logic.go b/prover-stats-api/internal/logic/logic.go deleted file mode 100644 index d09807deda..0000000000 --- a/prover-stats-api/internal/logic/logic.go +++ /dev/null @@ -1,45 +0,0 @@ -package logic - -import ( - "context" - "math/big" - - "gorm.io/gorm" - - "scroll-tech/prover-stats-api/internal/orm" -) - -type ProverTaskLogic struct { - db *orm.ProverTask -} - -func NewProverTaskLogic(db *gorm.DB) *ProverTaskLogic { - return &ProverTaskLogic{db: orm.NewProverTask(db)} -} - -func (p *ProverTaskLogic) GetTasksByProver(pubkey string) ([]*orm.ProverTask, error) { - return p.db.GetProverTasksByProver(context.Background(), pubkey) -} - -func (p *ProverTaskLogic) GetTotalRewards(pubkey string) (*big.Int, error) { - tasks, err := p.db.GetProverTasksByProver(context.Background(), pubkey) - if err != nil { - return nil, err - } - rewards := new(big.Int) - for _, task := range tasks { - rewards.Add(rewards, task.Reward.BigInt()) - } - return rewards, nil -} - -func (p *ProverTaskLogic) GetTask(taskID string) (*orm.ProverTask, error) { - tasks, err := p.db.GetProverTasksByHashes(context.Background(), []string{taskID}) - if err != nil { - return nil, err - } - if len(tasks) > 0 { - return tasks[0], nil - } - return nil, nil -} diff --git a/prover-stats-api/internal/logic/prover_task.go b/prover-stats-api/internal/logic/prover_task.go new file mode 100644 index 0000000000..53a8b7c56a --- /dev/null +++ b/prover-stats-api/internal/logic/prover_task.go @@ -0,0 +1,42 @@ +package logic + +import ( + "context" + "math/big" + + "gorm.io/gorm" + + "scroll-tech/prover-stats-api/internal/orm" +) + +type ProverTaskLogic struct { + proverTaskOrm *orm.ProverTask +} + +func NewProverTaskLogic(db *gorm.DB) *ProverTaskLogic { + return &ProverTaskLogic{ + proverTaskOrm: orm.NewProverTask(db), + } +} + +func (p *ProverTaskLogic) GetTasksByProver(ctx context.Context, pubkey string, page, pageSize int) ([]*orm.ProverTask, error) { + offset := (page - 1) * pageSize + limit := pageSize + return p.proverTaskOrm.GetProverTasksByProver(ctx, pubkey, offset, limit) +} + +func (p *ProverTaskLogic) GetTotalRewards(ctx context.Context, pubkey string) (*big.Int, error) { + totalReward, err := p.proverTaskOrm.GetProverTotalReward(ctx, pubkey) + if err != nil { + return nil, err + } + return totalReward, nil +} + +func (p *ProverTaskLogic) GetTask(ctx context.Context, taskID string) (*orm.ProverTask, error) { + task, err := p.proverTaskOrm.GetProverTasksByHash(ctx, taskID) + if err != nil { + return nil, err + } + return task, nil +} diff --git a/prover-stats-api/internal/logic/logic_test.go b/prover-stats-api/internal/logic/prover_task_test.go similarity index 100% rename from prover-stats-api/internal/logic/logic_test.go rename to prover-stats-api/internal/logic/prover_task_test.go diff --git a/prover-stats-api/internal/middleware/jwt.go b/prover-stats-api/internal/middleware/jwt.go index aa13f26539..39a7b3fa05 100644 --- a/prover-stats-api/internal/middleware/jwt.go +++ b/prover-stats-api/internal/middleware/jwt.go @@ -2,67 +2,64 @@ package middleware import ( "errors" - "fmt" - "net/http" "time" - "github.com/dgrijalva/jwt-go" + jwt "github.com/appleboy/gin-jwt/v2" "github.com/gin-gonic/gin" -) - -const TokenExpireDuration = time.Minute * 10 -var ( - Secret string - skipPaths = []string{"/api/v1/prover_task/request_token"} + "github.com/scroll-tech/go-ethereum/log" + "scroll-tech/prover-stats-api/internal/config" + "scroll-tech/prover-stats-api/internal/controller" + "scroll-tech/prover-stats-api/internal/types" ) -type ApiClaims struct { - jwt.StandardClaims -} - -func GenToken() (string, error) { - c := ApiClaims{ - jwt.StandardClaims{ - ExpiresAt: time.Now().Add(TokenExpireDuration).Unix(), - }, - } - token := jwt.NewWithClaims(jwt.SigningMethodHS256, c) - return token.SignedString([]byte(Secret)) -} +const IdentityKey = "public_key" -func ParseToken(tokenStr string) (*ApiClaims, error) { - token, err := jwt.ParseWithClaims(tokenStr, &ApiClaims{}, func(token *jwt.Token) (interface{}, error) { - return []byte(Secret), nil +// AuthMiddleware jwt auth middleware +func AuthMiddleware(conf *config.Config) *jwt.GinJWTMiddleware { + authLogic := controller.NewAuthController() + jwtMiddleware, err := jwt.New(&jwt.GinJWTMiddleware{ + PayloadFunc: PayloadFunc, + IdentityHandler: IdentityHandler, + IdentityKey: IdentityKey, + Key: []byte(conf.Auth.Secret), + Timeout: time.Second * time.Duration(conf.Auth.TokenExpireDuration), + Authenticator: authLogic.Login, + Unauthorized: Unauthorized, + TokenLookup: "header: Authorization, query: token, cookie: jwt", + TokenHeadName: "Bearer", + TimeFunc: time.Now, + LoginResponse: authLogic.LoginResponse, }) + if err != nil { - return nil, err + log.Crit("new jwt middleware panic", "error", err) } - if claims, ok := token.Claims.(*ApiClaims); ok && token.Valid { - return claims, nil + + if errInit := jwtMiddleware.MiddlewareInit(); errInit != nil { + log.Crit("init jwt middleware panic", "error", errInit) } - return nil, errors.New("invalid token") + + return jwtMiddleware } -func JWTAuthMiddleware() gin.HandlerFunc { - return func(c *gin.Context) { - for _, path := range skipPaths { - if path == c.FullPath() { - c.Next() - return - } - } - tokenString := c.Request.Header.Get("Authorization") - if tokenString == "" { - c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Null token"}) - return - } +func Unauthorized(c *gin.Context, code int, message string) { + err := errors.New(message) + types.RenderJson(c, code, err, nil) +} - _, err := ParseToken(tokenString) - if err != nil { - c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": fmt.Sprintf("Unauthorized: %v", err)}) - return +func PayloadFunc(data interface{}) jwt.MapClaims { + if v, ok := data.(types.LoginParameter); ok { + return jwt.MapClaims{ + IdentityKey: v.PublicKey, } - c.Next() + } + return jwt.MapClaims{} +} + +func IdentityHandler(c *gin.Context) interface{} { + claims := jwt.ExtractClaims(c) + return &types.LoginParameter{ + PublicKey: claims[IdentityKey].(string), } } diff --git a/prover-stats-api/internal/orm/prover_task.go b/prover-stats-api/internal/orm/prover_task.go index 18204472a7..9df262d34f 100644 --- a/prover-stats-api/internal/orm/prover_task.go +++ b/prover-stats-api/internal/orm/prover_task.go @@ -3,15 +3,11 @@ package orm import ( "context" "fmt" + "math/big" "time" - "gorm.io/gorm" - "gorm.io/gorm/clause" - "github.com/shopspring/decimal" - - "scroll-tech/common/types" - "scroll-tech/common/types/message" + "gorm.io/gorm" ) // ProverTask is assigned rollers info of chunk/batch proof prover task @@ -42,58 +38,45 @@ func (*ProverTask) TableName() string { return "prover_task" } -// GetProverTasksByHashes retrieves the ProverTask records associated with the specified hashes. -// The returned prover task objects are sorted in ascending order by their ids. -func (o *ProverTask) GetProverTasksByHashes(ctx context.Context, hashes []string) ([]*ProverTask, error) { - if len(hashes) == 0 { - return nil, nil - } - +// GetProverTasksByProver get all prover tasks by the given prover's public key. +func (o *ProverTask) GetProverTasksByProver(ctx context.Context, pubkey string, offset, limit int) ([]*ProverTask, error) { + var proverTasks []*ProverTask db := o.db.WithContext(ctx) db = db.Model(&ProverTask{}) - db = db.Where("task_id IN ?", hashes) - db = db.Order("id asc") - - var proverTasks []*ProverTask + db = db.Where("prover_public_key", pubkey) + db = db.Order("id desc") + db = db.Offset(offset) + db = db.Limit(limit) if err := db.Find(&proverTasks).Error; err != nil { - return nil, fmt.Errorf("ProverTask.GetProverTasksByHashes error: %w, hashes: %v", err, hashes) - } - return proverTasks, nil -} - -// GetProverTasksByProver returns prover-tasks by the given prover's public key. -func (o *ProverTask) GetProverTasksByProver(ctx context.Context, pubkey string) ([]*ProverTask, error) { - var proverTasks []*ProverTask - err := o.db.WithContext(ctx).Model(&ProverTask{}).Where(&ProverTask{ProverPublicKey: pubkey}).Order("id desc").Find(&proverTasks).Error - if err != nil { return nil, fmt.Errorf("ProverTask.GetProverTasksByProver error: %w, prover %s", err, pubkey) } return proverTasks, nil } -// SetProverTask updates or inserts a ProverTask record. -func (o *ProverTask) SetProverTask(ctx context.Context, proverTask *ProverTask) error { +// GetProverTotalReward get prover all reward by the given prover's public key. +func (o *ProverTask) GetProverTotalReward(ctx context.Context, pubkey string) (*big.Int, error) { + var totalReward decimal.Decimal db := o.db.WithContext(ctx) db = db.Model(&ProverTask{}) - db = db.Clauses(clause.OnConflict{ - Columns: []clause.Column{{Name: "task_type"}, {Name: "task_id"}, {Name: "prover_public_key"}}, - DoUpdates: clause.AssignmentColumns([]string{"proving_status"}), - }) - - if err := db.Create(&proverTask).Error; err != nil { - return fmt.Errorf("ProverTask.SetProverTask error: %w, prover task: %v", err, proverTask) + db = db.Select("sum(reward)") + db = db.Where("prover_public_key", pubkey) + if err := db.Scan(&totalReward).Error; err != nil { + return nil, fmt.Errorf("ProverTask.GetProverTotalReward error:%w, prover:%s", err, pubkey) } - return nil + return totalReward.BigInt(), nil } -// UpdateProverTaskProvingStatus updates the proving_status of a specific ProverTask record. -func (o *ProverTask) UpdateProverTaskProvingStatus(ctx context.Context, proofType message.ProofType, taskID string, pk string, status types.RollerProveStatus) error { +// GetProverTasksByHash retrieves the ProverTask records associated with the specified hashes. +// The returned prover task objects are sorted in ascending order by their ids. +func (o *ProverTask) GetProverTasksByHash(ctx context.Context, hash string) (*ProverTask, error) { db := o.db.WithContext(ctx) db = db.Model(&ProverTask{}) - db = db.Where("task_type = ? AND task_id = ? AND prover_public_key = ?", proofType, taskID, pk) + db = db.Where("task_id", hash) + db = db.Order("id asc") - if err := db.Update("proving_status", status).Error; err != nil { - return fmt.Errorf("ProverTask.UpdateProverTaskProvingStatus error: %w, proof type: %v, taskID: %v, prover public key: %v, status: %v", err, proofType.String(), taskID, pk, status.String()) + var proverTask *ProverTask + if err := db.Find(&proverTask).Error; err != nil { + return nil, fmt.Errorf("ProverTask.GetProverTasksByHash error: %w, hash: %v", err, hash) } - return nil + return proverTask, nil } diff --git a/prover-stats-api/internal/route/route.go b/prover-stats-api/internal/route/route.go new file mode 100644 index 0000000000..ad93c94f54 --- /dev/null +++ b/prover-stats-api/internal/route/route.go @@ -0,0 +1,34 @@ +package route + +import ( + "github.com/gin-gonic/gin" + swaggerFiles "github.com/swaggo/files" + ginSwagger "github.com/swaggo/gin-swagger" + "scroll-tech/prover-stats-api/internal/controller" + + "scroll-tech/prover-stats-api/internal/config" + "scroll-tech/prover-stats-api/internal/middleware" +) + +func Route(router *gin.Engine, conf *config.Config) { + router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + + r := router.Group("api/prover_task") + + v1(r, conf) +} + +func v1(router *gin.RouterGroup, conf *config.Config) { + r := router.Group("/v1") + + authMiddleware := middleware.AuthMiddleware(conf) + r.GET("/request_token", authMiddleware.LoginHandler) + + // need jwt token api + r.Use(authMiddleware.MiddlewareFunc()) + { + r.GET("/tasks", controller.ProverTask.ProverTasks) + r.GET("/total_rewards", controller.ProverTask.GetTotalRewards) + r.GET("/task", controller.ProverTask.GetTask) + } +} diff --git a/prover-stats-api/internal/types/auth.go b/prover-stats-api/internal/types/auth.go new file mode 100644 index 0000000000..c89c5bc44e --- /dev/null +++ b/prover-stats-api/internal/types/auth.go @@ -0,0 +1,12 @@ +package types + +import "time" + +type LoginParameter struct { + PublicKey string `form:"public_key" json:"public_key" binding:"required"` +} + +type LoginSchema struct { + Time time.Time `json:"time"` + Token string `json:"token"` +} diff --git a/prover-stats-api/internal/types/errno.go b/prover-stats-api/internal/types/errno.go new file mode 100644 index 0000000000..0e3fbbdacf --- /dev/null +++ b/prover-stats-api/internal/types/errno.go @@ -0,0 +1,7 @@ +package types + +const ( + ErrParameterInvalidNo = 10001 + ErrProverTaskFailure = 10002 + ErrProverTotalRewardFailure = 10003 +) diff --git a/prover-stats-api/internal/types/prover_task.go b/prover-stats-api/internal/types/prover_task.go new file mode 100644 index 0000000000..8529bdc6e4 --- /dev/null +++ b/prover-stats-api/internal/types/prover_task.go @@ -0,0 +1,31 @@ +package types + +import "time" + +type ProverTasksPaginationParameter struct { + PublicKey string `form:"public_key" json:"public_key" binding:"required"` + Page int `form:"page" json:"page" binding:"required"` + PageSize int `form:"page_size" json:"limit" binding:"required"` +} + +type ProverTaskSchema struct { + TaskID string `json:"task_id"` + ProverName string `json:"prover_name"` + TaskType string `json:"task_type"` + ProvingStatus string `json:"proving_status"` + FailureType string `json:"failure_type"` + Reward string `json:"reward"` + CreatedAt time.Time `json:"created_at"` +} + +type ProverTotalRewardsParameter struct { + PublicKey string `form:"public_key" json:"public_key" binding:"required"` +} + +type ProverTotalRewardsSchema struct { + Rewards string `json:"rewards"` +} + +type ProverTaskParameter struct { + TaskID string `form:"task_id" json:"task_id" binding:"required"` +} diff --git a/prover-stats-api/internal/types/response.go b/prover-stats-api/internal/types/response.go new file mode 100644 index 0000000000..3b0c74ad5a --- /dev/null +++ b/prover-stats-api/internal/types/response.go @@ -0,0 +1,27 @@ +package types + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +// Response the response schema +type Response struct { + ErrCode int `json:"errcode"` + ErrMsg string `json:"errmsg"` + Data interface{} `json:"data"` +} + +func RenderJson(ctx *gin.Context, errCode int, err error, data interface{}) { + var errMsg string + if err != nil { + errMsg = err.Error() + } + renderData := Response{ + ErrCode: errCode, + ErrMsg: errMsg, + Data: data, + } + ctx.JSON(http.StatusOK, renderData) +} From 274d5fa957332b7a2e56af8ae8dd5fb845ead12e Mon Sep 17 00:00:00 2001 From: georgehao Date: Tue, 18 Jul 2023 17:00:48 +0800 Subject: [PATCH 52/68] feat: update readme --- prover-stats-api/README | 7 +++++++ prover-stats-api/cmd/main.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/prover-stats-api/README b/prover-stats-api/README index 47ef34b0b1..26c08980c7 100644 --- a/prover-stats-api/README +++ b/prover-stats-api/README @@ -20,4 +20,11 @@ Listening and serving HTTP on :8990 open this documents in your browser ``` http://localhost:8990/swagger/index.html +``` + +## how to update the prover-stats-api docs + +``` +cd ./prover-stats-api +make swag ``` \ No newline at end of file diff --git a/prover-stats-api/cmd/main.go b/prover-stats-api/cmd/main.go index fe7f50d9f1..df2934ea0b 100644 --- a/prover-stats-api/cmd/main.go +++ b/prover-stats-api/cmd/main.go @@ -5,7 +5,7 @@ import ( _ "scroll-tech/prover-stats-api/docs" ) -// @title Zero-knowledge Prover Stats API +// @title Scroll Prover Stats API // @version 1.0 // @description This is an API server for Provers. From 27d6098b77261c3731ccd4ccc86434cb5d91176c Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 18 Jul 2023 17:05:02 +0800 Subject: [PATCH 53/68] fix lint --- prover-stats-api/internal/middleware/jwt.go | 1 + prover-stats-api/internal/route/route.go | 1 + 2 files changed, 2 insertions(+) diff --git a/prover-stats-api/internal/middleware/jwt.go b/prover-stats-api/internal/middleware/jwt.go index 39a7b3fa05..4da0ffacce 100644 --- a/prover-stats-api/internal/middleware/jwt.go +++ b/prover-stats-api/internal/middleware/jwt.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/scroll-tech/go-ethereum/log" + "scroll-tech/prover-stats-api/internal/config" "scroll-tech/prover-stats-api/internal/controller" "scroll-tech/prover-stats-api/internal/types" diff --git a/prover-stats-api/internal/route/route.go b/prover-stats-api/internal/route/route.go index ad93c94f54..ea6d9ad1f1 100644 --- a/prover-stats-api/internal/route/route.go +++ b/prover-stats-api/internal/route/route.go @@ -4,6 +4,7 @@ import ( "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" + "scroll-tech/prover-stats-api/internal/controller" "scroll-tech/prover-stats-api/internal/config" From 35ffa7356e3a636674c60037e581efc7a7ec474a Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 18 Jul 2023 18:02:10 +0800 Subject: [PATCH 54/68] fix test --- .../internal/controller/prover_task.go | 11 ++++- .../internal/logic/prover_task_test.go | 6 +-- prover-stats-api/internal/orm/prover_task.go | 17 +++++++ prover-stats-api/test/prover_task_test.go | 44 +++++++++++-------- 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/prover-stats-api/internal/controller/prover_task.go b/prover-stats-api/internal/controller/prover_task.go index 95b623ef1a..1acefd4d0e 100644 --- a/prover-stats-api/internal/controller/prover_task.go +++ b/prover-stats-api/internal/controller/prover_task.go @@ -123,5 +123,14 @@ func (c *ProverTaskController) GetTask(ctx *gin.Context) { return } - types.RenderJson(ctx, 0, nil, task) + schema := types.ProverTaskSchema{ + TaskID: task.TaskID, + ProverName: task.ProverName, + TaskType: message.ProofType(task.TaskType).String(), + ProvingStatus: ctype.ProvingStatus(task.ProvingStatus).String(), + Reward: task.Reward.String(), + CreatedAt: task.CreatedAt, + } + + types.RenderJson(ctx, 0, nil, schema) } diff --git a/prover-stats-api/internal/logic/prover_task_test.go b/prover-stats-api/internal/logic/prover_task_test.go index 9dc6ef59db..b5edc6a9cf 100644 --- a/prover-stats-api/internal/logic/prover_task_test.go +++ b/prover-stats-api/internal/logic/prover_task_test.go @@ -75,20 +75,20 @@ func TestProverTaskService(t *testing.T) { } func testGetTasksByProver(t *testing.T) { - tasks, err := service.GetTasksByProver(proverPubkey) + tasks, err := service.GetTasksByProver(context.Background(), proverPubkey, 1, 2) assert.NoError(t, err) assert.Equal(t, task2.TaskID, tasks[0].TaskID) assert.Equal(t, task1.TaskID, tasks[1].TaskID) } func testGetTotalRewards(t *testing.T) { - rewards, err := service.GetTotalRewards(proverPubkey) + rewards, err := service.GetTotalRewards(context.Background(), proverPubkey) assert.NoError(t, err) assert.Equal(t, big.NewInt(22), rewards) } func testGetTask(t *testing.T) { - task, err := service.GetTask("2") + task, err := service.GetTask(context.Background(), "2") assert.NoError(t, err) assert.Equal(t, task2.TaskID, task.TaskID) } diff --git a/prover-stats-api/internal/orm/prover_task.go b/prover-stats-api/internal/orm/prover_task.go index 9df262d34f..22495e8613 100644 --- a/prover-stats-api/internal/orm/prover_task.go +++ b/prover-stats-api/internal/orm/prover_task.go @@ -6,6 +6,8 @@ import ( "math/big" "time" + "gorm.io/gorm/clause" + "github.com/shopspring/decimal" "gorm.io/gorm" ) @@ -80,3 +82,18 @@ func (o *ProverTask) GetProverTasksByHash(ctx context.Context, hash string) (*Pr } return proverTask, nil } + +// SetProverTask updates or inserts a ProverTask record. +func (o *ProverTask) SetProverTask(ctx context.Context, proverTask *ProverTask) error { + db := o.db.WithContext(ctx) + db = db.Model(&ProverTask{}) + db = db.Clauses(clause.OnConflict{ + Columns: []clause.Column{{Name: "task_type"}, {Name: "task_id"}, {Name: "prover_public_key"}}, + DoUpdates: clause.AssignmentColumns([]string{"proving_status"}), + }) + + if err := db.Create(&proverTask).Error; err != nil { + return fmt.Errorf("ProverTask.SetProverTask error: %w, prover task: %v", err, proverTask) + } + return nil +} diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index dfe3e7f95b..7469bd03c2 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -11,16 +11,20 @@ import ( "scroll-tech/common/docker" "scroll-tech/common/types" "scroll-tech/database/migrate" + + "github.com/gin-gonic/gin" + "testing" + "scroll-tech/prover-stats-api/internal/config" "scroll-tech/prover-stats-api/internal/controller" + "scroll-tech/prover-stats-api/internal/orm" + "scroll-tech/prover-stats-api/internal/route" + api_types "scroll-tech/prover-stats-api/internal/types" "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" "gorm.io/gorm" - - "scroll-tech/prover-stats-api/internal/config" - "scroll-tech/prover-stats-api/internal/orm" ) var ( @@ -50,7 +54,12 @@ func TestProverTaskAPIs(t *testing.T) { insertSomeProverTasks(t, db) // run Prover Stats APIs - controller.Route(db, port, cfg) + router := gin.Default() + controller.InitController(db) + route.Route(router, cfg) + go func() { + router.Run(port) + }() t.Run("testRequestToken", testRequestToken) t.Run("testGetProverTasksByProver", testGetProverTasksByProver) @@ -59,32 +68,31 @@ func TestProverTaskAPIs(t *testing.T) { } func testRequestToken(t *testing.T) { - tokenByt := getResp(t, fmt.Sprintf("%s/request_token", basicPath)) - token = string(tokenByt) + data := getResp(t, fmt.Sprintf("%s/request_token", basicPath)) + token = data.(string) t.Log("token: ", token) } func testGetProverTasksByProver(t *testing.T) { - var tasks []*orm.ProverTask - byt := getResp(t, fmt.Sprintf("%s/tasks?pubkey=%s", basicPath, proverPubkey)) - assert.NoError(t, json.Unmarshal(byt, &tasks)) + data := getResp(t, fmt.Sprintf("%s/tasks?pubkey=%s", basicPath, proverPubkey)) + tasks := data.([]api_types.ProverTaskSchema) assert.Equal(t, task2.TaskID, tasks[0].TaskID) assert.Equal(t, task1.TaskID, tasks[1].TaskID) } func testGetTotalRewards(t *testing.T) { - rewards := getResp(t, fmt.Sprintf("%s/total_rewards?pubkey=%s", basicPath, proverPubkey)) - assert.Equal(t, big.NewInt(22), new(big.Int).SetBytes(rewards)) + data := getResp(t, fmt.Sprintf("%s/total_rewards?pubkey=%s", basicPath, proverPubkey)) + schema := data.(api_types.ProverTotalRewardsSchema) + assert.Equal(t, big.NewInt(22).String(), schema.Rewards) } func testGetProverTask(t *testing.T) { - var task orm.ProverTask - byt := getResp(t, fmt.Sprintf("%s/task?task_id=1", basicPath)) - assert.NoError(t, json.Unmarshal(byt, &task)) + data := getResp(t, fmt.Sprintf("%s/task?task_id=1", basicPath)) + task := data.(api_types.ProverTaskSchema) assert.Equal(t, task1.TaskID, task.TaskID) } -func getResp(t *testing.T, url string) []byte { +func getResp(t *testing.T, url string) interface{} { req, err := http.NewRequest(http.MethodGet, url, nil) assert.NoError(t, err) req.Header.Add("Authorization", token) @@ -96,10 +104,10 @@ func getResp(t *testing.T, url string) []byte { byt, err := io.ReadAll(resp.Body) assert.NoError(t, err) - res := new(controller.Resp) + res := new(api_types.Response) assert.NoError(t, json.Unmarshal(byt, res)) - assert.Equal(t, controller.OK, res.Code) - return res.Object + assert.Equal(t, 0, res.ErrCode) + return res.Data } var ( From 5d40552d729a0739531f6709163483a9136f4d71 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 18 Jul 2023 21:18:30 +0800 Subject: [PATCH 55/68] some fix --- prover-stats-api/internal/controller/prover_task.go | 6 +++--- prover-stats-api/internal/types/errno.go | 1 + prover-stats-api/test/prover_task_test.go | 13 +++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/prover-stats-api/internal/controller/prover_task.go b/prover-stats-api/internal/controller/prover_task.go index 1acefd4d0e..30fa627907 100644 --- a/prover-stats-api/internal/controller/prover_task.go +++ b/prover-stats-api/internal/controller/prover_task.go @@ -63,7 +63,7 @@ func (c *ProverTaskController) ProverTasks(ctx *gin.Context) { proverTaskSchemas = append(proverTaskSchemas, proverTaskSchema) } - types.RenderJson(ctx, 0, nil, proverTaskSchemas) + types.RenderJson(ctx, types.Success, nil, proverTaskSchemas) } // GetTotalRewards godoc @@ -95,7 +95,7 @@ func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { Rewards: rewards.String(), } - types.RenderJson(ctx, 0, nil, resp) + types.RenderJson(ctx, types.Success, nil, resp) } // GetTask godoc @@ -132,5 +132,5 @@ func (c *ProverTaskController) GetTask(ctx *gin.Context) { CreatedAt: task.CreatedAt, } - types.RenderJson(ctx, 0, nil, schema) + types.RenderJson(ctx, types.Success, nil, schema) } diff --git a/prover-stats-api/internal/types/errno.go b/prover-stats-api/internal/types/errno.go index 0e3fbbdacf..77a592c456 100644 --- a/prover-stats-api/internal/types/errno.go +++ b/prover-stats-api/internal/types/errno.go @@ -1,6 +1,7 @@ package types const ( + Success = 200 ErrParameterInvalidNo = 10001 ErrProverTaskFailure = 10002 ErrProverTotalRewardFailure = 10003 diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index 7469bd03c2..d85b70e3c7 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -34,7 +34,7 @@ var ( var ( port = ":12990" addr = fmt.Sprintf("http://localhost%s", port) - basicPath = fmt.Sprintf("%s/api/v1/prover_task", addr) + basicPath = fmt.Sprintf("%s/api/prover_task/v1", addr) token string ) @@ -68,20 +68,20 @@ func TestProverTaskAPIs(t *testing.T) { } func testRequestToken(t *testing.T) { - data := getResp(t, fmt.Sprintf("%s/request_token", basicPath)) - token = data.(string) + data := getResp(t, fmt.Sprintf("%s/request_token?public_key=%s&page=%d&page_size=%d", basicPath, proverPubkey, 1, 2)) + token = data.(map[string]interface{})["token"].(string) t.Log("token: ", token) } func testGetProverTasksByProver(t *testing.T) { - data := getResp(t, fmt.Sprintf("%s/tasks?pubkey=%s", basicPath, proverPubkey)) + data := getResp(t, fmt.Sprintf("%s/tasks?public_key=%s", basicPath, proverPubkey)) tasks := data.([]api_types.ProverTaskSchema) assert.Equal(t, task2.TaskID, tasks[0].TaskID) assert.Equal(t, task1.TaskID, tasks[1].TaskID) } func testGetTotalRewards(t *testing.T) { - data := getResp(t, fmt.Sprintf("%s/total_rewards?pubkey=%s", basicPath, proverPubkey)) + data := getResp(t, fmt.Sprintf("%s/total_rewards?public_key=%s", basicPath, proverPubkey)) schema := data.(api_types.ProverTotalRewardsSchema) assert.Equal(t, big.NewInt(22).String(), schema.Rewards) } @@ -106,7 +106,8 @@ func getResp(t *testing.T, url string) interface{} { res := new(api_types.Response) assert.NoError(t, json.Unmarshal(byt, res)) - assert.Equal(t, 0, res.ErrCode) + t.Log("----byt is ", string(byt)) + assert.Equal(t, api_types.Success, res.ErrCode) return res.Data } From f33b4b0d3a400cfc113d334facc1793238f758f2 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Tue, 18 Jul 2023 22:03:03 +0800 Subject: [PATCH 56/68] some fix --- prover-stats-api/test/prover_task_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index d85b70e3c7..188c72282c 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -68,13 +68,13 @@ func TestProverTaskAPIs(t *testing.T) { } func testRequestToken(t *testing.T) { - data := getResp(t, fmt.Sprintf("%s/request_token?public_key=%s&page=%d&page_size=%d", basicPath, proverPubkey, 1, 2)) - token = data.(map[string]interface{})["token"].(string) + data := getResp(t, fmt.Sprintf("%s/request_token?public_key=%s", basicPath, proverPubkey)) + token = fmt.Sprintf("Bearer %s", data.(map[string]interface{})["token"].(string)) t.Log("token: ", token) } func testGetProverTasksByProver(t *testing.T) { - data := getResp(t, fmt.Sprintf("%s/tasks?public_key=%s", basicPath, proverPubkey)) + data := getResp(t, fmt.Sprintf("%s/tasks?public_key=%s&page=%d&limit=%d", basicPath, proverPubkey, 0, 10)) tasks := data.([]api_types.ProverTaskSchema) assert.Equal(t, task2.TaskID, tasks[0].TaskID) assert.Equal(t, task1.TaskID, tasks[1].TaskID) From 2c3cce387609dc599df45c5a668362911c45ec3c Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 19 Jul 2023 09:51:11 +0800 Subject: [PATCH 57/68] change field --- prover-stats-api/internal/types/prover_task.go | 2 +- prover-stats-api/test/prover_task_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/prover-stats-api/internal/types/prover_task.go b/prover-stats-api/internal/types/prover_task.go index 8529bdc6e4..57e003080c 100644 --- a/prover-stats-api/internal/types/prover_task.go +++ b/prover-stats-api/internal/types/prover_task.go @@ -5,7 +5,7 @@ import "time" type ProverTasksPaginationParameter struct { PublicKey string `form:"public_key" json:"public_key" binding:"required"` Page int `form:"page" json:"page" binding:"required"` - PageSize int `form:"page_size" json:"limit" binding:"required"` + PageSize int `form:"page_size" json:"page_size" binding:"required"` } type ProverTaskSchema struct { diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index 188c72282c..0275b6d4e4 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -74,7 +74,7 @@ func testRequestToken(t *testing.T) { } func testGetProverTasksByProver(t *testing.T) { - data := getResp(t, fmt.Sprintf("%s/tasks?public_key=%s&page=%d&limit=%d", basicPath, proverPubkey, 0, 10)) + data := getResp(t, fmt.Sprintf("%s/tasks?public_key=%s&page=%d&page_size=%d", basicPath, proverPubkey, 0, 10)) tasks := data.([]api_types.ProverTaskSchema) assert.Equal(t, task2.TaskID, tasks[0].TaskID) assert.Equal(t, task1.TaskID, tasks[1].TaskID) From 502a8a7cae28f3113b8097a94e4ad42ac1ea443d Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 19 Jul 2023 09:58:49 +0800 Subject: [PATCH 58/68] feat: add empty line --- prover-stats-api/Makefile | 2 +- prover-stats-api/README | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/prover-stats-api/Makefile b/prover-stats-api/Makefile index 856427ebf7..213db87172 100644 --- a/prover-stats-api/Makefile +++ b/prover-stats-api/Makefile @@ -10,4 +10,4 @@ swag: swag init -g ./cmd/main.go test: - go test -v $(PWD)/... \ No newline at end of file + go test -v $(PWD)/... diff --git a/prover-stats-api/README b/prover-stats-api/README index 26c08980c7..01f3aaa3ba 100644 --- a/prover-stats-api/README +++ b/prover-stats-api/README @@ -27,4 +27,4 @@ http://localhost:8990/swagger/index.html ``` cd ./prover-stats-api make swag -``` \ No newline at end of file +``` From 32ef14483430af78c4d6653a76068a8fb99b7a0d Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 19 Jul 2023 10:03:55 +0800 Subject: [PATCH 59/68] feat: add empty line --- prover-stats-api/conf/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prover-stats-api/conf/config.json b/prover-stats-api/conf/config.json index d4c7dd0e99..3d371ce5f7 100644 --- a/prover-stats-api/conf/config.json +++ b/prover-stats-api/conf/config.json @@ -9,4 +9,4 @@ "secret": "prover secret key", "token_expire_duration": 3600 } -} \ No newline at end of file +} From 821fac837badbd6d3d398689d7603bdd8472c22d Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 19 Jul 2023 10:13:33 +0800 Subject: [PATCH 60/68] feat: rename variable name --- prover-stats-api/internal/controller/controller.go | 14 ++++++++++++-- prover-stats-api/internal/middleware/jwt.go | 5 ++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/prover-stats-api/internal/controller/controller.go b/prover-stats-api/internal/controller/controller.go index f74b254588..f89386b748 100644 --- a/prover-stats-api/internal/controller/controller.go +++ b/prover-stats-api/internal/controller/controller.go @@ -1,11 +1,21 @@ package controller -import "gorm.io/gorm" +import ( + "sync" + + "gorm.io/gorm" +) var ( ProverTask *ProverTaskController + Auth *AuthController + + initControllerOnce sync.Once ) func InitController(db *gorm.DB) { - ProverTask = NewProverTaskController(db) + initControllerOnce.Do(func() { + ProverTask = NewProverTaskController(db) + Auth = NewAuthController() + }) } diff --git a/prover-stats-api/internal/middleware/jwt.go b/prover-stats-api/internal/middleware/jwt.go index 4da0ffacce..aa7eef3603 100644 --- a/prover-stats-api/internal/middleware/jwt.go +++ b/prover-stats-api/internal/middleware/jwt.go @@ -18,19 +18,18 @@ const IdentityKey = "public_key" // AuthMiddleware jwt auth middleware func AuthMiddleware(conf *config.Config) *jwt.GinJWTMiddleware { - authLogic := controller.NewAuthController() jwtMiddleware, err := jwt.New(&jwt.GinJWTMiddleware{ PayloadFunc: PayloadFunc, IdentityHandler: IdentityHandler, IdentityKey: IdentityKey, Key: []byte(conf.Auth.Secret), Timeout: time.Second * time.Duration(conf.Auth.TokenExpireDuration), - Authenticator: authLogic.Login, + Authenticator: controller.Auth.Login, Unauthorized: Unauthorized, TokenLookup: "header: Authorization, query: token, cookie: jwt", TokenHeadName: "Bearer", TimeFunc: time.Now, - LoginResponse: authLogic.LoginResponse, + LoginResponse: controller.Auth.LoginResponse, }) if err != nil { From c6e2b7ebda824d2ba7b01bb1106ea2b1f89fe103 Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 19 Jul 2023 10:23:59 +0800 Subject: [PATCH 61/68] feat: comment tidy --- prover-stats-api/internal/controller/prover_task.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/prover-stats-api/internal/controller/prover_task.go b/prover-stats-api/internal/controller/prover_task.go index 30fa627907..1eb4303a62 100644 --- a/prover-stats-api/internal/controller/prover_task.go +++ b/prover-stats-api/internal/controller/prover_task.go @@ -30,9 +30,9 @@ func NewProverTaskController(db *gorm.DB) *ProverTaskController { // @Accept plain // @Produce plain // @Param pubkey query string true "prover public key" -// @Param page query int true "page" -// @Param page_size query int true "page_size" -// @Param Authorization header string false "Bearer license" +// @Param page query int true "page" +// @Param page_size query int true "page_size" +// @Param Authorization header string false "Bearer license" // @Success 200 {array} types.ProverTaskSchema // @Router /api/prover_task/v1/tasks [get] func (c *ProverTaskController) ProverTasks(ctx *gin.Context) { @@ -73,7 +73,7 @@ func (c *ProverTaskController) ProverTasks(ctx *gin.Context) { // @Accept plain // @Produce plain // @Param pubkey path string true "prover public key" -// @Param Authorization header string false "Bearer license" +// @Param Authorization header string false "Bearer license" // @Success 200 {object} types.ProverTotalRewardsSchema // @Router /api/prover_task/v1/total_rewards [get] func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { @@ -105,7 +105,7 @@ func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { // @Accept plain // @Produce plain // @Param task_id path string true "prover task hash" -// @Param Authorization header string false "Bearer license" +// @Param Authorization header string false "Bearer license" // @Success 200 {object} types.ProverTaskSchema // @Router /api/prover_task/v1/task [get] func (c *ProverTaskController) GetTask(ctx *gin.Context) { From 256e1261b23fd223dcf65849cc9a68b0dd1bc806 Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 19 Jul 2023 10:27:53 +0800 Subject: [PATCH 62/68] feat: format import --- prover-stats-api/internal/route/route.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/prover-stats-api/internal/route/route.go b/prover-stats-api/internal/route/route.go index ea6d9ad1f1..fe02f764cd 100644 --- a/prover-stats-api/internal/route/route.go +++ b/prover-stats-api/internal/route/route.go @@ -5,9 +5,8 @@ import ( swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" - "scroll-tech/prover-stats-api/internal/controller" - "scroll-tech/prover-stats-api/internal/config" + "scroll-tech/prover-stats-api/internal/controller" "scroll-tech/prover-stats-api/internal/middleware" ) From 94ac36e1bb5411170e12f41781f65c8874e4c7a7 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 19 Jul 2023 10:45:00 +0800 Subject: [PATCH 63/68] fix test and lint --- .github/workflows/prover_stats_api.yml | 28 +++++++++---------- prover-stats-api/Makefile | 3 ++ prover-stats-api/internal/config/config.go | 2 ++ prover-stats-api/internal/controller/auth.go | 5 +++- .../internal/controller/controller.go | 2 ++ .../internal/controller/prover_task.go | 20 +++++++------ .../internal/logic/prover_task.go | 5 ++++ prover-stats-api/internal/middleware/jwt.go | 6 +++- prover-stats-api/internal/orm/orm_test.go | 17 +++++------ prover-stats-api/internal/route/route.go | 1 + prover-stats-api/internal/types/auth.go | 2 ++ prover-stats-api/internal/types/errno.go | 10 +++++-- .../internal/types/prover_task.go | 5 ++++ prover-stats-api/internal/types/response.go | 3 +- prover-stats-api/test/prover_task_test.go | 23 +++++++++------ 15 files changed, 85 insertions(+), 47 deletions(-) diff --git a/.github/workflows/prover_stats_api.yml b/.github/workflows/prover_stats_api.yml index 2550d78f7c..61d4ac8143 100644 --- a/.github/workflows/prover_stats_api.yml +++ b/.github/workflows/prover_stats_api.yml @@ -25,20 +25,20 @@ defaults: working-directory: 'prover-stats-api' jobs: - # check: - # if: github.event.pull_request.draft == false - # runs-on: ubuntu-latest - # steps: - # - name: Install Go - # uses: actions/setup-go@v2 - # with: - # go-version: 1.19.x - # - name: Checkout code - # uses: actions/checkout@v2 - # - name: Lint - # run: | - # rm -rf $HOME/.cache/golangci-lint - # make lint + check: + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.19.x + - name: Checkout code + uses: actions/checkout@v2 + - name: Lint + run: | + rm -rf $HOME/.cache/golangci-lint + make lint test: if: github.event.pull_request.draft == false runs-on: ubuntu-latest diff --git a/prover-stats-api/Makefile b/prover-stats-api/Makefile index 213db87172..a527dc3c8b 100644 --- a/prover-stats-api/Makefile +++ b/prover-stats-api/Makefile @@ -11,3 +11,6 @@ swag: test: go test -v $(PWD)/... + +lint: ## Lint the files - used for CI + GOBIN=$(PWD)/build/bin go run ../build/lint.go diff --git a/prover-stats-api/internal/config/config.go b/prover-stats-api/internal/config/config.go index 3bae47c3c4..0fdac9520e 100644 --- a/prover-stats-api/internal/config/config.go +++ b/prover-stats-api/internal/config/config.go @@ -7,11 +7,13 @@ import ( "scroll-tech/common/database" ) +// Config provides the config of prover-stats-api type Config struct { DBConfig *database.Config `json:"db_config"` Auth Auth `json:"auth"` } +// Auth provides the auth of prover-stats-api type Auth struct { Secret string `json:"secret"` TokenExpireDuration int `json:"token_expire_duration"` // unit: seconds diff --git a/prover-stats-api/internal/controller/auth.go b/prover-stats-api/internal/controller/auth.go index 994894aa65..d5ad90ee82 100644 --- a/prover-stats-api/internal/controller/auth.go +++ b/prover-stats-api/internal/controller/auth.go @@ -10,9 +10,11 @@ import ( "scroll-tech/prover-stats-api/internal/types" ) +// AuthController is auth API type AuthController struct { } +// NewAuthController returns an AuthController instance func NewAuthController() *AuthController { return &AuthController{} } @@ -45,10 +47,11 @@ func (a *AuthController) checkValidPublicKey() bool { return true } +// LoginResponse response login api func (a *AuthController) LoginResponse(c *gin.Context, code int, message string, time time.Time) { resp := types.LoginSchema{ Time: time, Token: message, } - types.RenderJson(c, code, nil, resp) + types.RenderJSON(c, code, nil, resp) } diff --git a/prover-stats-api/internal/controller/controller.go b/prover-stats-api/internal/controller/controller.go index f89386b748..3834a2dbd1 100644 --- a/prover-stats-api/internal/controller/controller.go +++ b/prover-stats-api/internal/controller/controller.go @@ -7,12 +7,14 @@ import ( ) var ( + // ProverTask is controller instance ProverTask *ProverTaskController Auth *AuthController initControllerOnce sync.Once ) +// InitController inits Controller with database func InitController(db *gorm.DB) { initControllerOnce.Do(func() { ProverTask = NewProverTaskController(db) diff --git a/prover-stats-api/internal/controller/prover_task.go b/prover-stats-api/internal/controller/prover_task.go index 1eb4303a62..6d79ab54e2 100644 --- a/prover-stats-api/internal/controller/prover_task.go +++ b/prover-stats-api/internal/controller/prover_task.go @@ -13,10 +13,12 @@ import ( "scroll-tech/prover-stats-api/internal/types" ) +// ProverTaskController provides API controller. type ProverTaskController struct { logic *logic.ProverTaskLogic } +// NewProverTaskController provides a ProverTask instance. func NewProverTaskController(db *gorm.DB) *ProverTaskController { return &ProverTaskController{ logic: logic.NewProverTaskLogic(db), @@ -39,14 +41,14 @@ func (c *ProverTaskController) ProverTasks(ctx *gin.Context) { var pp types.ProverTasksPaginationParameter if err := ctx.ShouldBind(&pp); err != nil { nerr := fmt.Errorf("parameter invalid, err:%w", err) - types.RenderJson(ctx, types.ErrParameterInvalidNo, nerr, nil) + types.RenderJSON(ctx, types.ErrParameterInvalidNo, nerr, nil) return } tasks, err := c.logic.GetTasksByProver(ctx, pp.PublicKey, pp.Page, pp.PageSize) if err != nil { nerr := fmt.Errorf("controller.ProverTasks err:%w", err) - types.RenderJson(ctx, types.ErrProverTaskFailure, nerr, nil) + types.RenderJSON(ctx, types.ErrProverTaskFailure, nerr, nil) return } @@ -63,7 +65,7 @@ func (c *ProverTaskController) ProverTasks(ctx *gin.Context) { proverTaskSchemas = append(proverTaskSchemas, proverTaskSchema) } - types.RenderJson(ctx, types.Success, nil, proverTaskSchemas) + types.RenderJSON(ctx, types.Success, nil, proverTaskSchemas) } // GetTotalRewards godoc @@ -80,14 +82,14 @@ func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { var pp types.ProverTotalRewardsParameter if err := ctx.ShouldBind(&pp); err != nil { nerr := fmt.Errorf("parameter invalid, err:%w", err) - types.RenderJson(ctx, types.ErrParameterInvalidNo, nerr, nil) + types.RenderJSON(ctx, types.ErrParameterInvalidNo, nerr, nil) return } rewards, err := c.logic.GetTotalRewards(ctx, pp.PublicKey) if err != nil { nerr := fmt.Errorf("controller.GetTotalRewards, err:%w", err) - types.RenderJson(ctx, types.ErrProverTotalRewardFailure, nerr, nil) + types.RenderJSON(ctx, types.ErrProverTotalRewardFailure, nerr, nil) return } @@ -95,7 +97,7 @@ func (c *ProverTaskController) GetTotalRewards(ctx *gin.Context) { Rewards: rewards.String(), } - types.RenderJson(ctx, types.Success, nil, resp) + types.RenderJSON(ctx, types.Success, nil, resp) } // GetTask godoc @@ -112,14 +114,14 @@ func (c *ProverTaskController) GetTask(ctx *gin.Context) { var pp types.ProverTaskParameter if err := ctx.ShouldBind(&pp); err != nil { nerr := fmt.Errorf("parameter invalid, err:%w", err) - types.RenderJson(ctx, types.ErrParameterInvalidNo, nerr, nil) + types.RenderJSON(ctx, types.ErrParameterInvalidNo, nerr, nil) return } task, err := c.logic.GetTask(ctx, pp.TaskID) if err != nil { nerr := fmt.Errorf("controller.GetTask, err:%w", err) - types.RenderJson(ctx, types.ErrProverTotalRewardFailure, nerr, nil) + types.RenderJSON(ctx, types.ErrProverTotalRewardFailure, nerr, nil) return } @@ -132,5 +134,5 @@ func (c *ProverTaskController) GetTask(ctx *gin.Context) { CreatedAt: task.CreatedAt, } - types.RenderJson(ctx, types.Success, nil, schema) + types.RenderJSON(ctx, types.Success, nil, schema) } diff --git a/prover-stats-api/internal/logic/prover_task.go b/prover-stats-api/internal/logic/prover_task.go index 53a8b7c56a..24c5de7caf 100644 --- a/prover-stats-api/internal/logic/prover_task.go +++ b/prover-stats-api/internal/logic/prover_task.go @@ -9,22 +9,26 @@ import ( "scroll-tech/prover-stats-api/internal/orm" ) +// ProverTaskLogic deals the prover task logic with orm. type ProverTaskLogic struct { proverTaskOrm *orm.ProverTask } +// NewProverTaskLogic provides a ProverTaskLogic with database instance. func NewProverTaskLogic(db *gorm.DB) *ProverTaskLogic { return &ProverTaskLogic{ proverTaskOrm: orm.NewProverTask(db), } } +// GetTasksByProver returns tasks by given prover's public key and page, page size. func (p *ProverTaskLogic) GetTasksByProver(ctx context.Context, pubkey string, page, pageSize int) ([]*orm.ProverTask, error) { offset := (page - 1) * pageSize limit := pageSize return p.proverTaskOrm.GetProverTasksByProver(ctx, pubkey, offset, limit) } +// GetTotalRewards returns prover's total rewards by given public key. func (p *ProverTaskLogic) GetTotalRewards(ctx context.Context, pubkey string) (*big.Int, error) { totalReward, err := p.proverTaskOrm.GetProverTotalReward(ctx, pubkey) if err != nil { @@ -33,6 +37,7 @@ func (p *ProverTaskLogic) GetTotalRewards(ctx context.Context, pubkey string) (* return totalReward, nil } +// GetTask returns ProverTask by given task id. func (p *ProverTaskLogic) GetTask(ctx context.Context, taskID string) (*orm.ProverTask, error) { task, err := p.proverTaskOrm.GetProverTasksByHash(ctx, taskID) if err != nil { diff --git a/prover-stats-api/internal/middleware/jwt.go b/prover-stats-api/internal/middleware/jwt.go index aa7eef3603..979876f0db 100644 --- a/prover-stats-api/internal/middleware/jwt.go +++ b/prover-stats-api/internal/middleware/jwt.go @@ -14,6 +14,7 @@ import ( "scroll-tech/prover-stats-api/internal/types" ) +// IdentityKey is auth key const IdentityKey = "public_key" // AuthMiddleware jwt auth middleware @@ -43,11 +44,13 @@ func AuthMiddleware(conf *config.Config) *jwt.GinJWTMiddleware { return jwtMiddleware } +// Unauthorized response Unauthorized error message to client func Unauthorized(c *gin.Context, code int, message string) { err := errors.New(message) - types.RenderJson(c, code, err, nil) + types.RenderJSON(c, code, err, nil) } +// PayloadFunc returns jwt.MapClaims with public key. func PayloadFunc(data interface{}) jwt.MapClaims { if v, ok := data.(types.LoginParameter); ok { return jwt.MapClaims{ @@ -57,6 +60,7 @@ func PayloadFunc(data interface{}) jwt.MapClaims { return jwt.MapClaims{} } +// IdentityHandler replies to client for /login func IdentityHandler(c *gin.Context) interface{} { claims := jwt.ExtractClaims(c) return &types.LoginParameter{ diff --git a/prover-stats-api/internal/orm/orm_test.go b/prover-stats-api/internal/orm/orm_test.go index 1def2e13c4..5d6b2316d8 100644 --- a/prover-stats-api/internal/orm/orm_test.go +++ b/prover-stats-api/internal/orm/orm_test.go @@ -75,23 +75,21 @@ func TestProverTaskOrm(t *testing.T) { err = proverTaskOrm.SetProverTask(context.Background(), &proverTask) assert.NoError(t, err) - proverTasks, err := proverTaskOrm.GetProverTasksByHashes(context.Background(), []string{"test-hash"}) + getTask, err := proverTaskOrm.GetProverTasksByHash(context.Background(), "test-hash") assert.NoError(t, err) - assert.Equal(t, 1, len(proverTasks)) - assert.Equal(t, proverTask.ProverName, proverTasks[0].ProverName) + assert.Equal(t, proverTask.ProverName, getTask.ProverName) // test decimal reward, get reward - resultReward := proverTasks[0].Reward.BigInt() + resultReward := getTask.Reward.BigInt() assert.Equal(t, resultReward, reward) assert.Equal(t, resultReward.String(), "18446744073709551616") proverTask.ProvingStatus = int16(types.RollerProofValid) err = proverTaskOrm.SetProverTask(context.Background(), &proverTask) assert.NoError(t, err) - proverTasks, err = proverTaskOrm.GetProverTasksByHashes(context.Background(), []string{"test-hash"}) + getTask, err = proverTaskOrm.GetProverTasksByHash(context.Background(), "test-hash") assert.NoError(t, err) - assert.Equal(t, 1, len(proverTasks)) - assert.Equal(t, proverTask.ProvingStatus, proverTasks[0].ProvingStatus) + assert.Equal(t, proverTask.ProvingStatus, getTask.ProvingStatus) } func TestProverTaskOrmUint256(t *testing.T) { @@ -112,10 +110,9 @@ func TestProverTaskOrmUint256(t *testing.T) { err = proverTaskOrm.SetProverTask(context.Background(), &proverTask) assert.NoError(t, err) - proverTasksUint256, err := proverTaskOrm.GetProverTasksByHashes(context.Background(), []string{"test-hash"}) + proverTasksUint256, err := proverTaskOrm.GetProverTasksByHash(context.Background(), "test-hash") assert.NoError(t, err) - assert.Equal(t, 1, len(proverTasksUint256)) - resultRewardUint256 := proverTasksUint256[0].Reward.BigInt() + resultRewardUint256 := proverTasksUint256.Reward.BigInt() assert.Equal(t, resultRewardUint256, rewardUint256) assert.Equal(t, resultRewardUint256.String(), "115792089237316195423570985008687907853269984665640564039457584007913129639935") } diff --git a/prover-stats-api/internal/route/route.go b/prover-stats-api/internal/route/route.go index fe02f764cd..c10d442b32 100644 --- a/prover-stats-api/internal/route/route.go +++ b/prover-stats-api/internal/route/route.go @@ -10,6 +10,7 @@ import ( "scroll-tech/prover-stats-api/internal/middleware" ) +// Route routes the APIs func Route(router *gin.Engine, conf *config.Config) { router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) diff --git a/prover-stats-api/internal/types/auth.go b/prover-stats-api/internal/types/auth.go index c89c5bc44e..79a036783c 100644 --- a/prover-stats-api/internal/types/auth.go +++ b/prover-stats-api/internal/types/auth.go @@ -2,10 +2,12 @@ package types import "time" +// LoginParameter for /login api type LoginParameter struct { PublicKey string `form:"public_key" json:"public_key" binding:"required"` } +// LoginSchema for /login response type LoginSchema struct { Time time.Time `json:"time"` Token string `json:"token"` diff --git a/prover-stats-api/internal/types/errno.go b/prover-stats-api/internal/types/errno.go index 77a592c456..62a0de888d 100644 --- a/prover-stats-api/internal/types/errno.go +++ b/prover-stats-api/internal/types/errno.go @@ -1,8 +1,12 @@ package types const ( - Success = 200 - ErrParameterInvalidNo = 10001 - ErrProverTaskFailure = 10002 + // Success shows OK. + Success = 200 + // ErrParameterInvalidNo is invalid params + ErrParameterInvalidNo = 10001 + // ErrProverTaskFailure is getting prover task error + ErrProverTaskFailure = 10002 + // ErrProverTotalRewardFailure is getting total rewards error ErrProverTotalRewardFailure = 10003 ) diff --git a/prover-stats-api/internal/types/prover_task.go b/prover-stats-api/internal/types/prover_task.go index 57e003080c..bfa372b03c 100644 --- a/prover-stats-api/internal/types/prover_task.go +++ b/prover-stats-api/internal/types/prover_task.go @@ -2,12 +2,14 @@ package types import "time" +// ProverTasksPaginationParameter for GetTasksByProver request type ProverTasksPaginationParameter struct { PublicKey string `form:"public_key" json:"public_key" binding:"required"` Page int `form:"page" json:"page" binding:"required"` PageSize int `form:"page_size" json:"page_size" binding:"required"` } +// ProverTaskSchema is response for ProverTask type ProverTaskSchema struct { TaskID string `json:"task_id"` ProverName string `json:"prover_name"` @@ -18,14 +20,17 @@ type ProverTaskSchema struct { CreatedAt time.Time `json:"created_at"` } +// ProverTotalRewardsParameter for GetTotalRewards request type ProverTotalRewardsParameter struct { PublicKey string `form:"public_key" json:"public_key" binding:"required"` } +// ProverTotalRewardsSchema is response for GetTotalRewards type ProverTotalRewardsSchema struct { Rewards string `json:"rewards"` } +// ProverTaskParameter for GetTask request type ProverTaskParameter struct { TaskID string `form:"task_id" json:"task_id" binding:"required"` } diff --git a/prover-stats-api/internal/types/response.go b/prover-stats-api/internal/types/response.go index 3b0c74ad5a..61a69b1f8d 100644 --- a/prover-stats-api/internal/types/response.go +++ b/prover-stats-api/internal/types/response.go @@ -13,7 +13,8 @@ type Response struct { Data interface{} `json:"data"` } -func RenderJson(ctx *gin.Context, errCode int, err error, data interface{}) { +// RenderJSON renders response with json +func RenderJSON(ctx *gin.Context, errCode int, err error, data interface{}) { var errMsg string if err != nil { errMsg = err.Error() diff --git a/prover-stats-api/test/prover_task_test.go b/prover-stats-api/test/prover_task_test.go index 0275b6d4e4..e88f9c8d82 100644 --- a/prover-stats-api/test/prover_task_test.go +++ b/prover-stats-api/test/prover_task_test.go @@ -74,22 +74,28 @@ func testRequestToken(t *testing.T) { } func testGetProverTasksByProver(t *testing.T) { - data := getResp(t, fmt.Sprintf("%s/tasks?public_key=%s&page=%d&page_size=%d", basicPath, proverPubkey, 0, 10)) - tasks := data.([]api_types.ProverTaskSchema) - assert.Equal(t, task2.TaskID, tasks[0].TaskID) - assert.Equal(t, task1.TaskID, tasks[1].TaskID) + datas := getResp(t, fmt.Sprintf("%s/tasks?public_key=%s&page=%d&page_size=%d", basicPath, proverPubkey, 1, 10)) + anys := datas.([]interface{}) + var tasks []map[string]interface{} + for _, data := range anys { + task := data.(map[string]interface{}) + tasks = append(tasks, task) + } + + assert.Equal(t, task2.TaskID, tasks[0]["task_id"]) + assert.Equal(t, task1.TaskID, tasks[1]["task_id"]) } func testGetTotalRewards(t *testing.T) { data := getResp(t, fmt.Sprintf("%s/total_rewards?public_key=%s", basicPath, proverPubkey)) - schema := data.(api_types.ProverTotalRewardsSchema) - assert.Equal(t, big.NewInt(22).String(), schema.Rewards) + schema := data.(map[string]interface{}) + assert.Equal(t, big.NewInt(22).String(), schema["rewards"]) } func testGetProverTask(t *testing.T) { data := getResp(t, fmt.Sprintf("%s/task?task_id=1", basicPath)) - task := data.(api_types.ProverTaskSchema) - assert.Equal(t, task1.TaskID, task.TaskID) + task := data.(map[string]interface{}) + assert.Equal(t, task1.TaskID, task["task_id"]) } func getResp(t *testing.T, url string) interface{} { @@ -99,6 +105,7 @@ func getResp(t *testing.T, url string) interface{} { resp, err := http.DefaultClient.Do(req) assert.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, resp.StatusCode, http.StatusOK) byt, err := io.ReadAll(resp.Body) From 11f167b56030af4ee757f4285f5bd8356bf178fa Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 19 Jul 2023 10:48:30 +0800 Subject: [PATCH 64/68] fix ci --- .github/workflows/prover_stats_api.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/prover_stats_api.yml b/.github/workflows/prover_stats_api.yml index 61d4ac8143..a4518f4cc2 100644 --- a/.github/workflows/prover_stats_api.yml +++ b/.github/workflows/prover_stats_api.yml @@ -25,7 +25,7 @@ defaults: working-directory: 'prover-stats-api' jobs: - check: + check: if: github.event.pull_request.draft == false runs-on: ubuntu-latest steps: From a8f6d83b459fcc0c58741aac3c456fce4255df3b Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 19 Jul 2023 10:53:43 +0800 Subject: [PATCH 65/68] fix lint --- prover-stats-api/internal/controller/controller.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/prover-stats-api/internal/controller/controller.go b/prover-stats-api/internal/controller/controller.go index 3834a2dbd1..40f99270ea 100644 --- a/prover-stats-api/internal/controller/controller.go +++ b/prover-stats-api/internal/controller/controller.go @@ -9,7 +9,8 @@ import ( var ( // ProverTask is controller instance ProverTask *ProverTaskController - Auth *AuthController + // Auth is controller instance + Auth *AuthController initControllerOnce sync.Once ) From 383d06717e194e21f816c2a6ef20bffa2e1410bf Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 19 Jul 2023 10:58:44 +0800 Subject: [PATCH 66/68] check pubkey exists --- prover-stats-api/internal/controller/auth.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/prover-stats-api/internal/controller/auth.go b/prover-stats-api/internal/controller/auth.go index d5ad90ee82..3f88aeae06 100644 --- a/prover-stats-api/internal/controller/auth.go +++ b/prover-stats-api/internal/controller/auth.go @@ -3,6 +3,7 @@ package controller import ( "errors" "fmt" + "strings" "time" "github.com/gin-gonic/gin" @@ -34,7 +35,9 @@ func (a *AuthController) Login(c *gin.Context) (interface{}, error) { return "", fmt.Errorf("missing the public_key, err:%w", err) } - // TODO check public key is exist + if strings.TrimSpace(login.PublicKey) == "" { + return nil, errors.New("empty public_key") + } if a.checkValidPublicKey() { return types.LoginParameter{PublicKey: login.PublicKey}, nil From f85e39aa7f5456b80908369ef54eb4bc7b84ac11 Mon Sep 17 00:00:00 2001 From: xinran chen Date: Wed, 19 Jul 2023 11:11:05 +0800 Subject: [PATCH 67/68] fix --- prover-stats-api/internal/controller/auth.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/prover-stats-api/internal/controller/auth.go b/prover-stats-api/internal/controller/auth.go index 3f88aeae06..65be021a82 100644 --- a/prover-stats-api/internal/controller/auth.go +++ b/prover-stats-api/internal/controller/auth.go @@ -35,19 +35,15 @@ func (a *AuthController) Login(c *gin.Context) (interface{}, error) { return "", fmt.Errorf("missing the public_key, err:%w", err) } - if strings.TrimSpace(login.PublicKey) == "" { - return nil, errors.New("empty public_key") - } - - if a.checkValidPublicKey() { + if a.checkValidPublicKey(login.PublicKey) { return types.LoginParameter{PublicKey: login.PublicKey}, nil } return nil, errors.New("incorrect public_key") } -func (a *AuthController) checkValidPublicKey() bool { - return true +func (a *AuthController) checkValidPublicKey(pubkey string) bool { + return strings.TrimSpace(pubkey) != "" } // LoginResponse response login api From 8ca10f6163169cc47a5136b5c0ce1f0b97814f38 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Thu, 20 Jul 2023 15:10:17 +0800 Subject: [PATCH 68/68] Update version.go --- common/version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/version/version.go b/common/version/version.go index c3711186eb..936178cfc8 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.0.23" +var tag = "v4.0.24" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok {