Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #184 from AntelopeIO/larryk85/config-fixes
Browse files Browse the repository at this point in the history
Backwards Compatibility System [1.1.1]
  • Loading branch information
mikelik authored May 23, 2023
2 parents 7124480 + 4381a2b commit 67a0403
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 4 deletions.
63 changes: 63 additions & 0 deletions src/dune/configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import sys
import inspect

#pylint: disable=invalid-name
class node_config_v0_0_0 :
_config_args = {"wasm-runtime" : "eos-vm{0}",
"abi-serializer-max-time-ms" : "15",
"chain-state-db-size-mb" : "65536",
"contracts-console" : "true",
"http-server-address" : "0.0.0.0:8888",
"p2p-listen-endpoint" : "0.0.0.0:9876",
"state-history-endpoint" : "0.0.0.0:8080",
"verbose-http-errors" : "true",
"agent-name" : "DUNE Test Node",
"net-threads" : "2",
"max-transaction-time" : "100",
"producer-name" : "eosio",
"enable-stale-production" : "true",
"resource-monitor-not-shutdown-on-threshold-exceeded" : "true",
"http-validate-host" : "false"}

_plugins = ["eosio::chain_api_plugin",
"eosio::http_plugin",
"eosio::producer_plugin",
"eosio::producer_api_plugin"]

def get_config_ini(self, arch):
config = ""
vm_type = ""
if arch == "amd64":
vm_type = "-jit"

for k,v in self._config_args.items() :
config += k + " = " + v.format(vm_type) + "\n"
for plugin in self._plugins :
config += "plugin = " + plugin + "\n"
return config


class node_config_v4_0_0(node_config_v0_0_0) :
_config_add = {"read-only-read-window-time-us" : "120000"}

def get_config_ini(self, arch) :
#pylint: disable=too-many-function-args
config = super().get_config_ini(super(), arch)
for k,v in self._config_add.items() :
config += k + " = " + v + "\n"
return config

def get_config_ini(arch, major, minor=0, patch=0) :
cls_name = "node_config_v"+ str(major) + "_" + str(minor) + "_" + str(patch)
current_mod = sys.modules[__name__]
config_cls_name = ""
for name, obj in inspect.getmembers(current_mod):
if inspect.isclass(obj):
if (obj.__name__ == cls_name or obj.__name__ < cls_name) :
if config_cls_name < obj.__name__ :
config_cls_name = obj.__name__

config_cls = getattr(current_mod, config_cls_name)
return config_cls.get_config_ini(config_cls, arch)

#pylint: enable=invalid-name
20 changes: 20 additions & 0 deletions src/dune/docker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import platform
import subprocess
import tempfile


class docker:
Expand Down Expand Up @@ -97,6 +98,25 @@ def cp_from_host(self, host_file, container_file):
def rm_file(self, file_name):
self.execute_cmd(['rm', '-rf', file_name])

def write_file(self, file_name, body):
tmp_name = ""
with tempfile.NamedTemporaryFile(mode='w+', delete=False) as tmp:
tmp.write(body)
tmp.flush()
tmp_name = tmp.name

self.cp_from_host(tmp_name, file_name)
os.unlink(tmp_name)


def get_arch(self) :
stdout, stderr, exit_code = self.execute_cmd(['uname', '-m'])
if stdout in ('x86_64\n', 'amd64\n') :
return 'amd64'
if stdout in ('aarch64\n', 'arm64v8\n', 'arm64\n') :
return 'arm64'
raise NotImplementedError("Error, using an unsupported architecture")

def find_pid(self, process_name):
stdout, stderr, exit_code = self.execute_cmd(['ps', 'ax'])
for line in stdout.splitlines(True):
Expand Down
10 changes: 10 additions & 0 deletions src/dune/dune.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# pylint: disable=missing-function-docstring, missing-module-docstring
import os
import re
import sys # sys.stderr
from context import context
from docker import docker
from node_state import node_state
from configs import get_config_ini

# VERSION INFORMATION
def version_major():
Expand Down Expand Up @@ -101,6 +103,11 @@ def create_node(self, nod):
print("Creating node [" + nod.name() + "]")
self._docker.execute_cmd(['mkdir', '-p', nod.data_dir()])

def get_current_nodeos_version(self):
stdout, stderr, exit_code = self._docker.execute_cmd(['nodeos', '--version'])
#from "v4.0.0-rc1\n" make array of "["4","0","0","rc1"]"
return re.split(r"[+.-]", stdout[1:].strip())

def start_node(self, nod, snapshot=None):
stdout, stderr, exit_code = self._docker.execute_cmd(['ls', '/app/nodes'])

Expand All @@ -123,6 +130,9 @@ def start_node(self, nod, snapshot=None):

# copy config.ini to config-dir
if not is_restart and nod.config() is None:
current_ver = self.get_current_nodeos_version()
config_str = get_config_ini(self._docker.get_arch(), current_ver[0], current_ver[1], current_ver[2])
self._docker.write_file("/app/config.ini", config_str)
nod.set_config('/app/config.ini')

if nod.config() is not None:
Expand Down
9 changes: 6 additions & 3 deletions tests/common.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@


import os
import platform

# Find path for tests:
TEST_PATH = os.path.dirname(os.path.abspath(__file__))

# Set path for executable:
DUNE_EXE = os.path.split(TEST_PATH)[0] + "/dune"
DUNE_EXE = os.path.join( os.path.split(TEST_PATH)[0] , "dune")

if platform.system() == 'Windows':
DUNE_EXE += ".bat"

print("Executable path: ", DUNE_EXE)

# Default addresses
Expand Down
2 changes: 1 addition & 1 deletion tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import shutil # rmtree
import subprocess

# pylint: disable=wildcard-import
# pylint: disable=unused-wildcard-import,wildcard-import
from common import * # local defines
from container import container

Expand Down

0 comments on commit 67a0403

Please sign in to comment.