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

Upgrade CosmWasm to beta5 #215

Merged
merged 5 commits into from
Apr 27, 2021
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
16 changes: 8 additions & 8 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ default = []
backtraces = []

[dependencies]
cosmwasm-std = { git = "https://github.com/CosmWasm/cosmwasm", rev = "v0.14.0-beta4", features = ["iterator", "staking", "stargate"] }
cosmwasm-vm = { git = "https://github.com/CosmWasm/cosmwasm", rev = "v0.14.0-beta4", features = ["iterator", "staking", "stargate"] }
cosmwasm-std = { git = "https://github.com/CosmWasm/cosmwasm", rev = "v0.14.0-beta5", features = ["iterator", "staking", "stargate"] }
cosmwasm-vm = { git = "https://github.com/CosmWasm/cosmwasm", rev = "v0.14.0-beta5", features = ["iterator", "staking", "stargate"] }
errno = "0.2"
serde_json = "1.0"
thiserror = "1.0"
Expand Down
22 changes: 11 additions & 11 deletions api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestGetMetrics(t *testing.T) {
assert.Equal(t, &types.Metrics{
HitsFsCache: 1,
ElementsMemoryCache: 1,
SizeMemoryCache: 3417886,
SizeMemoryCache: 3428923,
}, metrics)

// Instantiate 2
Expand All @@ -223,7 +223,7 @@ func TestGetMetrics(t *testing.T) {
HitsMemoryCache: 1,
HitsFsCache: 1,
ElementsMemoryCache: 1,
SizeMemoryCache: 3417886,
SizeMemoryCache: 3428923,
}, metrics)

// Pin
Expand All @@ -238,8 +238,8 @@ func TestGetMetrics(t *testing.T) {
HitsFsCache: 1,
ElementsPinnedMemoryCache: 1,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 3417886,
SizeMemoryCache: 3417886,
SizePinnedMemoryCache: 3428923,
SizeMemoryCache: 3428923,
}, metrics)

// Instantiate 3
Expand All @@ -256,8 +256,8 @@ func TestGetMetrics(t *testing.T) {
HitsFsCache: 1,
ElementsPinnedMemoryCache: 1,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 3417886,
SizeMemoryCache: 3417886,
SizePinnedMemoryCache: 3428923,
SizeMemoryCache: 3428923,
}, metrics)

// Unpin
Expand All @@ -274,7 +274,7 @@ func TestGetMetrics(t *testing.T) {
ElementsPinnedMemoryCache: 0,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 0,
SizeMemoryCache: 3417886,
SizeMemoryCache: 3428923,
}, metrics)

// Instantiate 4
Expand All @@ -292,7 +292,7 @@ func TestGetMetrics(t *testing.T) {
ElementsPinnedMemoryCache: 0,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 0,
SizeMemoryCache: 3417886,
SizeMemoryCache: 3428923,
}, metrics)
}

Expand Down Expand Up @@ -363,7 +363,7 @@ func TestExecute(t *testing.T) {
res, cost, err = Execute(cache, checksum, env, info, []byte(`{"release":{}}`), &igasMeter2, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
diff = time.Now().Sub(start)
require.NoError(t, err)
assert.Equal(t, uint64(0xf363), cost)
assert.Equal(t, uint64(0xf364), cost)
t.Logf("Time (%d gas): %s\n", cost, diff)

// make sure it read the balance properly and we got 250 atoms
Expand Down Expand Up @@ -574,7 +574,7 @@ func TestMultipleInstances(t *testing.T) {
require.Equal(t, "Unauthorized", resp.Err)

// succeed to execute store1 with fred
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0xf2ef)
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0xf2f0)
require.Equal(t, "", resp.Err)
require.Equal(t, 1, len(resp.Ok.Messages))
attributes := resp.Ok.Attributes
Expand All @@ -583,7 +583,7 @@ func TestMultipleInstances(t *testing.T) {
require.Equal(t, "bob", attributes[1].Value)

// succeed to execute store2 with mary
resp = exec(t, cache, checksum, "mary", store2, api, querier, 0xf329)
resp = exec(t, cache, checksum, "mary", store2, api, querier, 0xf32a)
require.Equal(t, "", resp.Err)
require.Equal(t, 1, len(resp.Ok.Messages))
attributes = resp.Ok.Attributes
Expand Down
9 changes: 5 additions & 4 deletions api/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ func MockIBCPacket(myChannel string, data []byte) types.IBCPacket {
ChannelID: myChannel,
},
Sequence: 15,
TimeoutBlock: &types.IBCTimeoutBlock{
Revision: 1,
Height: 123456,
Timeout: types.IBCTimeout{
webmaster128 marked this conversation as resolved.
Show resolved Hide resolved
Block: &types.IBCTimeoutBlock{
Revision: 1,
Height: 123456,
},
},
TimeoutTimestamp: nil,
}
}

Expand Down
Binary file modified api/testdata/hackatom.wasm
Binary file not shown.
Binary file modified api/testdata/ibc_reflect.wasm
Binary file not shown.
Binary file modified api/testdata/queue.wasm
Binary file not shown.
Binary file modified api/testdata/reflect.wasm
Binary file not shown.
5 changes: 5 additions & 0 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func (vm *VM) AnalyzeCode(checksum Checksum) (*types.AnalysisReport, error) {
return api.AnalyzeCode(vm.cache, checksum)
}

// GetMetrics some internal metrics for monitoring purposes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this for @alpe

func (vm *VM) GetMetrics() (*types.Metrics, error) {
return api.GetMetrics(vm.cache)
}

// Instantiate will create a new contract based on the given Checksum.
// We can set the initMsg (contract "genesis") here, and it then receives
// an account and address and can be invoked (Execute) many times.
Expand Down
128 changes: 128 additions & 0 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,131 @@ func TestHappyPath(t *testing.T) {
expectedData := []byte{0xF0, 0x0B, 0xAA}
assert.Equal(t, expectedData, hres.Data)
}

func TestGetMetrics(t *testing.T) {
vm := withVM(t)

// GetMetrics 1
metrics, err := vm.GetMetrics()
require.NoError(t, err)
assert.Equal(t, &types.Metrics{}, metrics)

// Create contract
checksum := createTestContract(t, vm, HACKATOM_TEST_CONTRACT)

// GetMetrics 2
metrics, err = vm.GetMetrics()
require.NoError(t, err)
assert.Equal(t, &types.Metrics{}, metrics)

// Instantiate 1
gasMeter1 := api.NewMockGasMeter(TESTING_GAS_LIMIT)
// instantiate it with this store
store := api.NewLookup(gasMeter1)
goapi := api.NewMockAPI()
balance := types.Coins{types.NewCoin(250, "ATOM")}
querier := api.DefaultQuerier(api.MOCK_CONTRACT_ADDR, balance)

env := api.MockEnv()
info := api.MockInfo("creator", nil)
msg1 := []byte(`{"verifier": "fred", "beneficiary": "bob"}`)
ires, _, err := vm.Instantiate(checksum, env, info, msg1, store, *goapi, querier, gasMeter1, TESTING_GAS_LIMIT)
require.NoError(t, err)
require.Equal(t, 0, len(ires.Messages))

// GetMetrics 3
metrics, err = vm.GetMetrics()
require.NoError(t, err)
assert.Equal(t, &types.Metrics{
HitsFsCache: 1,
ElementsMemoryCache: 1,
SizeMemoryCache: 3428923,
}, metrics)

// Instantiate 2
msg2 := []byte(`{"verifier": "fred", "beneficiary": "susi"}`)
ires, _, err = vm.Instantiate(checksum, env, info, msg2, store, *goapi, querier, gasMeter1, TESTING_GAS_LIMIT)
require.NoError(t, err)
require.Equal(t, 0, len(ires.Messages))

// GetMetrics 4
metrics, err = vm.GetMetrics()
require.NoError(t, err)
assert.Equal(t, &types.Metrics{
HitsMemoryCache: 1,
HitsFsCache: 1,
ElementsMemoryCache: 1,
SizeMemoryCache: 3428923,
}, metrics)

// Pin
err = vm.Pin(checksum)
require.NoError(t, err)

// GetMetrics 5
metrics, err = vm.GetMetrics()
require.NoError(t, err)
assert.Equal(t, &types.Metrics{
HitsMemoryCache: 2,
HitsFsCache: 1,
ElementsPinnedMemoryCache: 1,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 3428923,
SizeMemoryCache: 3428923,
}, metrics)

// Instantiate 3
msg3 := []byte(`{"verifier": "fred", "beneficiary": "bert"}`)
ires, _, err = vm.Instantiate(checksum, env, info, msg3, store, *goapi, querier, gasMeter1, TESTING_GAS_LIMIT)
require.NoError(t, err)
require.Equal(t, 0, len(ires.Messages))

// GetMetrics 6
metrics, err = vm.GetMetrics()
require.NoError(t, err)
assert.Equal(t, &types.Metrics{
HitsPinnedMemoryCache: 1,
HitsMemoryCache: 2,
HitsFsCache: 1,
ElementsPinnedMemoryCache: 1,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 3428923,
SizeMemoryCache: 3428923,
}, metrics)

// Unpin
err = vm.Unpin(checksum)
require.NoError(t, err)

// GetMetrics 7
metrics, err = vm.GetMetrics()
require.NoError(t, err)
assert.Equal(t, &types.Metrics{
HitsPinnedMemoryCache: 1,
HitsMemoryCache: 2,
HitsFsCache: 1,
ElementsPinnedMemoryCache: 0,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 0,
SizeMemoryCache: 3428923,
}, metrics)

// Instantiate 4
msg4 := []byte(`{"verifier": "fred", "beneficiary": "jeff"}`)
ires, _, err = vm.Instantiate(checksum, env, info, msg4, store, *goapi, querier, gasMeter1, TESTING_GAS_LIMIT)
require.NoError(t, err)
require.Equal(t, 0, len(ires.Messages))

// GetMetrics 8
metrics, err = vm.GetMetrics()
require.NoError(t, err)
assert.Equal(t, &types.Metrics{
HitsPinnedMemoryCache: 1,
HitsMemoryCache: 3,
HitsFsCache: 1,
ElementsPinnedMemoryCache: 0,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 0,
SizeMemoryCache: 3428923,
}, metrics)
}
2 changes: 1 addition & 1 deletion src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ mod tests {
misses: 0,
elements_pinned_memory_cache: 1,
elements_memory_cache: 0,
size_pinned_memory_cache: 3417886,
size_pinned_memory_cache: 3428923,
size_memory_cache: 0,
}
);
Expand Down
26 changes: 19 additions & 7 deletions types/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,30 @@ func (t IBCTimeoutBlock) IsZero() bool {
return t.Revision == 0 && t.Height == 0
}

type IBCTimeoutBoth struct {
Block IBCTimeoutBlock `json:"block"`
Timestamp uint64 `json:"timestamp_nanos"` // TODO: simplify to just "timestamp" in Rust
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler field name coming with CosmWasm/cosmwasm#902. Timestamps are always nanoseconds in IBC and we have it documented right in the enum case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timestamps are always nanoseconds in IBC and we have it documented right in the enum case.

Let's discuss this in CosmWasm/cosmwasm#902
I wrote much of this code and twice returned seconds there, as there were no helpers, I just took env.block.time + 2000 or such.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy for simpler name in Go

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, we can stick to it if helps. No rush here. I just felt it was overly long when writing the glue code.

}

// IBCTimeout is the timeout for an IBC packet. At least one of block and timestamp is required.
//
// This is an enum, i.e. only one of the three fields must be set.
type IBCTimeout struct {
// Nanoseconds since UNIX epoch
// See https://golang.org/pkg/time/#Time.UnixNano
Timestamp *uint64 `json:"timestamp_nanos,omitempty"` // TODO: simplify to just "timestamp" in Rust
// Block after which the packet times out.
Block *IBCTimeoutBlock `json:"block,omitempty"`
// Block and time after which the packet times out.
Both *IBCTimeoutBoth `json:"both,omitempty"`
}

type IBCPacket struct {
Data []byte `json:"data"`
Src IBCEndpoint `json:"src"`
Dest IBCEndpoint `json:"dest"`
Sequence uint64 `json:"sequence"`
// block after which the packet times out.
// at least one of timeout_block, timeout_timestamp is required
TimeoutBlock *IBCTimeoutBlock `json:"timeout_block,omitempty"`
// Nanoseconds since UNIX epoch
// See https://golang.org/pkg/time/#Time.UnixNano
// at least one of timeout_block, timeout_timestamp is required
TimeoutTimestamp *uint64 `json:"timeout_timestamp,omitempty"`
Timeout IBCTimeout `json:"timeout"`
webmaster128 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line introduces a bug because in cosmwasm-std the IbcPacket still uses the old format with fields timeout_block and timeout_timestamp.

}

type IBCAcknowledgement struct {
Expand Down
Loading