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

Ride vm and compiler. #438

Draft
wants to merge 61 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f7bff52
Stateful compiler.
Frozen Oct 23, 2020
393bea6
Context for func execution.
Frozen Oct 23, 2020
c32e887
Function definition passed tess.
Frozen Oct 23, 2020
1975cd8
Uncomment completed tests.
Frozen Oct 23, 2020
fb77419
Pass args as reference.
Frozen Oct 30, 2020
d20052b
Pass args as mem storage.
Frozen Nov 3, 2020
197130e
Global variables.
Frozen Nov 5, 2020
980f91f
Get attribute vm.
Frozen Nov 6, 2020
b11b59e
Odd byte codes.
Frozen Nov 6, 2020
3f70cd3
Stagenet tests.
Frozen Nov 10, 2020
03e9286
Cells for variables.
Frozen Nov 12, 2020
3165334
Fix bug with if stmt.
Frozen Nov 23, 2020
f4c6943
Cache function result as variable.
Frozen Dec 1, 2020
ae6f02a
Function arguments.
Frozen Dec 2, 2020
86f9281
Cache variable result.
Frozen Dec 3, 2020
f6a69e9
Clear cache.
Frozen Dec 3, 2020
0fd9f97
Fix clear cache.
Frozen Dec 7, 2020
219cf08
Reverse assigments.
Frozen Dec 7, 2020
2f51036
Deferred code.
Frozen Dec 9, 2020
9e7f14c
Property state.
Frozen Dec 10, 2020
0296798
Call function.
Frozen Dec 10, 2020
9c0d640
Property invocation changed.
Frozen Dec 13, 2020
8f7a32a
Property bytecode checked in tests.
Frozen Dec 13, 2020
f01939c
Reversed tree.
Frozen Dec 15, 2020
4bdddaa
Fix transitions.
Frozen Dec 22, 2020
d983007
Merge branch 'master' into ride_vm_fsm
Frozen Dec 22, 2020
415c5c1
Fix transitions.
Frozen Dec 23, 2020
b43481d
Fix functions.
Frozen Dec 23, 2020
f755658
Fix functions.
Frozen Dec 24, 2020
33f2f24
Save entrypoints into meta.
Frozen Dec 24, 2020
36be49d
Testnet random script.
Frozen Jan 24, 2021
1b6f2ff
Passed testnet.
Frozen Feb 1, 2021
8a2b1cd
Enabled cache.
Frozen Feb 4, 2021
598f0aa
Merge branch 'master' into ride_vm_fsm
Frozen Feb 4, 2021
78afd85
Merged master.
Frozen Feb 4, 2021
ff8c959
Switchable bloom filter.
Frozen Feb 5, 2021
60410b4
Fix tests.
Frozen Feb 5, 2021
cc3d021
Merge branch 'optional_bloom_filter' into ride_vm_fsm
Frozen Feb 5, 2021
b70c14b
Code clean up and returned back debug info.
Frozen Feb 9, 2021
3e16ec5
Fix panic.
Frozen Feb 9, 2021
73a8ce5
Remove caching duplicates.
Frozen Feb 12, 2021
349c863
Expanded tree.
Frozen Mar 10, 2021
9c1b500
Rewrite tree by using immutable context with variables.
Frozen Mar 16, 2021
74b8cf3
Fix problems with tree expand.
Frozen Mar 17, 2021
be99ac9
Fix naming.
Frozen Mar 18, 2021
5d035b3
Remove unused code.
Frozen Mar 18, 2021
8b64449
Fix vetcheck errors.
Frozen Mar 18, 2021
366b203
Fix vetcheck errors.
Frozen Mar 18, 2021
ba560d8
Set up go 1.16
Frozen Mar 18, 2021
6c06ca0
Merge branch 'master' into ride_vm_fsm
Frozen Mar 18, 2021
b50a0c7
Rewrite path.
Frozen Mar 19, 2021
15d0cb0
Removed fmtcheck.
Frozen Mar 19, 2021
2e6c584
Clean code in tree evaluator.
Frozen Mar 19, 2021
2c1c208
Fix small errors.
Frozen Mar 19, 2021
f86c981
Clean up compiler.
Frozen Mar 22, 2021
1d6f34a
Fix bug with var override in condition stste.
Frozen Mar 25, 2021
80bfd76
Merge remote-tracking branch 'origin/expand_tree_rewrite_path' into r…
Frozen Mar 25, 2021
a644a73
Fix bug with nil values and duplicate vars in conditional state.
Frozen Apr 2, 2021
cee2edc
Merge remote-tracking branch 'origin/master' into ride_vm_fsm
Frozen Apr 2, 2021
0c792d4
Updated mocks.
Frozen Apr 2, 2021
48d19f8
Added skip file compiler_heplers
esuwu Apr 7, 2021
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
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:

steps:
- uses: actions/checkout@master
- name: Set up Go 1.15
- name: Set up Go 1.16
uses: actions/setup-go@v1
with:
go-version: 1.15
go-version: 1.16
id: go

- name: Set up GolangCI-Lint
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export GO111MODULE=on

.PHONY: vendor vetcheck fmtcheck clean build gotest

all: vendor vetcheck fmtcheck build gotest mod-clean
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to skip a package instead of removing fmtcheck at all in case if it's hard to fix style and stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried all possible ways - skip, ignore, fix, upgrade. Nothing helps.

all: vendor vetcheck build gotest mod-clean

ver:
@echo Building version: $(VERSION)
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/wavesplatform/gowaves

go 1.15
go 1.16

require (
github.com/OneOfOne/xxhash v1.2.5 // indirect
Expand All @@ -11,6 +11,7 @@ require (
github.com/coocood/freecache v1.1.0
github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc // indirect
github.com/ericlagergren/decimal v0.0.0-20190912144844-2c3e3e1ef942
github.com/frozen/immutable_map v0.1.0
github.com/fxamacker/cbor/v2 v2.2.0
github.com/go-chi/chi v4.0.3+incompatible
github.com/golang/mock v1.4.3
Expand All @@ -35,7 +36,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/starius/emsort v0.0.0-20191221202443-6f2fbdee4781
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d
github.com/valyala/bytebufferpool v1.0.0
github.com/xenolf/lego v2.7.2+incompatible
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ github.com/ericlagergren/decimal v0.0.0-20190912144844-2c3e3e1ef942/go.mod h1:ZW
github.com/ethereum/go-ethereum v1.9.15/go.mod h1:slT8bPPRhXsyNTwHQxrOnjuTZ1sDXRajW11EkJ84QJ0=
github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/frozen/immutable_map v0.1.0 h1:JvDI2+lE4+5UJ8QJwxesBl4RuAEOmCJCZDXiAQXXIcY=
github.com/frozen/immutable_map v0.1.0/go.mod h1:wIufmkixG0KtX1l5NNbSwlp/GIHJ0tUnMO/uXKUs9LU=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fxamacker/cbor/v2 v2.2.0 h1:6eXqdDDe588rSYAi1HfZKbx6YYQO4mxQ9eC6xYpU/JQ=
Expand Down Expand Up @@ -252,8 +254,9 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
Expand Down
11 changes: 11 additions & 0 deletions pkg/proto/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ func TestGetBlockMessage_MarshalBinary(t *testing.T) {
}

rs, err := b.MarshalBinary()
t.Log(rs)
require.NoError(t, err)

b2 := GetBlockMessage{}
Expand Down Expand Up @@ -616,3 +617,13 @@ func TestTCPAddr_ToUint64(t *testing.T) {

require.True(t, a.Equal(b))
}

func TestGetPeersMessage_MarshalBinary(t *testing.T) {
m := GetPeersMessage{}
bts, err := m.MarshalBinary()
require.NoError(t, err)
t.Log(bts)

err = m.UnmarshalBinary(bts)
require.NoError(t, err)
}
72 changes: 72 additions & 0 deletions pkg/proto/scripting.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package proto

import (
"bytes"
"encoding/binary"
"unicode/utf16"

Expand All @@ -10,9 +11,25 @@ import (
g "github.com/wavesplatform/gowaves/pkg/grpc/generated/waves"
)

type ScriptActions []ScriptAction

func (a ScriptActions) Eq(b ScriptActions) bool {
if len(a) != len(b) {
return false
}

for i := range a {
if !a[i].Eq(b[i]) {
return false
}
}
return true
}

// ScriptAction common interface of script invocation actions.
type ScriptAction interface {
scriptAction()
Eq(ScriptAction) bool
}

// DataEntryScriptAction is an action to manipulate account data state.
Expand All @@ -22,6 +39,14 @@ type DataEntryScriptAction struct {

func (a DataEntryScriptAction) scriptAction() {}

func (a DataEntryScriptAction) Eq(another ScriptAction) bool {
b, ok := another.(*DataEntryScriptAction)
if !ok {
return false
}
return a.Entry.Eq(b.Entry)
}

func (a *DataEntryScriptAction) ToProtobuf() *g.DataTransactionData_DataEntry {
return a.Entry.ToProtobuf()
}
Expand All @@ -35,6 +60,14 @@ type TransferScriptAction struct {

func (a TransferScriptAction) scriptAction() {}

func (a TransferScriptAction) Eq(other ScriptAction) bool {
b, ok := other.(*TransferScriptAction)
if !ok {
return false
}
return a.Amount == b.Amount && a.Asset == b.Asset && a.Recipient.Eq(b.Recipient)
}

func (a *TransferScriptAction) ToProtobuf() (*g.InvokeScriptResult_Payment, error) {
amount := &g.Amount{
AssetId: a.Asset.ToID(),
Expand All @@ -61,6 +94,21 @@ type IssueScriptAction struct {

func (a IssueScriptAction) scriptAction() {}

func (a IssueScriptAction) Eq(other ScriptAction) bool {
b, ok := other.(*IssueScriptAction)
if !ok {
return false
}
return a.ID == b.ID &&
a.Name == b.Name &&
a.Description == b.Description &&
a.Quantity == b.Quantity &&
a.Decimals == b.Decimals &&
a.Reissuable == b.Reissuable &&
bytes.Equal(a.Script, b.Script) &&
a.Nonce == b.Nonce
}

func (a *IssueScriptAction) ToProtobuf() *g.InvokeScriptResult_Issue {
return &g.InvokeScriptResult_Issue{
AssetId: a.ID.Bytes(),
Expand Down Expand Up @@ -109,6 +157,14 @@ type ReissueScriptAction struct {

func (a ReissueScriptAction) scriptAction() {}

func (a ReissueScriptAction) Eq(other ScriptAction) bool {
b, ok := other.(*ReissueScriptAction)
if !ok {
return false
}
return a.Reissuable == b.Reissuable && a.AssetID == b.AssetID && a.Quantity == b.Quantity
}

func (a *ReissueScriptAction) ToProtobuf() *g.InvokeScriptResult_Reissue {
return &g.InvokeScriptResult_Reissue{
AssetId: a.AssetID.Bytes(),
Expand All @@ -125,6 +181,14 @@ type BurnScriptAction struct {

func (a BurnScriptAction) scriptAction() {}

func (a BurnScriptAction) Eq(other ScriptAction) bool {
b, ok := other.(*BurnScriptAction)
if !ok {
return false
}
return a.AssetID == b.AssetID && a.Quantity == b.Quantity
}

func (a *BurnScriptAction) ToProtobuf() *g.InvokeScriptResult_Burn {
return &g.InvokeScriptResult_Burn{
AssetId: a.AssetID.Bytes(),
Expand All @@ -140,6 +204,14 @@ type SponsorshipScriptAction struct {

func (a SponsorshipScriptAction) scriptAction() {}

func (a SponsorshipScriptAction) Eq(other ScriptAction) bool {
b, ok := other.(*SponsorshipScriptAction)
if !ok {
return false
}
return a.AssetID == b.AssetID && a.MinFee == b.MinFee
}

func (a *SponsorshipScriptAction) ToProtobuf() *g.InvokeScriptResult_SponsorFee {
return &g.InvokeScriptResult_SponsorFee{
MinFee: &g.Amount{
Expand Down
37 changes: 37 additions & 0 deletions pkg/proto/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,8 @@ type DataEntry interface {
BinarySize() int

ToProtobuf() *g.DataTransactionData_DataEntry

Eq(DataEntry) bool
}

var bytesToDataEntry = map[DataValueType]reflect.Type{
Expand Down Expand Up @@ -1786,6 +1788,13 @@ type IntegerDataEntry struct {
Value int64
}

func (e IntegerDataEntry) Eq(other DataEntry) bool {
if b, ok := other.(*IntegerDataEntry); ok {
return e.Key == b.Key && e.Value == b.Value
}
return false
}

func (e IntegerDataEntry) ToProtobuf() *g.DataTransactionData_DataEntry {
return &g.DataTransactionData_DataEntry{
Key: e.Key,
Expand Down Expand Up @@ -1914,6 +1923,13 @@ type BooleanDataEntry struct {
Value bool
}

func (e BooleanDataEntry) Eq(other DataEntry) bool {
if b, ok := other.(*BooleanDataEntry); ok {
return e.Key == b.Key && e.Value == b.Value
}
return false
}

func (e BooleanDataEntry) ToProtobuf() *g.DataTransactionData_DataEntry {
return &g.DataTransactionData_DataEntry{
Key: e.Key,
Expand Down Expand Up @@ -2046,6 +2062,13 @@ type BinaryDataEntry struct {
Value []byte
}

func (e BinaryDataEntry) Eq(other DataEntry) bool {
if b, ok := other.(*BinaryDataEntry); ok {
return e.Key == b.Key && bytes.Equal(e.Value, b.Value)
}
return false
}

func (e BinaryDataEntry) ToProtobuf() *g.DataTransactionData_DataEntry {
return &g.DataTransactionData_DataEntry{
Key: e.Key,
Expand Down Expand Up @@ -2181,6 +2204,13 @@ type StringDataEntry struct {
Value string
}

func (e StringDataEntry) Eq(other DataEntry) bool {
if b, ok := other.(*StringDataEntry); ok {
return e.Key == b.Key && e.Value == b.Value
}
return false
}

func (e StringDataEntry) ToProtobuf() *g.DataTransactionData_DataEntry {
return &g.DataTransactionData_DataEntry{
Key: e.Key,
Expand Down Expand Up @@ -2315,6 +2345,13 @@ type DeleteDataEntry struct {
Key string
}

func (e DeleteDataEntry) Eq(other DataEntry) bool {
if b, ok := other.(*DeleteDataEntry); ok {
return e.Key == b.Key
}
return false
}

func (e DeleteDataEntry) ToProtobuf() *g.DataTransactionData_DataEntry {
return &g.DataTransactionData_DataEntry{
Key: e.Key,
Expand Down
35 changes: 35 additions & 0 deletions pkg/ride/code_samples.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ride

const fcall1 = `
func getInt(key: String) = {
match getInteger(this, key) {
case x : Int => x
case _ => 0
}
}

let a = getInt("5")
let b = getInt("6")
a == b
`

const finf = `
func abc() = {
func in() = {
true
}
in()
}
abc()
`

const intersectNames = `
{-# STDLIB_VERSION 3 #-}
{-# SCRIPT_TYPE ACCOUNT #-}
{-# CONTENT_TYPE EXPRESSION #-}
func inc(v: Int) = v + 1
func call(inc: Int) = {
inc(inc)
}
call(2) == 3
`
Loading