Skip to content

Commit

Permalink
Merge pull request #565 from tablelandnetwork/staging
Browse files Browse the repository at this point in the history
Prepare Release 1.3.2 (Ship 4b)
  • Loading branch information
brunocalza authored May 9, 2023
2 parents 556a9f3 + bea67d5 commit 75291ba
Show file tree
Hide file tree
Showing 22 changed files with 263 additions and 110 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Go Reference](https://pkg.go.dev/badge/github.com/textileio/go-tableland.svg)](https://pkg.go.dev/github.com/textileio/go-tableland) [![Go Report Card](https://goreportcard.com/badge/github.com/textileio/go-tableland)](https://goreportcard.com/report/github.com/textileio/go-tableland)
<h1 align="center">Tableland Validator</h1>

This repository contains the Go implementation of a Tableland validator.
A Go language implementation of the Tableland validator, enabling developers and service providers to run nodes on the Tableland network and host databases for web3 users and applications.

# What is a validator?

Expand Down Expand Up @@ -42,10 +42,13 @@ To understand better the usual work mechanics of the validator, let’s go throu
The validator detects the smart contract events using an EVM node API (e.g: `geth` node), which can be self-hosted or served by providers (e.g: Alchemy, Infura, etc).

# How can I run a validator?
# Running a validator

Soon we'll be creating full documentation on how to configure and run a validator, stay tuned.
If you're interested in running a Tableland validator, please [fill this form](https://hhueol4i6vp.typeform.com/to/gkcyeA22).
While network growth is not our immediate focus, we're excited about its potential in the future. If you're curious about the process, eager to contribute, or interested in experimenting, we encourage you to try running a validator. To get started, follow the step-by-step instructions provided in our [validator documentation](https://www.notion.so/textile/Validator-documentation-9f0cc2abf424410c8659fa939ed5095e?pvs=4).

We appreciate your interest and welcome any questions or feedback you may have during the process. As our project evolves, we'll be shifting our focus and priorities, including network expansion in the future. Stay tuned for updates and developments.

For projects that want to use the validator API, Tableland [maintains a public gateway](https://docs.tableland.xyz/gateway-api).

# Building from source

Expand Down
11 changes: 5 additions & 6 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/textileio/go-tableland/pkg/database"
"github.com/textileio/go-tableland/pkg/eventprocessor"
"github.com/textileio/go-tableland/pkg/eventprocessor/eventfeed"

"go.opentelemetry.io/otel/attribute"

efimpl "github.com/textileio/go-tableland/pkg/eventprocessor/eventfeed/impl"
Expand Down Expand Up @@ -72,18 +71,18 @@ func main() {
path.Join(dirPath, "database.db"),
)

db, err := database.Open(databaseURL, attribute.String("database", "main"))
if err != nil {
log.Fatal().Err(err).Msg("opening the read database")
}

// Restore provided backup (if configured).
if config.BootstrapBackupURL != "" {
if err := restoreBackup(databaseURL, config.BootstrapBackupURL); err != nil {
log.Fatal().Err(err).Msg("restoring backup")
}
}

db, err := database.Open(databaseURL, attribute.String("database", "main"))
if err != nil {
log.Fatal().Err(err).Msg("opening the read database")
}

// Parser.
parser, err := createParser(config.QueryConstraints)
if err != nil {
Expand Down
20 changes: 0 additions & 20 deletions docker/deployed/testnet/healthbot/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
"Debug": true
},
"Chains": [
{
"ChainID": 421613,
"WalletPrivateKey": "${HEALTHBOT_ARBITRUM_GOERLI_PRIVATE_KEY}",
"AlchemyAPIKey": "${HEALTHBOT_ALCHEMY_ARBITRUM_GOERLI_API_KEY}",
"Probe": {
"CheckInterval": "1.5h",
"ReceiptTimeout": "25s",
"Tablename": "${HEALTHBOT_ARBITRUM_GOERLI_TABLE}"
}
},
{
"ChainID": 11155111,
"WalletPrivateKey": "${HEALTHBOT_ETHEREUM_SEPOLIA_PRIVATE_KEY}",
Expand All @@ -41,16 +31,6 @@
"Tablename": "${HEALTHBOT_POLYGON_MUMBAI_TABLE}"
}
},
{
"ChainID": 420,
"WalletPrivateKey": "${HEALTHBOT_OPTIMISM_GOERLI_PRIVATE_KEY}",
"AlchemyAPIKey": "${HEALTHBOT_ALCHEMY_OPTIMISM_GOERLI_API_KEY}",
"Probe": {
"CheckInterval": "1.5h",
"ReceiptTimeout": "25s",
"Tablename": "${HEALTHBOT_OPTIMISM_GOERLI_TABLE}"
}
},
{
"ChainID": 3141,
"WalletPrivateKey": "${HEALTHBOT_FILECOIN_HYPERSPACE_PRIVATE_KEY}",
Expand Down
20 changes: 13 additions & 7 deletions internal/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ func (g *GatewayService) GetReceiptByTransactionHash(
BlockNumber: receipt.BlockNumber,
IndexInBlock: receipt.IndexInBlock,
TxnHash: receipt.TxnHash,
TableID: receipt.TableID,
TableIDs: receipt.TableIDs,
Error: receipt.Error,
ErrorEventIdx: receipt.ErrorEventIdx,

// Deprecated
TableID: receipt.TableID,
}, true, nil
}

Expand Down Expand Up @@ -195,14 +198,17 @@ func (g *GatewayService) emptyMetadataImage() string {

// Receipt represents a Tableland receipt.
type Receipt struct {
ChainID tableland.ChainID
BlockNumber int64
IndexInBlock int64
TxnHash string

TableID *tables.TableID
ChainID tableland.ChainID
BlockNumber int64
IndexInBlock int64
TxnHash string
TableIDs []tables.TableID
Error *string
ErrorEventIdx *int

// Deprecated: the Receipt must hold information of all tables that were modified by the transaction.
// This field was replaced by TableIDs.
TableID *tables.TableID
}

// Table represents a system-wide table stored in Tableland.
Expand Down
19 changes: 17 additions & 2 deletions internal/gateway/impl/gateway_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,33 @@ func (s *GatewayStore) GetReceipt(
IndexInBlock: res.IndexInBlock,
TxnHash: txnHash,
}

if res.Error.Valid {
receipt.Error = &res.Error.String

errorEventIdx := int(res.ErrorEventIdx.Int64)
receipt.ErrorEventIdx = &errorEventIdx
}

if res.TableID.Valid {
id, err := tables.NewTableIDFromInt64(res.TableID.Int64)
if err != nil {
return gateway.Receipt{}, false, fmt.Errorf("parsing id to string: %s", err)
return gateway.Receipt{}, false, fmt.Errorf("parsing id integer: %s", err)
}
receipt.TableID = &id // nolint
}

if res.TableIds.Valid {
tableIdsStr := strings.Split(res.TableIds.String, ",")
tableIds := make([]tables.TableID, len(tableIdsStr))
for i, idStr := range tableIdsStr {
tableID, err := tables.NewTableID(idStr)
if err != nil {
return gateway.Receipt{}, false, fmt.Errorf("parsing id string: %s", err)
}
tableIds[i] = tableID
}
receipt.TableID = &id
receipt.TableIDs = tableIds
}

return receipt, true, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type TransactionReceipt struct {

TableId string `json:"table_id,omitempty"`

TableIds []string `json:"table_ids,omitempty"`

TransactionHash string `json:"transaction_hash,omitempty"`

BlockNumber int64 `json:"block_number,omitempty"`
Expand Down
11 changes: 9 additions & 2 deletions internal/router/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,21 @@ func (c *Controller) GetReceiptByTransactionHash(rw http.ResponseWriter, r *http
BlockNumber: receipt.BlockNumber,
ChainId: int32(receipt.ChainID),
}
if receipt.TableID != nil {
receiptResponse.TableId = receipt.TableID.String()
if receipt.TableID != nil { // nolint
receiptResponse.TableId = receipt.TableID.String() // nolint
}
if receipt.Error != nil {
receiptResponse.Error_ = *receipt.Error
receiptResponse.ErrorEventIdx = int32(*receipt.ErrorEventIdx)
}

ids := make([]string, len(receipt.TableIDs))
for i, tblID := range receipt.TableIDs {
ids[i] = tblID.String()
}

receiptResponse.TableIds = ids

rw.Header().Set("Content-Type", "application/json")
rw.WriteHeader(http.StatusOK)
_ = json.NewEncoder(rw).Encode(receiptResponse)
Expand Down
36 changes: 36 additions & 0 deletions internal/router/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math/big"
"net/http"
"net/http/httptest"
"strconv"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/textileio/go-tableland/internal/router/middlewares"
"github.com/textileio/go-tableland/internal/tableland"
"github.com/textileio/go-tableland/mocks"
"github.com/textileio/go-tableland/pkg/tables"
)

func TestQuery(t *testing.T) {
Expand Down Expand Up @@ -244,6 +246,40 @@ func TestTableNotFoundMock(t *testing.T) {
require.JSONEq(t, expJSON, rr.Body.String())
}

func TestReceipt(t *testing.T) {
r := mocks.NewGateway(t)
r.EXPECT().GetReceiptByTransactionHash(mock.Anything, mock.Anything, mock.Anything).Return(
gateway.Receipt{
ChainID: 1337,
BlockNumber: 1,
IndexInBlock: 0,
TxnHash: "0xb5c8bd9430b6cc87a0e2fe110ece6bf527fa4f170a4bc8cd032f768fc5219838",
TableIDs: []tables.TableID{tables.TableID(*big.NewInt(1)), tables.TableID(*big.NewInt(2))},
Error: nil,
ErrorEventIdx: nil,
},
true,
nil,
)

ctrl := NewController(r)

router := mux.NewRouter()
router.HandleFunc("/receipt/{chainId}/{transactionHash}", ctrl.GetReceiptByTransactionHash)

ctx := context.WithValue(context.Background(), middlewares.ContextKeyChainID, tableland.ChainID(1337))
// Table format
req, err := http.NewRequestWithContext(
ctx, "GET", "/receipt/1337/0xb5c8bd9430b6cc87a0e2fe110ece6bf527fa4f170a4bc8cd032f768fc5219838", nil,
)
require.NoError(t, err)
rr := httptest.NewRecorder()
router.ServeHTTP(rr, req)
require.Equal(t, http.StatusOK, rr.Code)
exp := `{"table_ids":["1","2"],"transaction_hash":"0xb5c8bd9430b6cc87a0e2fe110ece6bf527fa4f170a4bc8cd032f768fc5219838","block_number":1,"chain_id":1337}` // nolint
require.JSONEq(t, exp, rr.Body.String())
}

func parseJSONLString(val string) []string {
s := strings.TrimRight(val, "\n")
return strings.Split(s, "\n")
Expand Down
6 changes: 3 additions & 3 deletions internal/tableland/impl/tableland_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,11 @@ func requireReceipts(
require.NotZero(t, receipt.BlockNumber)
if ok {
require.Empty(t, receipt.Error)
require.NotNil(t, receipt.TableID)
require.NotZero(t, receipt.TableID)
require.NotNil(t, receipt.TableID) // nolint
require.NotZero(t, receipt.TableID) // nolint
} else {
require.NotEmpty(t, receipt.Error)
require.Nil(t, receipt.TableID)
require.Nil(t, receipt.TableID) // nolint
}
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/database/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/database/db/receipt.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/database/migrations/005_receipttableids.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE system_txn_receipts DROP COLUMN table_ids;
3 changes: 3 additions & 0 deletions pkg/database/migrations/005_receipttableids.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE system_txn_receipts ADD table_ids TEXT;

UPDATE system_txn_receipts SET table_ids=cast(table_id as text) WHERE table_id is not null;
Loading

0 comments on commit 75291ba

Please sign in to comment.