Repository: tablelandnetwork/go-tableland
Pull request #254 (2022-08-30 21:25:41)

Add missing rpc endpoint to spec
Looks like the validateWriteQuery endpoint was missing from the comment that describes the endpoints.   This adds it in the same style as the other endpoints


Patch:
diff --git a/pkg/eventprocessor/eventfeed/impl/analytics.go b/pkg/eventprocessor/eventfeed/impl/analytics.go
index 4f61e15..fcdb6a7 100644
--- a/pkg/eventprocessor/eventfeed/impl/analytics.go
+++ b/pkg/eventprocessor/eventfeed/impl/analytics.go
@@ -9,7 +9,6 @@ import (
 var fetchBlockExtraInfoDelay = time.Second * 10
 
 func (ef *EventFeed) fetchExtraBlockInfo(ctx context.Context) {
-	var fromHeight *int64
 	for {
 		time.Sleep(fetchBlockExtraInfoDelay)
 
@@ -17,7 +16,7 @@ func (ef *EventFeed) fetchExtraBlockInfo(ctx context.Context) {
 			ef.log.Info().Msg("graceful close of extra block info fetcher")
 			return
 		}
-		blockNumbers, err := ef.systemStore.GetBlocksMissingExtraInfo(ctx, fromHeight)
+		blockNumbers, err := ef.systemStore.GetBlocksMissingExtraInfo(ctx)
 		if err != nil {
 			ef.log.Error().Err(err).Msg("get blocks without extra info")
 			continue
@@ -49,8 +48,5 @@ func (ef *EventFeed) fetchExtraBlockInfo(ctx context.Context) {
 		for i := 0; i < cap(rateLim); i++ {
 			rateLim <- struct{}{}
 		}
-		if len(blockNumbers) > 0 {
-			fromHeight = &blockNumbers[len(blockNumbers)-1]
-		}
 	}
 }
diff --git a/pkg/sqlstore/impl/system/internal/db/evm_events.go b/pkg/sqlstore/impl/system/internal/db/evm_events.go
index e7c59fb..49b6574 100644
--- a/pkg/sqlstore/impl/system/internal/db/evm_events.go
+++ b/pkg/sqlstore/impl/system/internal/db/evm_events.go
@@ -102,18 +102,16 @@ func (q *Queries) AreEVMEventsPersisted(ctx context.Context, arg AreEVMTxnEvents
 const getBlocksMissingExtraInfo = `
 SELECT DISTINCT e.block_number
 FROM system_evm_events e 
-WHERE e.chain_id=?1 AND 
-      (?2 is null OR e.block_number>?2) AND
-      NOT EXISTS(select* from system_evm_blocks b WHERE e.chain_id=b.chain_id AND e.block_number=b.block_number)
+LEFT OUTER JOIN system_evm_blocks b ON e.chain_id=b.chain_id AND e.block_number=b.block_number
+WHERE e.chain_id=?1 AND b.block_number is null
 ORDER BY e.block_number`
 
 type GetBlocksMissingExtraInfoParams struct {
-	ChainID    int64
-	FromHeight *int64
+	ChainID int64
 }
 
 func (q *Queries) GetBlocksMissingExtraInfo(ctx context.Context, arg GetBlocksMissingExtraInfoParams) ([]int64, error) {
-	rows, err := q.query(ctx, q.getBlocksMissingExtraInfoStmt, getBlocksMissingExtraInfo, arg.ChainID, arg.FromHeight)
+	rows, err := q.query(ctx, q.getBlocksMissingExtraInfoStmt, getBlocksMissingExtraInfo, arg.ChainID)
 	if err != nil {
 		return nil, fmt.Errorf("executing getBlocksMissingExtraInfo query: %s", err)
 	}
diff --git a/pkg/sqlstore/impl/system/migrations/migrations.go b/pkg/sqlstore/impl/system/migrations/migrations.go
index 82d0206..aeaf09d 100644
--- a/pkg/sqlstore/impl/system/migrations/migrations.go
+++ b/pkg/sqlstore/impl/system/migrations/migrations.go
@@ -1,6 +1,6 @@
 // Code generated by go-bindata. (@generated) DO NOT EDIT.
 
- //Package migrations generated by go-bindata.// sources:
+//Package migrations generated by go-bindata.// sources:
 // migrations/001_init.down.sql
 // migrations/001_init.up.sql
 // migrations/002_receipterroridx.down.sql
@@ -178,7 +178,7 @@ func _003_evm_eventsDownSql() (*asset, error) {
 		return nil, err
 	}
 
-	info := bindataFileInfo{name: "003_evm_events.down.sql", size: 59, mode: os.FileMode(436), modTime: time.Unix(1661377601, 0)}
+	info := bindataFileInfo{name: "003_evm_events.down.sql", size: 59, mode: os.FileMode(436), modTime: time.Unix(1661268420, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }
@@ -198,7 +198,7 @@ func _003_evm_eventsUpSql() (*asset, error) {
 		return nil, err
 	}
 
-	info := bindataFileInfo{name: "003_evm_events.up.sql", size: 701, mode: os.FileMode(436), modTime: time.Unix(1661377601, 0)}
+	info := bindataFileInfo{name: "003_evm_events.up.sql", size: 701, mode: os.FileMode(436), modTime: time.Unix(1661268422, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }
diff --git a/pkg/sqlstore/impl/system/store.go b/pkg/sqlstore/impl/system/store.go
index cae0551..86a2a60 100644
--- a/pkg/sqlstore/impl/system/store.go
+++ b/pkg/sqlstore/impl/system/store.go
@@ -376,12 +376,9 @@ func (s *SystemStore) SaveEVMEvents(ctx context.Context, events []tableland.EVME
 }
 
 // GetBlocksMissingExtraInfo returns a list of block numbers that don't contain enhanced information.
-// It receives an optional fromHeight to only look for blocks after a block number. If null it will look
-// for blocks at any height.
-func (s *SystemStore) GetBlocksMissingExtraInfo(ctx context.Context, lastKnownHeight *int64) ([]int64, error) {
+func (s *SystemStore) GetBlocksMissingExtraInfo(ctx context.Context) ([]int64, error) {
 	params := db.GetBlocksMissingExtraInfoParams{
-		ChainID:    int64(s.chainID),
-		FromHeight: lastKnownHeight,
+		ChainID: int64(s.chainID),
 	}
 	blockNumbers, err := s.dbWithTx.queries().GetBlocksMissingExtraInfo(ctx, params)
 	if err == sql.ErrNoRows {
diff --git a/pkg/sqlstore/impl/system_store_instrumented.go b/pkg/sqlstore/impl/system_store_instrumented.go
index ec07f91..3412ad0 100644
--- a/pkg/sqlstore/impl/system_store_instrumented.go
+++ b/pkg/sqlstore/impl/system_store_instrumented.go
@@ -333,13 +333,10 @@ func (s *InstrumentedSystemStore) GetEVMEvents(ctx context.Context, txnHash comm
 }
 
 // GetBlocksMissingExtraInfo implements sqlstore.SystemStore.
-func (s *InstrumentedSystemStore) GetBlocksMissingExtraInfo(
-	ctx context.Context,
-	fromHeight *int64,
-) ([]int64, error) {
+func (s *InstrumentedSystemStore) GetBlocksMissingExtraInfo(ctx context.Context) ([]int64, error) {
 	log.Debug().Msg("call GetBlocksMissingExtraInfo")
 	start := time.Now()
-	blockNumbers, err := s.store.GetBlocksMissingExtraInfo(ctx, fromHeight)
+	blockNumbers, err := s.store.GetBlocksMissingExtraInfo(ctx)
 	latency := time.Since(start).Milliseconds()
 
 	attributes := []attribute.KeyValue{
diff --git a/pkg/sqlstore/store_system.go b/pkg/sqlstore/store_system.go
index ebe3a71..04d82e1 100644
--- a/pkg/sqlstore/store_system.go
+++ b/pkg/sqlstore/store_system.go
@@ -30,7 +30,7 @@ type SystemStore interface {
 	AreEVMEventsPersisted(context.Context, common.Hash) (bool, error)
 	SaveEVMEvents(context.Context, []tableland.EVMEvent) error
 	GetEVMEvents(context.Context, common.Hash) ([]tableland.EVMEvent, error)
-	GetBlocksMissingExtraInfo(context.Context, *int64) ([]int64, error)
+	GetBlocksMissingExtraInfo(context.Context) ([]int64, error)
 	InsertBlockExtraInfo(context.Context, int64, uint64) error
 	GetBlockExtraInfo(context.Context, int64) (tableland.EVMBlockInfo, error)
 
diff --git a/tableland-openapi-spec.yaml b/tableland-openapi-spec.yaml
index bd15fc1..a9675b4 100644
--- a/tableland-openapi-spec.yaml
+++ b/tableland-openapi-spec.yaml
@@ -17,6 +17,8 @@ paths:
 
         * The `runReadQuery` method allows you execute a read-query in the validator and get the result.
 
+        * The `validateWriteQuery` method allows you validate a mutating query as a pre contract call check.
+
         * The `relayWriteQuery` method allows you to rely on the validator to send a runSQL SC call on your behalf for write-queries.
 
         * The `getReceipt` method allows you to get the receipt of a chain transaction to know if it was executed, and the execution details.
@@ -604,4 +606,4 @@ components:
               controller:
                 type: "string"
               token_id:
-                type: "string"
\ No newline at end of file
+                type: "string"


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index a8916c0..89412d2 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -14,7 +14,7 @@ jobs:
   test:
     strategy:
       matrix:
-        go-version: [1.18.x, v1.19.x]
+        go-version: [1.17.x, v1.18.x]
         os: [ubuntu-latest]
     runs-on: ${{ matrix.os }}
     steps: