提交 5c316711 编写于 作者: A arhag

Merge branch 'master' into 2561-eosio_assert_code

...@@ -5,7 +5,7 @@ RUN git clone -b $branch https://github.com/EOSIO/eos.git --recursive \ ...@@ -5,7 +5,7 @@ RUN git clone -b $branch https://github.com/EOSIO/eos.git --recursive \
&& cd eos && echo "$branch:$(git rev-parse HEAD)" > /etc/eosio-version \ && cd eos && echo "$branch:$(git rev-parse HEAD)" > /etc/eosio-version \
&& cmake -H. -B"/tmp/build" -GNinja -DCMAKE_BUILD_TYPE=Release -DWASM_ROOT=/opt/wasm -DCMAKE_CXX_COMPILER=clang++ \ && cmake -H. -B"/tmp/build" -GNinja -DCMAKE_BUILD_TYPE=Release -DWASM_ROOT=/opt/wasm -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/tmp/build -DSecp256k1_ROOT_DIR=/usr/local -DBUILD_MONGO_DB_PLUGIN=true \ -DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/tmp/build -DSecp256k1_ROOT_DIR=/usr/local -DBUILD_MONGO_DB_PLUGIN=true \
&& cmake --build /tmp/build --target install && cmake --build /tmp/build --target install && rm /tmp/build/bin/eosiocpp
FROM ubuntu:18.04 FROM ubuntu:18.04
......
...@@ -15,7 +15,7 @@ Simple and fast setup of EOS.IO on Docker is also available. ...@@ -15,7 +15,7 @@ Simple and fast setup of EOS.IO on Docker is also available.
## Build eos image ## Build eos image
```bash ```bash
git clone https://github.com/EOSIO/eos.git --recursive git clone https://github.com/EOSIO/eos.git --recursive --depth 1
cd eos/Docker cd eos/Docker
docker build . -t eosio/eos docker build . -t eosio/eos
``` ```
...@@ -67,7 +67,7 @@ After `docker-compose up -d`, two services named `nodeosd` and `keosd` will be s ...@@ -67,7 +67,7 @@ After `docker-compose up -d`, two services named `nodeosd` and `keosd` will be s
You can run the `cleos` commands via a bash alias. You can run the `cleos` commands via a bash alias.
```bash ```bash
alias cleos='docker-compose exec keosd /opt/eosio/bin/cleos -u http://nodeosd:8888' alias cleos='docker-compose exec keosd /opt/eosio/bin/cleos -u http://nodeosd:8888 --wallet-url http://localhost:8888'
cleos get info cleos get info
cleos get account inita cleos get account inita
``` ```
...@@ -86,29 +86,15 @@ docker-compose stop keosd ...@@ -86,29 +86,15 @@ docker-compose stop keosd
### Develop/Build custom contracts ### Develop/Build custom contracts
Due to the fact that the eosio/eos image does not contain the required dependencies for contract development (this is by design, to keep the image size small), you will need to utilize eosio/builder. However, eosio/builder does not contain eosiocpp. As such, you will need to run eosio/builder interactively, and clone, build and install EOS. Once this is complete, you can then utilize eosiocpp to compile your contracts. Due to the fact that the eosio/eos image does not contain the required dependencies for contract development (this is by design, to keep the image size small), you will need to utilize the eosio/eos-dev image. This image contains both the required binaries and dependencies to build contracts using eosiocpp.
You can also create a Dockerfile that will do this for you. You can either use the image available on [Docker Hub](https://hub.docker.com/r/eosio/eos-dev/) or navigate into the dev folder and build the image manually.
```
FROM eosio/builder
RUN git clone -b master --depth 1 https://github.com/EOSIO/eos.git --recursive \
&& cd eos \
&& cmake -H. -B"/tmp/build" -GNinja -DCMAKE_BUILD_TYPE=Release -DWASM_ROOT=/opt/wasm -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang -DSecp256k1_ROOT_DIR=/usr/local -DBUILD_MONGO_DB_PLUGIN=true \
&& cmake --build /tmp/build --target install && rm -rf /tmp/build /eos
```
Then, from the same directory as the Dockerfile, simply run:
```bash ```bash
docker build -t eosio/contracts . cd dev
docker run -it -v /path/to/custom/contracts:/contracts eosio/contracts /bin/bash docker build -t eosio/eos-dev .
``` ```
At this time you should be at a bash shell. You can navigate into the /contracts directory and use eosiocpp to compile your custom contracts.
### Change default configuration ### Change default configuration
You can use docker compose override file to change the default configurations. For example, create an alternate config file `config2.ini` and a `docker-compose.override.yml` with the following content. You can use docker compose override file to change the default configurations. For example, create an alternate config file `config2.ini` and a `docker-compose.override.yml` with the following content.
......
FROM eosio/builder
ARG branch=master
RUN git clone -b $branch https://github.com/EOSIO/eos.git --recursive \
&& cd eos && echo "$branch:$(git rev-parse HEAD)" > /etc/eosio-version \
&& cmake -H. -B"/opt/eosio" -GNinja -DCMAKE_BUILD_TYPE=Release -DWASM_ROOT=/opt/wasm -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/opt/eosio -DSecp256k1_ROOT_DIR=/usr/local -DBUILD_MONGO_DB_PLUGIN=true \
&& cmake --build /opt/eosio --target install \
&& mv /eos/Docker/config.ini / && mv /opt/eosio/contracts /contracts && mv /eos/Docker/nodeosd.sh /opt/eosio/bin/nodeosd.sh \
&& rm -rf /eos
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install openssl && rm -rf /var/lib/apt/lists/*
ENV EOSIO_ROOT=/opt/eosio
RUN chmod +x /opt/eosio/bin/nodeosd.sh
ENV LD_LIBRARY_PATH /usr/local/lib
VOLUME /opt/eosio/bin/data-dir
ENV PATH /opt/eosio/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
namespace eosiosystem { namespace eosiosystem {
const int64_t min_daily_tokens = 100; const int64_t min_daily_tokens = 100;
const int64_t min_activated_stake = 150'000'000'0000;
const double continuous_rate = 0.04879; // 5% annual rate const double continuous_rate = 0.04879; // 5% annual rate
const double perblock_rate = 0.0025; // 0.25% const double perblock_rate = 0.0025; // 0.25%
const double standby_rate = 0.0075; // 0.75% const double standby_rate = 0.0075; // 0.75%
...@@ -23,7 +23,7 @@ namespace eosiosystem { ...@@ -23,7 +23,7 @@ namespace eosiosystem {
require_auth(N(eosio)); require_auth(N(eosio));
/** until activated stake crosses this threshold no new rewards are paid */ /** until activated stake crosses this threshold no new rewards are paid */
if( _gstate.total_activated_stake < 150'000'000'0000 ) if( _gstate.total_activated_stake < min_activated_stake )
return; return;
if( _gstate.last_pervote_bucket_fill == 0 ) /// start the presses if( _gstate.last_pervote_bucket_fill == 0 ) /// start the presses
...@@ -56,6 +56,8 @@ namespace eosiosystem { ...@@ -56,6 +56,8 @@ namespace eosiosystem {
const auto& prod = _producers.get( owner ); const auto& prod = _producers.get( owner );
eosio_assert( prod.active(), "producer does not have an active key" ); eosio_assert( prod.active(), "producer does not have an active key" );
eosio_assert( _gstate.total_activated_stake >= min_activated_stake, "not enough has been staked for producers to claim rewards" );
auto ct = current_time(); auto ct = current_time();
eosio_assert( ct - prod.last_claim_time > useconds_per_day, "already claimed rewards within past day" ); eosio_assert( ct - prod.last_claim_time > useconds_per_day, "already claimed rewards within past day" );
...@@ -81,8 +83,14 @@ namespace eosiosystem { ...@@ -81,8 +83,14 @@ namespace eosiosystem {
_gstate.last_pervote_bucket_fill = ct; _gstate.last_pervote_bucket_fill = ct;
} }
int64_t producer_per_block_pay = (_gstate.perblock_bucket * prod.unpaid_blocks) / _gstate.total_unpaid_blocks; int64_t producer_per_block_pay = 0;
int64_t producer_per_vote_pay = int64_t((_gstate.pervote_bucket * prod.total_votes ) / _gstate.total_producer_vote_weight); if( _gstate.total_unpaid_blocks > 0 ) {
producer_per_block_pay = (_gstate.perblock_bucket * prod.unpaid_blocks) / _gstate.total_unpaid_blocks;
}
int64_t producer_per_vote_pay = 0;
if( _gstate.total_producer_vote_weight > 0 ) {
producer_per_vote_pay = int64_t((_gstate.pervote_bucket * prod.total_votes ) / _gstate.total_producer_vote_weight);
}
if( producer_per_vote_pay < 100'0000 ) { if( producer_per_vote_pay < 100'0000 ) {
producer_per_vote_pay = 0; producer_per_vote_pay = 0;
} }
......
...@@ -181,8 +181,8 @@ void resource_limits_manager::verify_account_ram_usage( const account_name accou ...@@ -181,8 +181,8 @@ void resource_limits_manager::verify_account_ram_usage( const account_name accou
if( ram_bytes >= 0 ) { if( ram_bytes >= 0 ) {
EOS_ASSERT( usage.ram_usage <= ram_bytes, ram_usage_exceeded, EOS_ASSERT( usage.ram_usage <= ram_bytes, ram_usage_exceeded,
"account ${account} has insufficient ram bytes; needs ${available} has ${needs}", "account ${account} has insufficient ram; needs ${needs} bytes has ${available} bytes",
("account", account)("available",usage.ram_usage)("needs",ram_bytes) ); ("account", account)("needs",usage.ram_usage)("available",ram_bytes) );
} }
} }
......
...@@ -403,11 +403,27 @@ static float64_t to_softfloat64( double d ) { ...@@ -403,11 +403,27 @@ static float64_t to_softfloat64( double d ) {
return *reinterpret_cast<float64_t*>(&d); return *reinterpret_cast<float64_t*>(&d);
} }
static fc::variant get_global_row( const database& db, const abi_def& abi, const abi_serializer& abis ) {
const auto table_type = get_table_type(abi, N(global));
EOS_ASSERT(table_type == read_only::KEYi64, chain::contract_table_query_exception, "Invalid table type ${type} for table global", ("type",table_type));
const auto* const table_id = db.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple(N(eosio), N(eosio), N(global)));
EOS_ASSERT(table_id, chain::contract_table_query_exception, "Missing table global");
const auto& kv_index = db.get_index<key_value_index, by_scope_primary>();
const auto it = kv_index.find(boost::make_tuple(table_id->id, N(global)));
EOS_ASSERT(it != kv_index.end(), chain::contract_table_query_exception, "Missing row in table global");
vector<char> data;
read_only::copy_inline_row(*it, data);
return abis.binary_to_variant(abis.get_table_type(N(global)), data);
}
read_only::get_producers_result read_only::get_producers( const read_only::get_producers_params& p ) const { read_only::get_producers_result read_only::get_producers( const read_only::get_producers_params& p ) const {
const abi_def abi = get_abi(db, N(eosio)); const abi_def abi = get_abi(db, N(eosio));
const auto table_type = get_table_type(abi, N(producers)); const auto table_type = get_table_type(abi, N(producers));
const abi_serializer abis{ abi }; const abi_serializer abis{ abi };
EOS_ASSERT(table_type == KEYi64, chain::contract_table_query_exception, "Invalid table type ${type}", ("type",table_type)); EOS_ASSERT(table_type == KEYi64, chain::contract_table_query_exception, "Invalid table type ${type} for table producers", ("type",table_type));
const auto& d = db.db(); const auto& d = db.db();
const auto lower = name{p.lower_bound}; const auto lower = name{p.lower_bound};
...@@ -448,6 +464,7 @@ read_only::get_producers_result read_only::get_producers( const read_only::get_p ...@@ -448,6 +464,7 @@ read_only::get_producers_result read_only::get_producers( const read_only::get_p
result.rows.emplace_back(fc::variant(data)); result.rows.emplace_back(fc::variant(data));
} }
result.total_producer_vote_weight = get_global_row(d, abi, abis)["total_producer_vote_weight"].as_double();
return result; return result;
} }
......
...@@ -216,6 +216,7 @@ public: ...@@ -216,6 +216,7 @@ public:
struct get_producers_result { struct get_producers_result {
vector<fc::variant> rows; ///< one row per item, either encoded as hex string or JSON object vector<fc::variant> rows; ///< one row per item, either encoded as hex string or JSON object
double total_producer_vote_weight;
string more; ///< fill lower_bound with this value to fetch more rows string more; ///< fill lower_bound with this value to fetch more rows
}; };
...@@ -397,7 +398,7 @@ FC_REFLECT( eosio::chain_apis::read_only::get_currency_stats_params, (code)(symb ...@@ -397,7 +398,7 @@ FC_REFLECT( eosio::chain_apis::read_only::get_currency_stats_params, (code)(symb
FC_REFLECT( eosio::chain_apis::read_only::get_currency_stats_result, (supply)(max_supply)(issuer)); FC_REFLECT( eosio::chain_apis::read_only::get_currency_stats_result, (supply)(max_supply)(issuer));
FC_REFLECT( eosio::chain_apis::read_only::get_producers_params, (json)(lower_bound)(limit) ) FC_REFLECT( eosio::chain_apis::read_only::get_producers_params, (json)(lower_bound)(limit) )
FC_REFLECT( eosio::chain_apis::read_only::get_producers_result, (rows)(more) ); FC_REFLECT( eosio::chain_apis::read_only::get_producers_result, (rows)(total_producer_vote_weight)(more) );
FC_REFLECT( eosio::chain_apis::read_only::get_account_results, (account_name)(privileged)(last_code_update)(created)(ram_quota)(net_weight)(cpu_weight)(net_limit)(cpu_limit)(ram_usage)(permissions)(total_resources)(delegated_bandwidth)(voter_info) ) FC_REFLECT( eosio::chain_apis::read_only::get_account_results, (account_name)(privileged)(last_code_update)(created)(ram_quota)(net_weight)(cpu_weight)(net_limit)(cpu_limit)(ram_usage)(permissions)(total_resources)(delegated_bandwidth)(voter_info) )
FC_REFLECT( eosio::chain_apis::read_only::get_code_results, (account_name)(code_hash)(wast)(abi) ) FC_REFLECT( eosio::chain_apis::read_only::get_code_results, (account_name)(code_hash)(wast)(abi) )
......
...@@ -1031,13 +1031,16 @@ struct list_producers_subcommand { ...@@ -1031,13 +1031,16 @@ struct list_producers_subcommand {
std::cout << "No producers found" << std::endl; std::cout << "No producers found" << std::endl;
return; return;
} }
printf("%-13s %-54s %-59s %s\n", "Producer", "Producer key", "Url", "Total votes"); auto weight = result.total_producer_vote_weight;
if ( !weight )
weight = 1;
printf("%-13s %-54s %-59s %s\n", "Producer", "Producer key", "Url", "Scaled votes");
for ( auto& row : result.rows ) for ( auto& row : result.rows )
printf("%-13.13s %-54.54s %-59.59s %040f\n", printf("%-13.13s %-54.54s %-59.59s %1.4f\n",
row["owner"].as_string().c_str(), row["owner"].as_string().c_str(),
row["producer_key"].as_string().c_str(), row["producer_key"].as_string().c_str(),
row["url"].as_string().c_str(), row["url"].as_string().c_str(),
row["total_votes"].as_double()); row["total_votes"].as_double() / weight);
if ( !result.more.empty() ) if ( !result.more.empty() )
std::cout << "-L " << result.more << " for more" << std::endl; std::cout << "-L " << result.more << " for more" << std::endl;
}); });
......
...@@ -2120,6 +2120,16 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try { ...@@ -2120,6 +2120,16 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try {
BOOST_REQUIRE_EQUAL(true, rest_didnt_produce); BOOST_REQUIRE_EQUAL(true, rest_didnt_produce);
} }
{
BOOST_CHECK_EQUAL(0, get_global_state()["total_unpaid_blocks"].as<uint32_t>());
BOOST_REQUIRE_EQUAL(error("condition: assertion failed: not enough has been staked for producers to claim rewards"),
push_action(producer_names.front(), N(claimrewards), mvo()("owner", producer_names.front())));
BOOST_REQUIRE_EQUAL(0, get_balance(producer_names.front()).amount);
BOOST_REQUIRE_EQUAL(error("condition: assertion failed: not enough has been staked for producers to claim rewards"),
push_action(producer_names.back(), N(claimrewards), mvo()("owner", producer_names.back())));
BOOST_REQUIRE_EQUAL(0, get_balance(producer_names.back()).amount);
}
// stake across 15% boundary // stake across 15% boundary
transfer(config::system_account_name, "producvoterb", "100000000.0000 EOS", config::system_account_name); transfer(config::system_account_name, "producvoterb", "100000000.0000 EOS", config::system_account_name);
BOOST_REQUIRE_EQUAL(success(), stake("producvoterb", "4000000.0000 EOS", "4000000.0000 EOS")); BOOST_REQUIRE_EQUAL(success(), stake("producvoterb", "4000000.0000 EOS", "4000000.0000 EOS"));
...@@ -2157,6 +2167,9 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try { ...@@ -2157,6 +2167,9 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try {
} }
BOOST_REQUIRE_EQUAL(true, all_21_produced); BOOST_REQUIRE_EQUAL(true, all_21_produced);
BOOST_REQUIRE_EQUAL(true, rest_didnt_produce); BOOST_REQUIRE_EQUAL(true, rest_didnt_produce);
BOOST_REQUIRE_EQUAL(success(),
push_action(producer_names.front(), N(claimrewards), mvo()("owner", producer_names.front())));
BOOST_REQUIRE(0 < get_balance(producer_names.front()).amount);
} }
} FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册