Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove the copied interface from tm-db #82

Merged
merged 2 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/builds_and_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: set up
uses: actions/setup-go@v2
with:
go-version: ^1.17.4
go-version: 1.17
id: go
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -66,7 +66,7 @@ jobs:
- name: set up
uses: actions/setup-go@v2
with:
go-version: ^1.17.4
go-version: 1.17
id: go
- name: CHeckout
uses: actions/checkout@v2
Expand All @@ -88,7 +88,7 @@ jobs:
- name: set up
uses: actions/setup-go@v2
with:
go-version: ^1.17.4
go-version: 1.17
id: go
- name: Install shfmt
run: GO111MODULE=on go install mvdan.cc/sh/v3/cmd/[email protected]
Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
- name: set up
uses: actions/[email protected]
with:
go-version: 1.18
go-version: 1.17
id: go
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -159,7 +159,7 @@ jobs:
- name: set up
uses: actions/setup-go@v2
with:
go-version: ^1.17.4
go-version: 1.17
id: go
- name: Checkout
uses: actions/checkout@v2
Expand Down
44 changes: 34 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# Changelog

## [Unreleased]

## [[v1.0.0-0.10.0](https://github.com/line/wasmvm/compare/v0.16.3-0.9.0...v1.0.0-0.10.0)] - 2022-06-21
### Features

### Fixes
* fix: getmetrics test due to this is environment-dependent test ([#80](https://github.com/line/wasmvm/pull/80))

### Changes
* chore: remove the copied interface from tm-db ([#82](https://github.com/line/wasmvm/pull/82))
* refactor: Revert using line/tm-db ([#77](https://github.com/line/wasmvm/pull/77))
* ci: add release job ([#71](https://github.com/line/wasmvm/pull/71))
* chore: Revert linux_static ([#70](https://github.com/line/wasmvm/pull/70))

## [v1.0.0-0.10.0] - 2022-06-21

### Features

Expand All @@ -11,7 +23,7 @@

* improve CHANGELOG's template and devtools/update_changlog.sh ([#60](https://github.com/line/wasmvm/pull/60))

## [[0.16.3-0.9.0](https://github.com/line/wasmvm/compare/v0.14.0-0.8.0...0.16.3-0.9.0)] - 2022-03-03
## [v0.16.3-0.9.0] - 2022-03-03

### Changes

Expand All @@ -24,43 +36,43 @@

* fix Cargo.toml path in devtools/set_version.sh (part of [#59](https://github.com/line/wasmvm/issues/59))

## [[v0.14.0-0.8.0](https://github.com/line/wasmvm/compare/v0.14.0-0.7.0...v0.14.0-0.8.0)] - 2021-10-01
## [v0.14.0-0.8.0] - 2021-10-01

### Features

* change tag name for static build ([#49](https://github.com/line/wasmvm/issues/49))


## [[0.14.0-0.7.0](https://github.com/line/wasmvm/compare/v0.14.0-0.6.1...0.14.0-0.7.0)] - 2021-09-30
## [v0.14.0-0.7.0] - 2021-09-30

### Features

* add static linking of wasmvm ([#46](https://github.com/line/wasmvm/issues/46))


## [[0.14.0-0.6.1](https://github.com/line/wasmvm/compare/v0.14.0-0.6.0...0.14.0-0.6.1)] - 2021-07-15
## [v0.14.0-0.6.1] - 2021-07-15

### Fixes

* rebuild shared libs to resolve compile error ([#44](https://github.com/line/wasmvm/issues/44))


## [[v0.14.0-0.6.0](https://github.com/line/wasmvm/compare/v0.14.0-0.5.0...v0.14.0-0.6.0)] - 2021-07-12
## [v0.14.0-0.6.0] - 2021-07-12

### Changes
* update upstream Cosmwasm/wasmvm version to 0.14.0 (#36)
- Please refer [CHANGELOG_OF_WASMVM_v0.14.0](https://github.com/CosmWasm/wasmvm/blob/v0.14.0/CHANGELOG.md)
* change the depended CosmWasm/cosmwasm to line/cosmwasm


## [[v0.14.0-0.5.0](https://github.com/line/wasmvm/compare/v0.14.0-0.4.0...v0.14.0-0.5.0)] - 2021-05-12
## [v0.14.0-0.5.0] - 2021-05-12

### Changes

* Change the module uri from github.com/CosmWasm/wasmvm to github.com/link/wasmvm ([#23](https://github.com/line/wasmvm/issues/23))


## [[v0.14.0-0.4.0](https://github.com/line/wasmvm/compare/v0.14.0-0.3.0...v0.14.0-0.4.0)] - 2021-05-03
## [v0.14.0-0.4.0] - 2021-05-03

### Changes

Expand All @@ -76,7 +88,7 @@
The implementation of KVStore now must return a newly defined iterator rather than the `tm-db` defines.


## [[v0.14.0-0.3.0](https://github.com/line/wasmvm/compare/v0.12.0-0.1.0...v0.14.0-0.3.0)] - 2021-04-08
## [v0.14.0-0.3.0] - 2021-04-08

### Changes
* Update upstream Cosmwasm/wasmvm version to 0.14.0-beta1 (#8)
Expand All @@ -85,7 +97,7 @@
* Adjust semantic PR validation rule (#9)


## [0.12.0-0.1.0] - 2021-02-15
## [v0.12.0-0.1.0] - 2021-02-15

### Add
* Add semantic.yml for semantic pull request (#6)
Expand All @@ -102,3 +114,15 @@ Initial code is based on the wasmvm v0.12.0, cosmwasm v0.12.0
* (cosmwasm) [v0.12.0](https://github.com/CosmWasm/cosmwasm/releases/tag/v0.12.0).

Please refer [CHANGELOG_OF_WASMVM_v0.12.0](https://github.com/CosmWasm/wasmvm/releases?after=v0.13.0)

[Unreleased]:https://github.com/line/wasmvm/compare/v1.0.0-0.10.0...HEAD
[v1.0.0-0.10.0]:https://github.com/line/wasmvm/compare/v0.16.3-0.9.0...v1.0.0-0.10.0
[v0.16.3-0.9.0]:https://github.com/line/wasmvm/compare/v0.14.0-0.8.0...v0.16.3-0.9.0
[v0.14.0-0.8.0]:https://github.com/line/wasmvm/compare/v0.14.0-0.7.0...v0.14.0-0.8.0
[v0.14.0-0.7.0]:https://github.com/line/wasmvm/compare/v0.14.0-0.6.1...v0.14.0-0.7.0
[v0.14.0-0.6.1]:https://github.com/line/wasmvm/compare/v0.14.0-0.6.0...v0.14.0-0.6.1
[v0.14.0-0.6.0]:https://github.com/line/wasmvm/compare/v0.14.0-0.5.0...v0.14.0-0.6.0
[v0.14.0-0.5.0]:https://github.com/line/wasmvm/compare/v0.14.0-0.4.0...v0.14.0-0.5.0
[v0.14.0-0.4.0]:https://github.com/line/wasmvm/compare/v0.14.0-0.3.0...v0.14.0-0.4.0
[v0.14.0-0.3.0]:https://github.com/line/wasmvm/compare/v0.12.0-0.1.0...v0.14.0-0.3.0
[v0.12.0-0.1.0]:https://github.com/line/wasmvm/compare/v0.12.0...v0.12.0-0.1.0
35 changes: 6 additions & 29 deletions api/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import (
"runtime/debug"
"unsafe"

dbm "github.com/tendermint/tm-db"

"github.com/line/wasmvm/types"
)

Expand Down Expand Up @@ -112,37 +114,12 @@ type KVStore interface {
// Start must be less than end, or the Iterator is invalid.
// Iterator must be closed by caller.
// To iterate over entire domain, use store.Iterator(nil, nil)
Iterator(start, end []byte) Iterator
Iterator(start, end []byte) dbm.Iterator

// Iterator over a domain of keys in descending order. End is exclusive.
// Start must be less than end, or the Iterator is invalid.
// Iterator must be closed by caller.
ReverseIterator(start, end []byte) Iterator
}

// Iterator copies a subset of types from lbm-sdk
type Iterator interface {
// Valid returns whether the current iterator is valid. Once invalid, the Iterator remains
// invalid forever.
Valid() bool

// Next moves the iterator to the next key in the database, as defined by order of iteration.
// If Valid returns false, this method will panic.
Next()

// Key returns the key at the current position. Panics if the iterator is invalid.
// CONTRACT: key readonly []byte
Key() (key []byte)

// Value returns the value at the current position. Panics if the iterator is invalid.
// CONTRACT: value readonly []byte
Value() (value []byte)

// Error returns the last error encountered by the iterator, if any.
Error() error

// Close closes the iterator, releasing any allocated resources.
Close() error
ReverseIterator(start, end []byte) dbm.Iterator
}

var db_vtable = C.Db_vtable{
Expand Down Expand Up @@ -191,7 +168,7 @@ const frameLenLimit = 32768

// contract: original pointer/struct referenced must live longer than C.Db struct
// since this is only used internally, we can verify the code that this is the case
func buildIterator(callID uint64, it Iterator) (C.iterator_t, error) {
func buildIterator(callID uint64, it dbm.Iterator) (C.iterator_t, error) {
idx, err := storeIterator(callID, it, frameLenLimit)
if err != nil {
return C.iterator_t{}, err
Expand Down Expand Up @@ -297,7 +274,7 @@ func cScan(ptr *C.db_t, gasMeter *C.gas_meter_t, usedGas *C.uint64_t, start C.U8
s := copyU8Slice(start)
e := copyU8Slice(end)

var iter Iterator
var iter dbm.Iterator
gasBefore := gm.GasConsumed()
switch order {
case 1: // Ascending
Expand Down
10 changes: 6 additions & 4 deletions api/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package api
import (
"fmt"
"sync"

dbm "github.com/tendermint/tm-db"
)

// frame stores all Iterators for one contract
type frame []Iterator
// frame stores all Iterators for one contract call
type frame []dbm.Iterator

// iteratorFrames contains one frame for each contract call, indexed by contract call ID.
var iteratorFrames = make(map[uint64]frame)
Expand Down Expand Up @@ -50,7 +52,7 @@ func endCall(callID uint64) {
// storeIterator will add this to the end of the frame for the given ID and return a reference to it.
// We start counting with 1, so the 0 value is flagged as an error. This means we must
// remember to do idx-1 when retrieving
func storeIterator(callID uint64, it Iterator, frameLenLimit int) (uint64, error) {
func storeIterator(callID uint64, it dbm.Iterator, frameLenLimit int) (uint64, error) {
iteratorFramesMutex.Lock()
defer iteratorFramesMutex.Unlock()

Expand All @@ -69,7 +71,7 @@ func storeIterator(callID uint64, it Iterator, frameLenLimit int) (uint64, error
// retrieveIterator will recover an iterator based on index. This ensures it will not be garbage collected.
// We start counting with 1, in storeIterator so the 0 value is flagged as an error. This means we must
// remember to do idx-1 when retrieving
func retrieveIterator(callID uint64, index uint64) Iterator {
func retrieveIterator(callID uint64, index uint64) dbm.Iterator {
iteratorFramesMutex.Lock()
defer iteratorFramesMutex.Unlock()
myFrame := iteratorFrames[callID]
Expand Down
6 changes: 3 additions & 3 deletions api/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestStoreIterator(t *testing.T) {
callID2 := startCall()

store := dbm.NewMemDB()
var iter Iterator
var iter dbm.Iterator
var index uint64
var err error

Expand Down Expand Up @@ -102,7 +102,7 @@ func TestStoreIteratorHitsLimit(t *testing.T) {
callID := startCall()

store := dbm.NewMemDB()
var iter Iterator
var iter dbm.Iterator
var err error
const limit = 2

Expand All @@ -127,7 +127,7 @@ func TestRetrieveIterator(t *testing.T) {
callID2 := startCall()

store := dbm.NewMemDB()
var iter Iterator
var iter dbm.Iterator
var err error

iter, _ = store.Iterator(nil, nil)
Expand Down
1 change: 0 additions & 1 deletion api/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestCreateAndDestroyUnmanagedVector(t *testing.T) {

// Like the test above but without `newUnmanagedVector` calls.
// Since only Rust can actually create them, we only test edge cases here.

//go:nocheckptr
func TestCopyDestroyUnmanagedVector(t *testing.T) {
{
Expand Down
4 changes: 2 additions & 2 deletions api/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (l Lookup) Delete(key []byte) {
}

// Iterator wraps the underlying DB's Iterator method panicing on error.
func (l Lookup) Iterator(start, end []byte) Iterator {
func (l Lookup) Iterator(start, end []byte) dbm.Iterator {
l.meter.ConsumeGas(RangePrice, "range")
iter, err := l.db.Iterator(start, end)
if err != nil {
Expand All @@ -313,7 +313,7 @@ func (l Lookup) Iterator(start, end []byte) Iterator {
}

// ReverseIterator wraps the underlying DB's ReverseIterator method panicing on error.
func (l Lookup) ReverseIterator(start, end []byte) Iterator {
func (l Lookup) ReverseIterator(start, end []byte) dbm.Iterator {
l.meter.ConsumeGas(RangePrice, "range")
iter, err := l.db.ReverseIterator(start, end)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ type WasmCode []byte
// KVStore is a reference to some sub-kvstore that is valid for one instance of a code
type KVStore = api.KVStore

type Iterator = api.Iterator

// GoAPI is a reference to some "precompiles", go callbacks
type GoAPI = api.GoAPI

Expand Down