Skip to content

Commit

Permalink
Merge branch 'base'
Browse files Browse the repository at this point in the history
  • Loading branch information
sink772 committed Jan 29, 2021
2 parents 3eae825 + 94efbcb commit 6c8341e
Show file tree
Hide file tree
Showing 104 changed files with 3,149 additions and 755 deletions.
7 changes: 7 additions & 0 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ func (c *singleChain) MaxWaitTimeout() time.Duration {
return 0
}

func (c *singleChain) TransactionTimeout() time.Duration {
if c.cfg.TxTimeout > 0 {
return time.Duration(c.cfg.TxTimeout) * time.Millisecond
}
return ConfigDefaultTxTimeout
}

func (c *singleChain) State() (string, int64, error) {
c.mtx.RLock()
defer c.mtx.RUnlock()
Expand Down
3 changes: 3 additions & 0 deletions chain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path"
"path/filepath"
"strconv"
"time"

"github.com/icon-project/goloop/common/crypto"
"github.com/icon-project/goloop/module"
Expand All @@ -14,6 +15,7 @@ const (
ConfigDefaultNormalTxPoolSize = 5000
ConfigDefaultPatchTxPoolSize = 1000
ConfigDefaultMaxBlockTxBytes = 1024 * 1024
ConfigDefaultTxTimeout = 5000 * time.Millisecond
)

const (
Expand Down Expand Up @@ -50,6 +52,7 @@ type Config struct {
SecureAeads string `json:"secureAeads"`
DefWaitTimeout int64 `json:"waitTimeout"`
MaxWaitTimeout int64 `json:"maxTimeout"`
TxTimeout int64 `json:"txTimeout"`

GenesisStorage module.GenesisStorage `json:"-"`
Genesis json.RawMessage `json:"genesis"`
Expand Down
2 changes: 2 additions & 0 deletions cmd/cli/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func NewChainCmd(parentCmd *cobra.Command, parentVc *viper.Viper) (*cobra.Comman
param.SecureAeads, _ = fs.GetString("secure_aeads")
param.DefWaitTimeout, _ = fs.GetInt64("default_wait_timeout")
param.MaxWaitTimeout, _ = fs.GetInt64("max_wait_timeout")
param.TxTimeout, _ = fs.GetInt64("tx_timeout")
param.AutoStart, _ = fs.GetBool("auto_start")

var buf *bytes.Buffer
Expand Down Expand Up @@ -167,6 +168,7 @@ func NewChainCmd(parentCmd *cobra.Command, parentVc *viper.Viper) (*cobra.Comman
"Supported Secure AEAD with order (chacha,aes128,aes256) - Comma separated string")
joinFlags.Int64("default_wait_timeout", 0, "Default wait timeout in milli-second (0: disable)")
joinFlags.Int64("max_wait_timeout", 0, "Max wait timeout in milli-second (0: uses same value of default_wait_timeout)")
joinFlags.Int64("tx_timeout", 0, "Transaction timeout in milli-second (0: uses system default value)")
joinFlags.Bool("auto_start", false, "Auto start")

leaveCmd := &cobra.Command{
Expand Down
1 change: 1 addition & 0 deletions cmd/gochain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func main() {
flag.StringToString("log_forwarder_options", nil, "LogForwarder options, comma-separated 'key=value'")
flag.Int64Var(&cfg.DefWaitTimeout, "default_wait_timeout", 0, "Default wait timeout in milli-second (0: disable)")
flag.Int64Var(&cfg.MaxWaitTimeout, "max_wait_timeout", 0, "Max wait timeout in milli-second (0: uses same value of default_wait_timeout)")
flag.Int64Var(&cfg.TxTimeout, "tx_timeout", 0, "Transaction timeout in milli-second (0: uses system default value)")
flag.StringVar(&cfg.Engines, "engines", "python", "Execution engines, comma-separated (python,java)")
flag.StringVar(&lwCfg.Filename, "log_writer_filename", "", "Log filename")
flag.IntVar(&lwCfg.MaxSize, "log_writer_maxsize", 100, "Log file max size")
Expand Down
10 changes: 10 additions & 0 deletions common/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ func (a *Address) Equal(a2 module.Address) bool {
return bytes.Equal(a[:], a2.Bytes())
}

func AddressEqual(a, b module.Address) bool {
if a == b {
return true
}
if a == nil || b == nil {
return false
}
return a.Equal(b)
}

func (a *Address) RLPEncodeSelf(e codec.Encoder) error {
return e.Encode([]byte(a[:]))
}
Expand Down
89 changes: 57 additions & 32 deletions common/db/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,83 @@
package db

type Flags map[string]interface{}
type Context struct {
Database
info map[string]interface{}
}

func (c *Context) WithFlags(flags map[string]interface{}) *Context {
if c == nil {
func (f Flags) Get(n string) interface{} {
if f == nil {
return nil
} else {
return f[n]
}
info := make(map[string]interface{})
if len(c.info) > 0 {
for k, v := range c.info {
info[k] = v
}

func (f Flags) Clone() Flags {
flags := make(map[string]interface{})
if len(f) > 0 {
for k, v := range f {
flags[k] = v
}
}
return flags
}

func (f Flags) Merged(flags Flags) Flags {
newFlags := f.Clone()
if len(flags) > 0 {
for k, v := range flags {
info[k] = v
newFlags[k] = v
}
}
return &Context{
Database: c.Database,
info: info,
}
return newFlags
}

func (c *Context) GetFlag(n string) interface{} {
if c == nil {
return nil
}
return c.info[n]
type ContextBuilder interface {
WithFlags(flags Flags) Context
}

func WithFlags(dbase Database, flags Flags) Database {
ctx := ContextOf(dbase)
return ctx.WithFlags(flags)
type Context interface {
Database
ContextBuilder
GetFlag(n string) interface{}
Flags() Flags
}

func ContextOf(dbase Database) *Context {
if dbase == nil {
type databaseContext struct {
Database
flags Flags
}

func (c *databaseContext) WithFlags(flags Flags) Context {
newFlags := c.flags.Merged(flags)
return &databaseContext{c.Database, newFlags}
}

func (c *databaseContext) GetFlag(name string) interface{} {
return c.flags.Get(name)
}

func (c *databaseContext) Flags() Flags {
return c.flags.Clone()
}

func WithFlags(database Database, flags Flags) Context {
if database == nil {
return nil
}
if dbc, ok := dbase.(*Context); ok {
return dbc
if ctx, ok := database.(Context); ok {
return ctx
} else {
return &Context{
Database: dbase,
info: make(map[string]interface{}),
if cb, ok := database.(ContextBuilder); ok {
return cb.WithFlags(flags)
} else {
return &databaseContext{database, flags}
}
}
}

func GetFlag(db Database, name string) interface{} {
return ContextOf(db).GetFlag(name)
func GetFlag(database Database, name string) interface{} {
if ctx, ok := database.(Context); ok {
return ctx.GetFlag(name)
} else {
return nil
}
}
36 changes: 32 additions & 4 deletions common/db/layer_db.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package db

import (
"github.com/pkg/errors"
"sync"

"github.com/pkg/errors"
)

type layerBucket struct {
Expand Down Expand Up @@ -134,9 +135,36 @@ func (ldb *layerDB) Close() error {
return nil
}

func NewLayerDB(dbase Database) LayerDB {
return &layerDB{
real: dbase,
type layerDBContext struct {
LayerDB
flags Flags
}

func (c *layerDBContext) WithFlags(flags Flags) Context {
newFlags := c.flags.Merged(flags)
return &layerDBContext{c.LayerDB, newFlags}
}

func (c *layerDBContext) GetFlag(name string) interface{} {
return c.flags.Get(name)
}

func (c *layerDBContext) Flags() Flags {
return c.flags.Clone()
}

func (ldb *layerDB) WithFlags(flags Flags) Context {
return &layerDBContext{ldb, flags}
}

func NewLayerDB(database Database) LayerDB {
ldb := &layerDB{
real: database,
buckets: make(map[string]*layerBucket),
}
if ctx, ok := database.(Context); ok {
return &layerDBContext{ldb, ctx.Flags()}
} else {
return ldb
}
}
13 changes: 13 additions & 0 deletions common/hexint.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ func (i *HexInt) Value() *big.Int {
return &i.Int
}

func (i *HexInt) SetValue(x *big.Int) *HexInt {
if iv := i.Int.Set(x); iv == nil {
return nil
} else {
return i
}
}

func (i *HexInt) AddValue(x, y *big.Int) *HexInt {
i.Add(x, y)
return i
}

func NewHexInt(v int64) *HexInt {
i := new(HexInt)
i.SetInt64(v)
Expand Down
8 changes: 7 additions & 1 deletion common/trie/ompt/mpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func bytesToNibs(k []byte) []byte {
return nibs
}

func (mb *mptBase) Equal(mb2 *mptBase) bool {
return mb.db == mb2.db &&
mb.bucket == mb2.bucket &&
mb.objectType == mb2.objectType
}

func (m *mpt) bytesToNibs(k []byte) []byte {
ks := len(k)
if cap(m.nibs) < ks*2 {
Expand Down Expand Up @@ -270,7 +276,7 @@ func (m *mpt) Reset(s trie.ImmutableForObject) {
}

m2, ok := s.(*mpt)
if (!ok) || !reflect.DeepEqual(m2.mptBase, m.mptBase) {
if (!ok) || !m2.mptBase.Equal(&m.mptBase) {
log.Panicln("Supplied ImmutableForObject isn't usable in here", s)
}
m.root = m2.root
Expand Down
5 changes: 5 additions & 0 deletions doc/goloop_admin_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@ components:
type: integer
default: 0
description: "Max wait timeout in milli-second(0:uses same value of defaultWaitTimeout)"
txTimeout:
type: integer
default: 0
description: "Transaction timeout in milli-second(0:uses system default value)"
autoStart:
type: boolean
default: false
Expand All @@ -571,6 +575,7 @@ components:
secureSuites: "none,tls,ecdhe"
secureAeads: "chacha,aes128,aes256"
defaultWaitTimeout: 0
txTimeout: 0
maxWaitTimeout: 0
autoStart: false
ChainImportParam:
Expand Down
2 changes: 1 addition & 1 deletion javaee/app/proxytest/src/java/ProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static void setGetApiHandler(EEProxy proxy) {

private static void setInvokeHandler(EEProxy proxy) {
proxy.setOnInvokeListener((code, isQuery, from, to, value, limit,
method, params, info, eid, nextHash, graphHash, prevEID) -> {
method, params, info, contractID, eid, nextHash, graphHash, prevEID) -> {
if (logger.isDebugEnabled()) {
logger.debug(">>> code={}", code);
logger.debug(" isQuery={}", isQuery);
Expand Down
7 changes: 4 additions & 3 deletions javaee/exec/src/java/foundation/icon/ee/ipc/EEProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ public interface OnInvokeListener {
InvokeResult onInvoke(String code, boolean isQuery, Address from, Address to,
BigInteger value, BigInteger limit,
String method, Object[] params,
Map<String, Object> info, int eid, int nextHash,
Map<String, Object> info,
byte[] contractID, int eid, int nextHash,
byte[] graphHash, int prevEID) throws IOException;
}

Expand Down Expand Up @@ -293,7 +294,7 @@ private void handleInvoke(Value raw) throws IOException {
Object[] params = (Object[]) TypedObj.decodeAny(data.get(7));
@SuppressWarnings("unchecked")
var info = (Map<String, Object>) TypedObj.decodeAny(data.get(8));
// TODO need to handle codeId in data.get(9)
var contractID = getValueAsByteArray(data.get(9));
int eid = data.get(10).asIntegerValue().asInt();
int nextHash = 0;
byte[] graphHash = null;
Expand All @@ -309,7 +310,7 @@ private void handleInvoke(Value raw) throws IOException {
if (mOnInvokeListener != null) {
InvokeResult result = mOnInvokeListener.onInvoke(
code, isQuery, from, to, value, limit, method, params,
info, eid, nextHash, graphHash, prevEID);
info, contractID, eid, nextHash, graphHash, prevEID);
sendMessage(MsgType.RESULT, result.getStatus(), result.getStepUsed(), result.getResult());
} else {
throw new IOException("no invoke handler");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,22 @@ public class ExternalState implements IExternalState {
private final Address owner;
private final String codePath;
private final FileIO fileIO;
private final byte[] contractID;
private final StepCost stepCost;
private final int nextHash;
private final byte[] graphHash;
private int feeProportion;

ExternalState(EEProxy proxy, int option, String codePath,
FileIO fileIO, BigInteger blockHeight,
FileIO fileIO, byte[] contractID, BigInteger blockHeight,
BigInteger blockTimestamp, Address owner,
Map<String, BigInteger> stepCosts, int nextHash,
byte[] graphHash) {
this.proxy = proxy;
this.option = option;
this.codePath = codePath;
this.fileIO = fileIO;
this.contractID = contractID;
this.blockHeight = blockHeight.longValue();
this.blockTimestamp = blockTimestamp.longValue();
this.owner = owner; // owner cannot be null
Expand Down Expand Up @@ -100,6 +102,10 @@ public void setTransformedCode(byte[] code) {
}
}

public byte[] getContractID() {
return contractID;
}

@Override
public ObjectGraph getObjectGraph() {
try {
Expand Down
Loading

0 comments on commit 6c8341e

Please sign in to comment.