From 8b5eaeb32841f9fbd324a3dfb1bc5cab1b7fb149 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Thu, 30 Nov 2023 15:48:52 +0800 Subject: [PATCH 1/3] test --- testutils/suite.go | 70 ++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/testutils/suite.go b/testutils/suite.go index 5f31c969b..3ac6dd077 100644 --- a/testutils/suite.go +++ b/testutils/suite.go @@ -79,14 +79,16 @@ func (s *ClientTestSuite) SetupTest() { s.ProverEndpoints = []*url.URL{LocalRandomProverEndpoint()} s.proverServer = NewTestProverServer(s, l1ProverPrivKey, capacity.New(1024), s.ProverEndpoints[0]) - allowance, err := rpcCli.TaikoToken.Allowance( - nil, - crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey), - common.HexToAddress("TAIKO_L1_ADDRESS"), - ) + // allowance, err := rpcCli.TaikoToken.Allowance( + // nil, + // crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey), + // common.HexToAddress("TAIKO_L1_ADDRESS"), + // ) + + balance, err := rpcCli.TaikoToken.BalanceOf(nil, crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey)) s.Nil(err) - if allowance.Cmp(common.Big0) == 0 { + if balance.Cmp(common.Big0) == 0 { // Do not verify zk && sgx proofs in tests. securityConcilPrivKey, err := crypto.ToECDSA(common.Hex2Bytes(os.Getenv("L1_SECURITY_COUNCIL_PRIVATE_KEY"))) s.Nil(err) @@ -104,35 +106,35 @@ func (s *ClientTestSuite) SetupTest() { opts, err := bind.NewKeyedTransactorWithChainID(ownerPrivKey, rpcCli.L1ChainID) s.Nil(err) proverBalance := new(big.Int).Div(balance, common.Big2) - if proverBalance.Cmp(common.Big0) == 1 { - tx, err := rpcCli.TaikoToken.Transfer(opts, crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey), proverBalance) - s.Nil(err) - _, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx) - s.Nil(err) - - // Deposit taiko tokens for provers. - opts, err = bind.NewKeyedTransactorWithChainID(l1ProverPrivKey, rpcCli.L1ChainID) - s.Nil(err) - - _, err = rpcCli.TaikoToken.Approve( - opts, - common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")), - new(big.Int).Exp(big.NewInt(1_000_000_000), big.NewInt(18), nil), - ) - s.Nil(err) - - _, err = rpcCli.TaikoToken.Approve( - opts, - common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), - new(big.Int).Exp(big.NewInt(1_000_000_000), big.NewInt(18), nil), - ) - s.Nil(err) - - _, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx) - s.Nil(err) - } - } + s.Greater(proverBalance.Cmp(common.Big0), 0) + + tx, err := rpcCli.TaikoToken.Transfer(opts, crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey), proverBalance) + s.Nil(err) + _, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx) + s.Nil(err) + + // Deposit taiko tokens for provers. + opts, err = bind.NewKeyedTransactorWithChainID(l1ProverPrivKey, rpcCli.L1ChainID) + s.Nil(err) + bigInt := new(big.Int).Exp(big.NewInt(1_000_000_000), big.NewInt(18), nil) + _, err = rpcCli.TaikoToken.Approve( + opts, + common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")), + bigInt, + ) + s.Nil(err) + + _, err = rpcCli.TaikoToken.Approve( + opts, + common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), + bigInt, + ) + s.Nil(err) + + _, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx) + s.Nil(err) + } s.Nil(rpcCli.L1RawRPC.CallContext(context.Background(), &s.testnetL1SnapshotID, "evm_snapshot")) s.NotEmpty(s.testnetL1SnapshotID) } From 5f3de6ef79431296b7b22f5f0e4734e51cd8a764 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Thu, 30 Nov 2023 16:00:15 +0800 Subject: [PATCH 2/3] remove unused code, fix comment --- testutils/suite.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/testutils/suite.go b/testutils/suite.go index 3ac6dd077..40187f26d 100644 --- a/testutils/suite.go +++ b/testutils/suite.go @@ -79,12 +79,6 @@ func (s *ClientTestSuite) SetupTest() { s.ProverEndpoints = []*url.URL{LocalRandomProverEndpoint()} s.proverServer = NewTestProverServer(s, l1ProverPrivKey, capacity.New(1024), s.ProverEndpoints[0]) - // allowance, err := rpcCli.TaikoToken.Allowance( - // nil, - // crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey), - // common.HexToAddress("TAIKO_L1_ADDRESS"), - // ) - balance, err := rpcCli.TaikoToken.BalanceOf(nil, crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey)) s.Nil(err) @@ -113,7 +107,7 @@ func (s *ClientTestSuite) SetupTest() { _, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx) s.Nil(err) - // Deposit taiko tokens for provers. + // Increase allowance for AssignmentHook and TaikoL1 opts, err = bind.NewKeyedTransactorWithChainID(l1ProverPrivKey, rpcCli.L1ChainID) s.Nil(err) From 43377fe686d1fad32526177eabfd0533670ceac5 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Thu, 30 Nov 2023 20:42:21 +0800 Subject: [PATCH 3/3] fixed swagger autogen --- docs/docs.go | 56 +++++++++++++++++++++++++++++++++++++++++++- docs/swagger.json | 56 +++++++++++++++++++++++++++++++++++++++++++- docs/swagger.yaml | 37 ++++++++++++++++++++++++++++- prover/server/api.go | 3 ++- 4 files changed, 148 insertions(+), 4 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index cd322bd2f..6de82f426 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -33,7 +33,6 @@ const docTemplate = `{ "application/json" ], "summary": "Try to accept a block proof assignment", - "operationId": "create-assignment", "parameters": [ { "description": "assignment request body", @@ -61,6 +60,29 @@ const docTemplate = `{ } } }, + "/signedBlocks": { + "get": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Get signed blocks", + "operationId": "get-signed-blocks", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/prover_server.SignedBlock" + } + } + } + } + } + }, "/status": { "get": { "consumes": [ @@ -123,6 +145,12 @@ const docTemplate = `{ "prover_server.ProposeBlockResponse": { "type": "object", "properties": { + "maxBlockID": { + "type": "integer" + }, + "maxProposedIn": { + "type": "integer" + }, "prover": { "type": "string" }, @@ -134,12 +162,35 @@ const docTemplate = `{ } } }, + "prover_server.SignedBlock": { + "type": "object", + "properties": { + "blockHash": { + "type": "string" + }, + "blockID": { + "type": "integer" + }, + "proverAddress": { + "type": "string" + }, + "signature": { + "type": "string" + } + } + }, "prover_server.Status": { "type": "object", "properties": { "currentCapacity": { "type": "integer" }, + "heartBeatSignature": { + "type": "array", + "items": { + "type": "integer" + } + }, "maxExpiry": { "type": "integer" }, @@ -151,6 +202,9 @@ const docTemplate = `{ }, "minSgxTierFee": { "type": "integer" + }, + "prover": { + "type": "string" } } } diff --git a/docs/swagger.json b/docs/swagger.json index e0db39db9..157ede6dd 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -24,7 +24,6 @@ "application/json" ], "summary": "Try to accept a block proof assignment", - "operationId": "create-assignment", "parameters": [ { "description": "assignment request body", @@ -52,6 +51,29 @@ } } }, + "/signedBlocks": { + "get": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "summary": "Get signed blocks", + "operationId": "get-signed-blocks", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/prover_server.SignedBlock" + } + } + } + } + } + }, "/status": { "get": { "consumes": [ @@ -114,6 +136,12 @@ "prover_server.ProposeBlockResponse": { "type": "object", "properties": { + "maxBlockID": { + "type": "integer" + }, + "maxProposedIn": { + "type": "integer" + }, "prover": { "type": "string" }, @@ -125,12 +153,35 @@ } } }, + "prover_server.SignedBlock": { + "type": "object", + "properties": { + "blockHash": { + "type": "string" + }, + "blockID": { + "type": "integer" + }, + "proverAddress": { + "type": "string" + }, + "signature": { + "type": "string" + } + } + }, "prover_server.Status": { "type": "object", "properties": { "currentCapacity": { "type": "integer" }, + "heartBeatSignature": { + "type": "array", + "items": { + "type": "integer" + } + }, "maxExpiry": { "type": "integer" }, @@ -142,6 +193,9 @@ }, "minSgxTierFee": { "type": "integer" + }, + "prover": { + "type": "string" } } } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 348f3bf08..e6d809428 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -25,6 +25,10 @@ definitions: type: object prover_server.ProposeBlockResponse: properties: + maxBlockID: + type: integer + maxProposedIn: + type: integer prover: type: string signedPayload: @@ -32,10 +36,25 @@ definitions: type: integer type: array type: object + prover_server.SignedBlock: + properties: + blockHash: + type: string + blockID: + type: integer + proverAddress: + type: string + signature: + type: string + type: object prover_server.Status: properties: currentCapacity: type: integer + heartBeatSignature: + items: + type: integer + type: array maxExpiry: type: integer minOptimisticTierFee: @@ -44,6 +63,8 @@ definitions: type: integer minSgxTierFee: type: integer + prover: + type: string type: object info: contact: @@ -61,7 +82,6 @@ paths: post: consumes: - application/json - operationId: create-assignment parameters: - description: assignment request body in: body @@ -81,6 +101,21 @@ paths: schema: type: string summary: Try to accept a block proof assignment + /signedBlocks: + get: + consumes: + - application/json + operationId: get-signed-blocks + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/prover_server.SignedBlock' + type: array + summary: Get signed blocks /status: get: consumes: diff --git a/prover/server/api.go b/prover/server/api.go index f3b9db554..e6b158100 100644 --- a/prover/server/api.go +++ b/prover/server/api.go @@ -218,6 +218,7 @@ func (srv *ProverServer) CreateAssignment(c echo.Context) error { }) } +// SignedBlock represents a signed block. type SignedBlock struct { BlockID uint64 `json:"blockID"` BlockHash string `json:"blockHash"` @@ -231,7 +232,7 @@ type SignedBlock struct { // @ID get-signed-blocks // @Accept json // @Produce json -// @Success 200 {object} []SignedBlocks +// @Success 200 {object} []SignedBlock // @Router /signedBlocks [get] func (srv *ProverServer) GetSignedBlocks(c echo.Context) error { latestBlock, err := srv.rpc.L2.BlockByNumber(c.Request().Context(), nil)