From e9d30e43198b0f9de95b457eeca82c4c324aee1d Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Fri, 10 Aug 2018 14:20:55 -0400 Subject: [PATCH 1/4] Remove WAST support from cleos set code/contract The textual format of WebAssembly continues to be somewhat fluid. For example, the renaming of grow_memory with memory.grow. The binary format has been stable for some time. Only consume the binary format in cleos now -- the eosio tools (like eosiocpp) have produced binary .wasm files since the 1.0 release by default as do most other toolchains. This protects us from further deviations of the textual format --- programs/cleos/main.cpp | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index c4b0f654ae6..81365b2d92a 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -114,7 +114,6 @@ Usage: ./cleos create account [OPTIONS] creator name OwnerKey ActiveKey #include #include #include -#include #include #include @@ -2133,23 +2132,23 @@ int main( int argc, char** argv ) { // set contract subcommand string account; string contractPath; - string wastPath; + string wasmPath; string abiPath; bool shouldSend = true; auto codeSubcommand = setSubcommand->add_subcommand("code", localized("Create or update the code on an account")); codeSubcommand->add_option("account", account, localized("The account to set code for"))->required(); - codeSubcommand->add_option("code-file", wastPath, localized("The fullpath containing the contract WAST or WASM"))->required(); + codeSubcommand->add_option("code-file", wasmPath, localized("The fullpath containing the contract WASM"))->required(); auto abiSubcommand = setSubcommand->add_subcommand("abi", localized("Create or update the abi on an account")); abiSubcommand->add_option("account", account, localized("The account to set the ABI for"))->required(); - abiSubcommand->add_option("abi-file", abiPath, localized("The fullpath containing the contract WAST or WASM"))->required(); + abiSubcommand->add_option("abi-file", abiPath, localized("The fullpath containing the contract ABI"))->required(); auto contractSubcommand = setSubcommand->add_subcommand("contract", localized("Create or update the contract on an account")); contractSubcommand->add_option("account", account, localized("The account to publish a contract for")) ->required(); - contractSubcommand->add_option("contract-dir", contractPath, localized("The path containing the .wast and .abi")) + contractSubcommand->add_option("contract-dir", contractPath, localized("The path containing the .wasm and .abi")) ->required(); - contractSubcommand->add_option("wast-file", wastPath, localized("The file containing the contract WAST or WASM relative to contract-dir")); + contractSubcommand->add_option("wasm-file", wasmPath, localized("The file containing the contract WASM relative to contract-dir")); // ->check(CLI::ExistingFile); auto abi = contractSubcommand->add_option("abi-file,-a,--abi", abiPath, localized("The ABI for the contract relative to contract-dir")); // ->check(CLI::ExistingFile); @@ -2161,26 +2160,13 @@ int main( int argc, char** argv ) { if( cpath.filename().generic_string() == "." ) cpath = cpath.parent_path(); - if( wastPath.empty() ) - { - wastPath = (cpath / (cpath.filename().generic_string()+".wasm")).generic_string(); - if (!fc::exists(wastPath)) - wastPath = (cpath / (cpath.filename().generic_string()+".wast")).generic_string(); - } + if( wasmPath.empty() ) + wasmPath = (cpath / (cpath.filename().generic_string()+".wasm")).generic_string(); - std::cerr << localized(("Reading WAST/WASM from " + wastPath + "...").c_str()) << std::endl; - fc::read_file_contents(wastPath, wast); - EOS_ASSERT( !wast.empty(), wast_file_not_found, "no wast file found ${f}", ("f", wastPath) ); - vector wasm; - const string binary_wasm_header("\x00\x61\x73\x6d", 4); - if(wast.compare(0, 4, binary_wasm_header) == 0) { - std::cerr << localized("Using already assembled WASM...") << std::endl; - wasm = vector(wast.begin(), wast.end()); - } - else { - std::cerr << localized("Assembling WASM...") << std::endl; - wasm = wast_to_wasm(wast); - } + std::cerr << localized(("Reading WASM from " + wasmPath + "...").c_str()) << std::endl; + fc::read_file_contents(wasmPath, wast); + EOS_ASSERT( !wast.empty(), wast_file_not_found, "no wasm file found ${f}", ("f", wasmPath) ); + vector wasm = vector(wast.begin(), wast.end()); actions.emplace_back( create_setcode(account, bytes(wasm.begin(), wasm.end()) ) ); if ( shouldSend ) { From 4f6ff2a96e51b1bfb9ca473f6fd1f676fe5a3b36 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Fri, 10 Aug 2018 14:56:52 -0400 Subject: [PATCH 2/4] Fix merge goof in cleos main.cpp --- programs/cleos/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index c000882eda3..751fdd42311 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -2163,7 +2163,7 @@ int main( int argc, char** argv ) { if( wasmPath.empty() ) wasmPath = (cpath / (cpath.filename().generic_string()+".wasm")).generic_string(); else - wastPath = (cpath / wastPath).generic_string(); + wasmPath = (cpath / wasmPath).generic_string(); std::cerr << localized(("Reading WASM from " + wasmPath + "...").c_str()) << std::endl; fc::read_file_contents(wasmPath, wast); From 05ceede8a317eca71d0b976f57f5189024f18ae1 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Fri, 10 Aug 2018 15:22:18 -0400 Subject: [PATCH 3/4] Replease wasts with wasms in launcher template & test scripts --- testnet.template | 2 +- tests/Cluster.py | 12 ++++++------ tests/Node.py | 4 ++-- tests/consensus-validation-malicious-producers.py | 4 ++-- tests/nodeos_run_test.py | 12 ++++++------ tests/nodeos_under_min_avail_ram.py | 4 ++-- tests/p2p_network_test.py | 6 +++--- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/testnet.template b/testnet.template index 12e49a799fc..7a7593cc83a 100644 --- a/testnet.template +++ b/testnet.template @@ -75,7 +75,7 @@ wcmd create -n ignition # ------ DO NOT ALTER THE NEXT LINE ------- ###INSERT prodkeys -ecmd set contract eosio contracts/eosio.bios eosio.bios.wast eosio.bios.abi +ecmd set contract eosio contracts/eosio.bios eosio.bios.wasm eosio.bios.abi # Create required system accounts ecmd create key diff --git a/tests/Cluster.py b/tests/Cluster.py index fde8dde4c0d..3df4ccff04d 100644 --- a/tests/Cluster.py +++ b/tests/Cluster.py @@ -726,10 +726,10 @@ def bootstrap(totalNodes, prodCount, biosHost, biosPort, dontKill=False, onlyBio contract="eosio.bios" contractDir="contracts/%s" % (contract) - wastFile="%s.wast" % (contract) + wasmFile="%s.wasm" % (contract) abiFile="%s.abi" % (contract) Utils.Print("Publish %s contract" % (contract)) - trans=biosNode.publishContract(eosioAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True) + trans=biosNode.publishContract(eosioAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True) if trans is None: Utils.Print("ERROR: Failed to publish contract %s." % (contract)) return None @@ -850,10 +850,10 @@ def bootstrap(totalNodes, prodCount, biosHost, biosPort, dontKill=False, onlyBio contract="eosio.token" contractDir="contracts/%s" % (contract) - wastFile="%s.wast" % (contract) + wasmFile="%s.wasm" % (contract) abiFile="%s.abi" % (contract) Utils.Print("Publish %s contract" % (contract)) - trans=biosNode.publishContract(eosioTokenAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True) + trans=biosNode.publishContract(eosioTokenAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True) if trans is None: Utils.Print("ERROR: Failed to publish contract %s." % (contract)) return None @@ -905,10 +905,10 @@ def bootstrap(totalNodes, prodCount, biosHost, biosPort, dontKill=False, onlyBio contract="eosio.system" contractDir="contracts/%s" % (contract) - wastFile="%s.wast" % (contract) + wasmFile="%s.wasm" % (contract) abiFile="%s.abi" % (contract) Utils.Print("Publish %s contract" % (contract)) - trans=biosNode.publishContract(eosioAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True) + trans=biosNode.publishContract(eosioAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True) if trans is None: Utils.Print("ERROR: Failed to publish contract %s." % (contract)) return None diff --git a/tests/Node.py b/tests/Node.py index 89cbba5df60..3f50bfbce4f 100644 --- a/tests/Node.py +++ b/tests/Node.py @@ -757,9 +757,9 @@ def getAccountCodeHash(self, account): return None # publish contract and return transaction as json object - def publishContract(self, account, contractDir, wastFile, abiFile, waitForTransBlock=False, shouldFail=False): + def publishContract(self, account, contractDir, wasmFile, abiFile, waitForTransBlock=False, shouldFail=False): cmd="%s %s -v set contract -j %s %s" % (Utils.EosClientPath, self.endpointArgs, account, contractDir) - cmd += "" if wastFile is None else (" "+ wastFile) + cmd += "" if wasmFile is None else (" "+ wasmFile) cmd += "" if abiFile is None else (" " + abiFile) if Utils.Debug: Utils.Print("cmd: %s" % (cmd)) trans=None diff --git a/tests/consensus-validation-malicious-producers.py b/tests/consensus-validation-malicious-producers.py index 95357196e92..67d7722ed82 100755 --- a/tests/consensus-validation-malicious-producers.py +++ b/tests/consensus-validation-malicious-producers.py @@ -288,10 +288,10 @@ def myTest(transWillEnterBlock): error("Failed to create account %s" % (currencyAccount.name)) return False - wastFile="currency.wast" + wasmFile="currency.wasm" abiFile="currency.abi" Print("Publish contract") - trans=node.publishContract(currencyAccount.name, wastFile, abiFile, waitForTransBlock=True) + trans=node.publishContract(currencyAccount.name, wasmFile, abiFile, waitForTransBlock=True) if trans is None: error("Failed to publish contract.") return False diff --git a/tests/nodeos_run_test.py b/tests/nodeos_run_test.py index 40d5d8b5072..85be1bd940b 100755 --- a/tests/nodeos_run_test.py +++ b/tests/nodeos_run_test.py @@ -319,10 +319,10 @@ errorExit("FAILURE - get code currency1111 failed", raw=True) contractDir="contracts/eosio.token" - wastFile="eosio.token.wast" + wasmFile="eosio.token.wasm" abiFile="eosio.token.abi" Print("Publish contract") - trans=node.publishContract(currencyAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True) + trans=node.publishContract(currencyAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True) if trans is None: cmdError("%s set contract currency1111" % (ClientName)) errorExit("Failed to publish contract.") @@ -605,20 +605,20 @@ Print("upload exchange contract") contractDir="contracts/exchange" - wastFile="exchange.wast" + wasmFile="exchange.wasm" abiFile="exchange.abi" Print("Publish exchange contract") - trans=node.publishContract(exchangeAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True) + trans=node.publishContract(exchangeAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True) if trans is None: cmdError("%s set contract exchange" % (ClientName)) errorExit("Failed to publish contract.") contractDir="contracts/simpledb" - wastFile="simpledb.wast" + wasmFile="simpledb.wasm" abiFile="simpledb.abi" Print("Setting simpledb contract without simpledb account was causing core dump in %s." % (ClientName)) Print("Verify %s generates an error, but does not core dump." % (ClientName)) - retMap=node.publishContract("simpledb", contractDir, wastFile, abiFile, shouldFail=True) + retMap=node.publishContract("simpledb", contractDir, wasmFile, abiFile, shouldFail=True) if retMap is None: errorExit("Failed to publish, but should have returned a details map") if retMap["returncode"] == 0 or retMap["returncode"] == 139: # 139 SIGSEGV diff --git a/tests/nodeos_under_min_avail_ram.py b/tests/nodeos_under_min_avail_ram.py index 633a7d67a13..84425f275c6 100755 --- a/tests/nodeos_under_min_avail_ram.py +++ b/tests/nodeos_under_min_avail_ram.py @@ -138,10 +138,10 @@ def setName(self, num): trans=nodes[0].delegatebw(contractAccount, 1000000.0000, 88000000.0000, exitOnError=True) contractDir="contracts/integration_test" - wastFile="contracts/integration_test/integration_test.wast" + wasmFile="contracts/integration_test/integration_test.wasm" abiFile="contracts/integration_test/integration_test.abi" Print("Publish contract") - trans=nodes[0].publishContract(contractAccount.name, contractDir, wastFile, abiFile, waitForTransBlock=True) + trans=nodes[0].publishContract(contractAccount.name, contractDir, wasmFile, abiFile, waitForTransBlock=True) if trans is None: cmdError("%s set contract %s" % (ClientName, contractAccount.name)) errorExit("Failed to publish contract.") diff --git a/tests/p2p_network_test.py b/tests/p2p_network_test.py index 4d03526424e..bdd7ed16f00 100755 --- a/tests/p2p_network_test.py +++ b/tests/p2p_network_test.py @@ -144,10 +144,10 @@ Print("host %s: %s" % (hosts[i], trans)) -wastFile="eosio.system.wast" +wasmFile="eosio.system.wasm" abiFile="eosio.system.abi" -Print("\nPush system contract %s %s" % (wastFile, abiFile)) -trans=node0.publishContract(eosio.name, wastFile, abiFile, waitForTransBlock=True) +Print("\nPush system contract %s %s" % (wasmFile, abiFile)) +trans=node0.publishContract(eosio.name, wasmFile, abiFile, waitForTransBlock=True) if trans is None: Utils.errorExit("Failed to publish eosio.system.") else: From 52e066f2e53eaed6d2dddca4bf94dea45a323d65 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Sat, 11 Aug 2018 11:48:44 -0400 Subject: [PATCH 4/4] Remove one more unneeded "wast" variable now that we're wasm only --- programs/cleos/main.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 751fdd42311..f1ff21d3f02 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -2155,7 +2155,7 @@ int main( int argc, char** argv ) { std::vector actions; auto set_code_callback = [&]() { - std::string wast; + std::string wasm; fc::path cpath(contractPath); if( cpath.filename().generic_string() == "." ) cpath = cpath.parent_path(); @@ -2166,9 +2166,8 @@ int main( int argc, char** argv ) { wasmPath = (cpath / wasmPath).generic_string(); std::cerr << localized(("Reading WASM from " + wasmPath + "...").c_str()) << std::endl; - fc::read_file_contents(wasmPath, wast); - EOS_ASSERT( !wast.empty(), wast_file_not_found, "no wasm file found ${f}", ("f", wasmPath) ); - vector wasm = vector(wast.begin(), wast.end()); + fc::read_file_contents(wasmPath, wasm); + EOS_ASSERT( !wasm.empty(), wast_file_not_found, "no wasm file found ${f}", ("f", wasmPath) ); actions.emplace_back( create_setcode(account, bytes(wasm.begin(), wasm.end()) ) ); if ( shouldSend ) {