Skip to content

Commit 5af5fd0

Browse files
authored
Merge pull request #579 from tablelandnetwork/staging
Prepare for v1.5.0 release
2 parents a4c0b53 + 6c9719e commit 5af5fd0

12 files changed

Lines changed: 117 additions & 27 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/sethvargo/go-limiter v0.7.2
2121
github.com/spf13/cobra v1.7.0
2222
github.com/stretchr/testify v1.8.2
23-
github.com/tablelandnetwork/sqlparser v0.0.0-20230516213554-c251484b2141
23+
github.com/tablelandnetwork/sqlparser v0.0.0-20230518143735-838d223866f6
2424
github.com/textileio/cli v1.0.2
2525
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.37.0
2626
go.opentelemetry.io/otel v1.14.0

go.sum

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,22 +1295,10 @@ github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG
12951295
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
12961296
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI=
12971297
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
1298-
github.com/tablelandnetwork/sqlparser v0.0.0-20230328132500-785ebca8e351 h1:aHuHicCezduOZVQXPXFM5MJ+h73caB2OUvVjGffzIsc=
1299-
github.com/tablelandnetwork/sqlparser v0.0.0-20230328132500-785ebca8e351/go.mod h1:S+M/v3Q8X+236kQxMQziFcLId2Cscb1LzW06IUVhljE=
1300-
github.com/tablelandnetwork/sqlparser v0.0.0-20230420192826-7c549ca44bf8 h1:mC58HOJfkfPsqetYd4hpCp0ey5qb9/ZkIRZEx+d2b4U=
1301-
github.com/tablelandnetwork/sqlparser v0.0.0-20230420192826-7c549ca44bf8/go.mod h1:S+M/v3Q8X+236kQxMQziFcLId2Cscb1LzW06IUVhljE=
1302-
github.com/tablelandnetwork/sqlparser v0.0.0-20230502223534-5872144545c4 h1:YjROwj4D7PXJbKCNdpTZJM8TpfKhdFgdzzjh3RTY1wo=
1303-
github.com/tablelandnetwork/sqlparser v0.0.0-20230502223534-5872144545c4/go.mod h1:S+M/v3Q8X+236kQxMQziFcLId2Cscb1LzW06IUVhljE=
1304-
github.com/tablelandnetwork/sqlparser v0.0.0-20230502232446-6e10f18895a3 h1:QyOUHf3JEz3p3JrijVHRggaPKahuJLuxyslxlMmuXAc=
1305-
github.com/tablelandnetwork/sqlparser v0.0.0-20230502232446-6e10f18895a3/go.mod h1:S+M/v3Q8X+236kQxMQziFcLId2Cscb1LzW06IUVhljE=
1306-
github.com/tablelandnetwork/sqlparser v0.0.0-20230512140127-295f5d9328d3 h1:GG6+Ydq75q1sN+aryvtblhX/iH1QixsOzy3neOE0MOA=
1307-
github.com/tablelandnetwork/sqlparser v0.0.0-20230512140127-295f5d9328d3/go.mod h1:S+M/v3Q8X+236kQxMQziFcLId2Cscb1LzW06IUVhljE=
1308-
github.com/tablelandnetwork/sqlparser v0.0.0-20230512150513-bea6933a3c28 h1:LItobZtMndgp0gVAot6OYruJavXndkmHcJN4LaNjCLc=
1309-
github.com/tablelandnetwork/sqlparser v0.0.0-20230512150513-bea6933a3c28/go.mod h1:S+M/v3Q8X+236kQxMQziFcLId2Cscb1LzW06IUVhljE=
1310-
github.com/tablelandnetwork/sqlparser v0.0.0-20230516205558-f93193cec061 h1:hy+sHKMwf58mMdJoJO496mb8aDwiA10TmWlhNXfhHNg=
1311-
github.com/tablelandnetwork/sqlparser v0.0.0-20230516205558-f93193cec061/go.mod h1:S+M/v3Q8X+236kQxMQziFcLId2Cscb1LzW06IUVhljE=
1312-
github.com/tablelandnetwork/sqlparser v0.0.0-20230516213554-c251484b2141 h1:mLJmSw0iqfEQR6h/FxuhvDdsNNaDsu33kQkvldWhgIw=
1313-
github.com/tablelandnetwork/sqlparser v0.0.0-20230516213554-c251484b2141/go.mod h1:S+M/v3Q8X+236kQxMQziFcLId2Cscb1LzW06IUVhljE=
1298+
github.com/tablelandnetwork/sqlparser v0.0.0-20230517143402-3ab9022be0df h1:SUG49BUSuO9S6U3RjAV8a0NIDRByHj3kSt8/QR75rtI=
1299+
github.com/tablelandnetwork/sqlparser v0.0.0-20230517143402-3ab9022be0df/go.mod h1:S+M/v3Q8X+236kQxMQziFcLId2Cscb1LzW06IUVhljE=
1300+
github.com/tablelandnetwork/sqlparser v0.0.0-20230518143735-838d223866f6 h1:f8TRklEZmT4fJd7wE+oktjf4wQndJ5BqkwXOpuHrYBU=
1301+
github.com/tablelandnetwork/sqlparser v0.0.0-20230518143735-838d223866f6/go.mod h1:S+M/v3Q8X+236kQxMQziFcLId2Cscb1LzW06IUVhljE=
13141302
github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I=
13151303
github.com/textileio/cli v1.0.2 h1:qSp/x4d/9SZ93TxhgZnE5okRKqzqHqrzAwKAPjuPw50=
13161304
github.com/textileio/cli v1.0.2/go.mod h1:vTlCvvVyOmXXLwddCcBg3PDavfUsCkRBZoyr6Nu1lkc=

internal/tableland/acl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ const (
8888
OpRevoke
8989
// OpCreate is represents a CREATE query.
9090
OpCreate
91+
// OpAlter is represents a ALTER query.
92+
OpAlter
9193
)
9294

9395
// String returns the string representation of the operation.
@@ -107,6 +109,8 @@ func (op Operation) String() string {
107109
return "OpRevoke"
108110
case OpCreate:
109111
return "OpCreate"
112+
case OpAlter:
113+
return "OpAlter"
110114
}
111115

112116
return ""

pkg/client/v1/client_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ func TestCreate(t *testing.T) {
2020
func TestWrite(t *testing.T) {
2121
calls := setup(t)
2222
tableName := requireCreate(t, calls)
23-
requireWrite(t, calls, tableName)
23+
requireReceipt(t, calls, requireInsert(t, calls, tableName), WaitFor(time.Second*10))
24+
requireReceipt(t, calls, requireAlter(t, calls, tableName), WaitFor(time.Second*10))
2425
}
2526

2627
func TestRead(t *testing.T) {
2728
t.Run("status 200", func(t *testing.T) {
2829
calls := setup(t)
2930
tableName := requireCreate(t, calls)
30-
hash := requireWrite(t, calls, tableName)
31+
hash := requireInsert(t, calls, tableName)
3132
requireReceipt(t, calls, hash, WaitFor(time.Second*10))
3233

3334
type result struct {
@@ -68,7 +69,7 @@ func TestGetReceipt(t *testing.T) {
6869
t.Run("status 200", func(t *testing.T) {
6970
calls := setup(t)
7071
tableName := requireCreate(t, calls)
71-
hash := requireWrite(t, calls, tableName)
72+
hash := requireInsert(t, calls, tableName)
7273
requireReceipt(t, calls, hash, WaitFor(time.Second*10))
7374
})
7475

@@ -152,8 +153,8 @@ func TestBlockNum(t *testing.T) {
152153

153154
// We create a table and do two inserts, that will increase our block number to 5.
154155
tableName := requireCreate(t, calls)
155-
requireReceipt(t, calls, requireWrite(t, calls, tableName), WaitFor(time.Second*10))
156-
requireReceipt(t, calls, requireWrite(t, calls, tableName), WaitFor(time.Second*10))
156+
requireReceipt(t, calls, requireInsert(t, calls, tableName), WaitFor(time.Second*10))
157+
requireReceipt(t, calls, requireInsert(t, calls, tableName), WaitFor(time.Second*10))
157158

158159
type result struct {
159160
BlockNumber int64 `json:"bn"`
@@ -171,12 +172,18 @@ func requireCreate(t *testing.T, calls clientCalls) string {
171172
return tableName
172173
}
173174

174-
func requireWrite(t *testing.T, calls clientCalls, table string) string {
175+
func requireInsert(t *testing.T, calls clientCalls, table string) string {
175176
hash := calls.write(fmt.Sprintf("insert into %s (bar) values('baz')", table))
176177
require.NotEmpty(t, hash)
177178
return hash
178179
}
179180

181+
func requireAlter(t *testing.T, calls clientCalls, table string) string {
182+
hash := calls.write(fmt.Sprintf("alter table %s rename bar to foo", table))
183+
require.NotEmpty(t, hash)
184+
return hash
185+
}
186+
180187
func requireReceipt(t *testing.T, calls clientCalls, hash string, opts ...ReceiptOption) *apiv1.TransactionReceipt {
181188
res, found := calls.receipt(hash, opts...)
182189
require.True(t, found)

pkg/eventprocessor/eventfeed/impl/eventfeed.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ func (ef *EventFeed) Start(
151151
// sideffects.
152152
toHeight := h.Number.Int64() - int64(ef.config.MinBlockChainDepth)
153153
if toHeight < fromHeight {
154+
ef.log.Warn().
155+
Int64("from_height", fromHeight).
156+
Int64("to_height", toHeight).
157+
Msgf("from_height bigger than to_height")
154158
break
155159
}
156160

pkg/eventprocessor/impl/eventprocessor_replayhistory_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestReplayProductionHistory(t *testing.T) {
4343
69: "b1136bd05118349be32372509f05c240180a93d3",
4444
137: "12b3d0aa62b4e61b10ea81c16bf050f8c27b1dca",
4545
420: "058bd19e7874fa3c9436b0cebbcf5846f7c347f3",
46-
80001: "5c9709607bd9da6e5e80df04e9ec2b30b488793d",
46+
80001: "92e3252755054c969a1e1118a8e3743b2b1768a7",
4747
421613: "18ae0ef43cdedc548706c61dccae533411f9d514",
4848
}
4949

pkg/eventprocessor/impl/executor/impl/executor_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func TestMultiEventTxnBlock(t *testing.T) {
109109
require.Nil(t, res.Error)
110110
require.Nil(t, res.ErrorEventIdx)
111111
require.Equal(t, eventCreateTable.TableId.Int64(), res.TableID.ToBigInt().Int64())
112+
require.Equal(t, []tables.TableID{tables.TableID(*big.NewInt(100))}, res.TableIDs)
112113
}
113114
// Txn 2
114115
{

pkg/eventprocessor/impl/executor/impl/txnscope.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (ts *txnScope) executeTxnEvents(
5656
var res eventExecutionResult
5757
var err error
5858

59-
tableIDs := make([]tables.TableID, 0)
59+
tableIDs, tableIDsMap := make([]tables.TableID, 0), make(map[string]struct{})
6060
for idx, event := range evmTxn.Events {
6161
switch event := event.(type) {
6262
case *ethereum.ContractRunSQL:
@@ -110,7 +110,10 @@ func (ts *txnScope) executeTxnEvents(
110110
}
111111

112112
if res.TableID != nil {
113-
tableIDs = append(tableIDs, *res.TableID)
113+
if _, ok := tableIDsMap[(*res.TableID).String()]; !ok {
114+
tableIDs = append(tableIDs, *res.TableID)
115+
tableIDsMap[(*res.TableID).String()] = struct{}{}
116+
}
114117
}
115118
}
116119

pkg/eventprocessor/impl/executor/impl/txnscope_runsql.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (ts *txnScope) execWriteQueries(
8181
return fmt.Errorf("executing grant stmt: %w", err)
8282
}
8383
case parsing.WriteStmt:
84-
if err := ts.executeWriteStmt(ctx, stmt, controller, policy, beforeRowCount); err != nil {
84+
if err := ts.executeWriteStmt(ctx, stmt, controller, policy, beforeRowCount, isOwner); err != nil {
8585
return fmt.Errorf("executing write stmt: %w", err)
8686
}
8787
default:
@@ -220,7 +220,17 @@ func (ts *txnScope) executeWriteStmt(
220220
addr common.Address,
221221
policy tableland.Policy,
222222
beforeRowCount int,
223+
isOwner bool,
223224
) error {
225+
if ws.Operation() == tableland.OpAlter {
226+
if !isOwner {
227+
return &errQueryExecution{
228+
Code: "ACL_NOT_OWNER",
229+
Msg: "non owner cannot execute alter stmt",
230+
}
231+
}
232+
}
233+
224234
controller, err := ts.getController(ctx, ws.GetTableID())
225235
if err != nil {
226236
return fmt.Errorf("checking controller is set: %w", err)

pkg/eventprocessor/impl/executor/impl/txnscope_runsql_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,48 @@ func TestRunSQL_WriteQueriesWithPolicies(t *testing.T) {
423423
})
424424
}
425425

426+
func TestRunSQL_AlterTable(t *testing.T) {
427+
t.Parallel()
428+
ctx := context.Background()
429+
430+
ex, _ := newExecutorWithStringTable(t, 0)
431+
432+
bs, err := ex.NewBlockScope(ctx, 0)
433+
require.NoError(t, err)
434+
435+
policy := ethereum.ITablelandControllerPolicy{
436+
AllowInsert: true,
437+
AllowUpdate: true,
438+
AllowDelete: true,
439+
WhereClause: "",
440+
WithCheck: "",
441+
UpdatableColumns: nil,
442+
}
443+
444+
// create an event where isOwner is false
445+
event := &ethereum.ContractRunSQL{
446+
Caller: common.HexToAddress("0xb451cee4A42A652Fe77d373BAe66D42fd6B8D8FF"),
447+
IsOwner: false,
448+
TableId: big.NewInt(100),
449+
Statement: "ALTER TABLE foo_1337_100 ADD COLUMN bar text",
450+
Policy: policy,
451+
}
452+
453+
var hashBytes [common.HashLength]byte
454+
binary.LittleEndian.PutUint64(hashBytes[:], rand.Uint64())
455+
txnHash := common.BytesToHash(hashBytes[:])
456+
457+
txnResult, err := bs.ExecuteTxnEvents(
458+
context.Background(),
459+
eventfeed.TxnEvents{
460+
TxnHash: txnHash,
461+
Events: []interface{}{event},
462+
},
463+
)
464+
require.NoError(t, err)
465+
require.Contains(t, *txnResult.Error, "non owner cannot execute alter stmt")
466+
}
467+
426468
func TestRunSQL_RowCountLimit(t *testing.T) {
427469
t.Parallel()
428470
ctx := context.Background()

0 commit comments

Comments
 (0)