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 serializer can serialize strings and bytes arrays with size up t… #448

Draft
wants to merge 6 commits into
base: ride_vm_fsm
Choose a base branch
from
Draft
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
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 build gotest mod-clean
all: vendor vetcheck fmtcheck build gotest mod-clean

ver:
@echo Building version: $(VERSION)
Expand Down
2 changes: 1 addition & 1 deletion cmd/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var (

var defaultPeers = map[string]string{
"mainnet": "34.253.153.4:6868,168.119.116.189:6868,135.181.87.72:6868,35.158.218.156:6868,52.48.34.89:6868",
"testnet": "159.69.126.149:6863,94.130.105.239:6863,159.69.126.153:6863,94.130.172.201:6863",
"testnet": "159.69.126.149:6868,94.130.105.239:6868,159.69.126.153:6868,94.130.172.201:6868",
"stagenet": "88.99.185.128:6862,49.12.15.166:6862,95.216.205.3:6862,88.198.179.16:6862",
}

Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
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=
github.com/fxamacker/cbor/v2 v2.2.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
Expand Down
35 changes: 0 additions & 35 deletions pkg/ride/code_samples.go

This file was deleted.

10 changes: 8 additions & 2 deletions pkg/ride/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ func encode(v uint16) []byte {
return b
}

func encode32(v uint32) []byte {
b := make([]byte, 4)
binary.BigEndian.PutUint32(b, v)
return b
}

func compile(f State, node Node) (State, error) {
switch n := node.(type) {
case *AssignmentNode:
Expand Down Expand Up @@ -97,11 +103,11 @@ func CompileDapp(txID string, tree *Tree) (out *Executable, err error) {
defer func() {
if r := recover(); r != nil {
zap.S().Error(DecompileTree(tree), " ", r)
err = errors.New("failed to compile")
err = errors.Errorf("failed to compile: %s", r.(string))
}
}()
if !tree.IsDApp() {
return nil, errors.Errorf("unable to compile dappp")
return nil, errors.Errorf("unable to compile DApp")
}
fns := tree.Functions
if tree.HasVerifier() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/ride/compiler_assigment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type AssigmentState struct {
bodyParams params
prev State
name string
n uniqueid
n uniqueID
body Deferred
d Deferreds
}
Expand Down Expand Up @@ -53,7 +53,7 @@ func (a AssigmentState) Boolean(v bool) State {
return a
}

func assigmentTransition(prev State, params params, name string, n uniqueid, d Deferreds) State {
func assigmentTransition(prev State, params params, name string, n uniqueID, d Deferreds) State {
return newAssigment(prev, params, name, n, d)
}

Expand All @@ -62,7 +62,7 @@ func extendParams(p params) params {
return p
}

func newAssigment(prev State, p params, name string, n uniqueid, d Deferreds) State {
func newAssigment(prev State, p params, name string, n uniqueID, d Deferreds) State {
return AssigmentState{
prev: prev,
params: p,
Expand Down
4 changes: 2 additions & 2 deletions pkg/ride/compiler_call_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type CallSystemState struct {
deferred []Deferred
deferreds Deferreds
// Sequential function arguments.
ns []uniqueid
ns []uniqueID
}

func (a CallSystemState) backward(state State) State {
Expand Down Expand Up @@ -62,7 +62,7 @@ func callTransition(prev State, params params, name string, argc uint16, d Defer
}

func newCallSystemState(prev State, params params, name string, argc uint16, d Deferreds) State {
var ns []uniqueid
var ns []uniqueID
for i := uint16(0); i < argc; i++ {
ns = append(ns, params.u.next())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ride/compiler_call_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type CallUserState struct {
name string
argc uint16
deferreds Deferreds
ns []uniqueid
ns []uniqueID
}

func (a CallUserState) backward(state State) State {
Expand Down
16 changes: 8 additions & 8 deletions pkg/ride/compiler_conditional.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ type ConditionalState struct {
params
prev State

rets []uint16
rets []uint32

// Clean assigments after exit.
deferred []Deferred
deferreds Deferreds

condN uniqueid
condN uniqueID
}

func (a ConditionalState) backward(as State) State {
Expand Down Expand Up @@ -126,19 +126,19 @@ func (a ConditionalState) Write(_ params, _ []byte) {
a.b.write(encode(a.condN))

a.b.jpmIfFalse()
patchTruePosition := a.b.writeStub(2)
patchFalsePosition := a.b.writeStub(2)
patchNextPosition := a.b.writeStub(2)
patchTruePosition := a.b.writeStub(4)
patchFalsePosition := a.b.writeStub(4)
patchNextPosition := a.b.writeStub(4)

a.b.patch(patchTruePosition, encode(a.b.len()))
a.b.patch(patchTruePosition, encode32(a.b.len()))
trueB.Write(a.params, nil)
a.b.ret()

a.b.patch(patchFalsePosition, encode(a.b.len()))
a.b.patch(patchFalsePosition, encode32(a.b.len()))
falsB.Write(a.params, nil)
a.b.ret()

a.b.patch(patchNextPosition, encode(a.b.len()))
a.b.patch(patchNextPosition, encode32(a.b.len()))
}
func (a ConditionalState) Clean() {
}
31 changes: 15 additions & 16 deletions pkg/ride/compiler_func.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package ride

import "fmt"
import (
"fmt"
)

type arguments []string

type Deferreds interface {
Add(Deferred, uniqueid, string)
Add(Deferred, uniqueID, string)
}

type dd struct {
deferred Deferred
uniq uniqueid
uniq uniqueID
debug string
}

Expand All @@ -19,7 +21,7 @@ type deferreds struct {
d []dd
}

func (a *deferreds) Add(deferred2 Deferred, n uniqueid, debug string) {
func (a *deferreds) Add(deferred2 Deferred, n uniqueID, debug string) {
a.d = append(a.d, dd{
deferred: deferred2,
uniq: n,
Expand All @@ -36,9 +38,9 @@ type FuncState struct {
prev State
name string
args arguments
n uniqueid
n uniqueID
invokeParam string
paramIds []uniqueid
paramIds []uniqueID

// References that defined inside function.
deferred []Deferred
Expand Down Expand Up @@ -72,7 +74,7 @@ func funcTransition(prev State, params params, name string, args []string, invok
if invokeParam != "" {
args = append([]string{invokeParam}, args...)
}
paramIds := make([]uniqueid, 0, len(args))
paramIds := make([]uniqueID, 0, len(args))
for i := range args {
e := params.u.next()
paramIds = append(paramIds, e)
Expand All @@ -99,7 +101,7 @@ func (a FuncState) Assigment(name string) State {
return assigmentTransition(a, a.params, name, n, a.defers)
}

func (a FuncState) ParamIds() []uniqueid {
func (a FuncState) ParamIds() []uniqueID {
return a.paramIds
}

Expand Down Expand Up @@ -152,13 +154,11 @@ func (a FuncState) Func(name string, args []string, invoke string) State {
return funcTransition(a, a.params, name, args, invoke)
}

func (a FuncState) Clean() {

}
func (a FuncState) Clean() {}

func (a FuncState) Write(_ params, _ []byte) {
pos := a.b.len()
a.params.c.set(a.n, nil, 0, pos, false, fmt.Sprintf("function %s", a.name))
a.params.c.set(a.n, nil, 0, pos, fmt.Sprintf("function %s", a.name))
if len(a.deferred) != 1 {
panic("len(a.deferred) != 1")
}
Expand All @@ -170,17 +170,16 @@ func (a FuncState) Write(_ params, _ []byte) {
}
a.deferred[0].Write(a.params, nil)

// End of function body. Clear and write assigments.
// End of function body. Clear and write assignments.
for _, v := range a.defers.Get() {
v.deferred.Clean()
}
a.b.ret()

for _, v := range a.defers.Get() {
pos := a.b.len()
a.c.set(v.uniq, nil, 0, pos, false, v.debug)
p := a.b.len()
a.c.set(v.uniq, nil, 0, p, v.debug)
v.deferred.Write(a.params, nil)
a.b.ret()
}

}
Loading