Compare commits
18 commits
master
...
feature/py
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bad6a8ac6 | ||
|
|
e3bf6b9553 | ||
|
|
75d2e19455 | ||
|
|
46e0d033fb | ||
|
|
5cf9d2900a | ||
|
|
149d2876d5 | ||
|
|
d093584016 | ||
|
|
c33a20384a | ||
|
|
ae23e37375 | ||
|
|
a874806f09 | ||
|
|
fc3b66a0a1 | ||
|
|
f6532efa74 | ||
|
|
aef6129bf3 | ||
|
|
b5a2b84558 | ||
|
|
943e02cdcd | ||
|
|
e8d74f65d3 | ||
|
|
76e8cdf750 | ||
|
|
98933a6f86 |
35 changed files with 571 additions and 814 deletions
111
.gitlab-ci.yml
111
.gitlab-ci.yml
|
|
@ -6,11 +6,10 @@ include:
|
||||||
- template: Secret-Detection.gitlab-ci.yml
|
- template: Secret-Detection.gitlab-ci.yml
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
|
- python-test
|
||||||
|
- dockerize
|
||||||
- build
|
- build
|
||||||
- test
|
- test
|
||||||
- dockerize
|
|
||||||
- python-test
|
|
||||||
- deploy
|
|
||||||
|
|
||||||
build-mainnet:
|
build-mainnet:
|
||||||
stage: build
|
stage: build
|
||||||
|
|
@ -31,6 +30,8 @@ build-mainnet:
|
||||||
- build/tests/
|
- build/tests/
|
||||||
tags:
|
tags:
|
||||||
- builder
|
- builder
|
||||||
|
when:
|
||||||
|
manual
|
||||||
|
|
||||||
test-mainnet:
|
test-mainnet:
|
||||||
stage: test
|
stage: test
|
||||||
|
|
@ -50,18 +51,63 @@ dockerize-mainnet:
|
||||||
IMAGE: $CI_REGISTRY_IMAGE/mainnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
|
IMAGE: $CI_REGISTRY_IMAGE/mainnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
|
||||||
before_script:
|
before_script:
|
||||||
- docker info
|
- docker info
|
||||||
- docker builder prune -a -f
|
|
||||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||||
|
- df -BM $pwd
|
||||||
script:
|
script:
|
||||||
|
- docker images
|
||||||
|
- docker builder prune -a -f
|
||||||
- docker build --no-cache -t $IMAGE .
|
- docker build --no-cache -t $IMAGE .
|
||||||
|
- docker images
|
||||||
- docker push $IMAGE
|
- docker push $IMAGE
|
||||||
after_script:
|
after_script:
|
||||||
- docker rmi $IMAGE
|
- docker rmi $IMAGE
|
||||||
|
- docker images
|
||||||
tags:
|
tags:
|
||||||
- builder
|
- builder
|
||||||
timeout:
|
timeout:
|
||||||
3h
|
3h
|
||||||
|
|
||||||
|
test-e2e:
|
||||||
|
stage: python-test
|
||||||
|
before_script:
|
||||||
|
- docker info
|
||||||
|
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||||
|
script:
|
||||||
|
- docker stop $(docker ps -a -q)
|
||||||
|
- docker rm $(docker ps -aq)
|
||||||
|
- git clone https://gitlab.com/PBSA/tools-libs/peerplays-utils.git
|
||||||
|
- pwd
|
||||||
|
- cd peerplays-utils/peerplays-qa-environment
|
||||||
|
- FULL_PWD=$(pwd)
|
||||||
|
- cd e2e-tests/
|
||||||
|
- python3 -m venv venv
|
||||||
|
- source venv/bin/activate
|
||||||
|
- pip3 install -r requirements.txt
|
||||||
|
- docker ps -a -q
|
||||||
|
- python3 main.py --stop
|
||||||
|
- docker ps -a -q
|
||||||
|
- python3 main.py --start btc hive eth
|
||||||
|
- docker ps -a -q
|
||||||
|
- python3 -m pytest test_btc_init_state.py test_hive_inital_state.py
|
||||||
|
- docker pull registry.gitlab.com/pbsa/peerplays/mainnet/feature-python-e2e-tests:943e02cdcd9fb8a90137851635b998cf1b4f622c
|
||||||
|
- ls -la $FULL_PWD/peerplays/config.ini
|
||||||
|
- ls -la $FULL_PWD/peerplays/genesis.json
|
||||||
|
- ls -la $FULL_PWD/peerplays/init-network.sh
|
||||||
|
- PP_CONTAINER_ID=$(docker run --name pp -d registry.gitlab.com/pbsa/peerplays/mainnet/feature-python-e2e-tests:943e02cdcd9fb8a90137851635b998cf1b4f622c tail -f /dev/null)
|
||||||
|
- docker cp $FULL_PWD/e2e-tests/peerplays-utils/peerplays-qa-environment/peerplays/config.ini $PP_CONTAINER_ID:/home/peerplays/peerplays-network/witness_node_data_dir/config.ini
|
||||||
|
- docker cp $FULL_PWD/e2e-tests/peerplays-utils/peerplays-qa-environment/peerplays/genensis.json $PP_CONTAINER_ID:/home/peerplays/peerplays-network/witness_node_data_dir/genensis.json
|
||||||
|
- docker cp $FULL_PWD/e2e-tests/peerplays-utils/peerplays-qa-environment/peerplays/init-network.sh $PP_CONTAINER_ID:/home/peerplays/peerplays-network/init-network.sh
|
||||||
|
- docker exec -c pp ./init-network.sh
|
||||||
|
- docker ps -a -q
|
||||||
|
- docker exec pp sh -c ./witness_node -d ./witness_node_data_dir --replay-blockchain
|
||||||
|
- docker exec pp sh -c ./init-network.sh
|
||||||
|
- python3 -m pytest test_pp_inital_state.py
|
||||||
|
- ./main.py --stop
|
||||||
|
- deactivate
|
||||||
|
- docker ps -a -q
|
||||||
|
tags:
|
||||||
|
- python-tests
|
||||||
|
|
||||||
build-testnet:
|
build-testnet:
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
|
|
@ -79,27 +125,12 @@ build-testnet:
|
||||||
- build/libraries/
|
- build/libraries/
|
||||||
- build/programs/
|
- build/programs/
|
||||||
- build/tests/
|
- build/tests/
|
||||||
when: manual
|
|
||||||
tags:
|
tags:
|
||||||
- builder
|
- builder
|
||||||
|
when:
|
||||||
deploy-testnet:
|
manual
|
||||||
stage: deploy
|
timeout:
|
||||||
dependencies:
|
3h
|
||||||
- build-testnet
|
|
||||||
script:
|
|
||||||
- sudo systemctl stop witness
|
|
||||||
- rm $WORK_DIR/peerplays/witness_node || true
|
|
||||||
- cp build/programs/witness_node/witness_node $WORK_DIR/peerplays/
|
|
||||||
- sudo systemctl restart witness
|
|
||||||
rules:
|
|
||||||
- if: $CI_COMMIT_BRANCH == "master"
|
|
||||||
when: always
|
|
||||||
environment:
|
|
||||||
name: devnet
|
|
||||||
url: $DEVNET_URL
|
|
||||||
tags:
|
|
||||||
- devnet
|
|
||||||
|
|
||||||
test-testnet:
|
test-testnet:
|
||||||
stage: test
|
stage: test
|
||||||
|
|
@ -135,37 +166,3 @@ dockerize-testnet:
|
||||||
manual
|
manual
|
||||||
timeout:
|
timeout:
|
||||||
3h
|
3h
|
||||||
|
|
||||||
test-e2e:
|
|
||||||
stage: python-test
|
|
||||||
variables:
|
|
||||||
IMAGE: $CI_REGISTRY_IMAGE/mainnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
|
|
||||||
before_script:
|
|
||||||
- docker info
|
|
||||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
|
||||||
script:
|
|
||||||
- git clone https://gitlab.com/PBSA/tools-libs/peerplays-utils.git
|
|
||||||
- cd peerplays-utils/peerplays-qa-environment
|
|
||||||
- git checkout origin/feature/python-e2e-tests-for-CI
|
|
||||||
- cd e2e-tests/
|
|
||||||
- python3 -m venv venv
|
|
||||||
- source venv/bin/activate
|
|
||||||
- pip3 install -r requirements.txt
|
|
||||||
- docker-compose down --remove-orphans
|
|
||||||
- docker ps -a
|
|
||||||
- docker pull $IMAGE
|
|
||||||
- docker tag $IMAGE peerplays-base:latest
|
|
||||||
- docker image ls -a
|
|
||||||
- docker-compose build
|
|
||||||
- python3 main.py --start all
|
|
||||||
- docker ps -a
|
|
||||||
- python3 -m pytest test_btc_init_state.py test_hive_inital_state.py test_pp_inital_state.py
|
|
||||||
- python3 main.py --stop
|
|
||||||
- deactivate
|
|
||||||
- docker ps -a
|
|
||||||
after_script:
|
|
||||||
- docker rmi $(docker images -a | grep -v 'hive-for-peerplays\|ethereum-for-peerplays\|bitcoin-for-peerplays\|ubuntu-for-peerplays' | awk '{print $3}')
|
|
||||||
tags:
|
|
||||||
- python-tests
|
|
||||||
when:
|
|
||||||
manual
|
|
||||||
|
|
|
||||||
24
Dockerfile
24
Dockerfile
|
|
@ -50,8 +50,14 @@ RUN echo 'peerplays:peerplays' | chpasswd
|
||||||
# SSH
|
# SSH
|
||||||
EXPOSE 22
|
EXPOSE 22
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
df -h -BM $pwd
|
||||||
|
|
||||||
WORKDIR /home/peerplays/src
|
WORKDIR /home/peerplays/src
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
df -h -BM $pwd
|
||||||
|
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
# Boost setup
|
# Boost setup
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
@ -134,8 +140,14 @@ RUN \
|
||||||
libsodium-dev
|
libsodium-dev
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
git clone --branch version3.8.0 --depth 1 https://gitlab.com/PBSA/peerplays-1.0/libbitcoin-explorer.git && \
|
df -h -BM $pwd
|
||||||
cd libbitcoin-explorer && \
|
|
||||||
|
RUN \
|
||||||
|
git clone https://github.com/libbitcoin/libbitcoin-build.git && \
|
||||||
|
cd libbitcoin-build && \
|
||||||
|
git reset --hard 92c215fc1ffa272bab4d485d369d0306db52d69d && \
|
||||||
|
./generate3.sh && \
|
||||||
|
cd ../libbitcoin-explorer && \
|
||||||
./install.sh && \
|
./install.sh && \
|
||||||
ldconfig && \
|
ldconfig && \
|
||||||
rm -rf /home/peerplays/src/*
|
rm -rf /home/peerplays/src/*
|
||||||
|
|
@ -187,10 +199,9 @@ ADD . peerplays
|
||||||
RUN \
|
RUN \
|
||||||
cd peerplays && \
|
cd peerplays && \
|
||||||
git submodule update --init --recursive && \
|
git submodule update --init --recursive && \
|
||||||
git log --oneline -n 5 && \
|
|
||||||
mkdir build && \
|
mkdir build && \
|
||||||
cd build && \
|
cd build && \
|
||||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_PEERPLAYS_TESTNET=1 ..
|
||||||
|
|
||||||
# Build Peerplays
|
# Build Peerplays
|
||||||
RUN \
|
RUN \
|
||||||
|
|
@ -204,9 +215,6 @@ RUN \
|
||||||
ln -s /home/peerplays/src/peerplays/build/programs/cli_wallet/cli_wallet ./ && \
|
ln -s /home/peerplays/src/peerplays/build/programs/cli_wallet/cli_wallet ./ && \
|
||||||
ln -s /home/peerplays/src/peerplays/build/programs/witness_node/witness_node ./
|
ln -s /home/peerplays/src/peerplays/build/programs/witness_node/witness_node ./
|
||||||
|
|
||||||
RUN ./witness_node --create-genesis-json genesis.json && \
|
|
||||||
rm genesis.json
|
|
||||||
|
|
||||||
RUN chown peerplays:root -R /home/peerplays/peerplays-network
|
RUN chown peerplays:root -R /home/peerplays/peerplays-network
|
||||||
|
|
||||||
# Peerplays RPC
|
# Peerplays RPC
|
||||||
|
|
@ -214,5 +222,3 @@ EXPOSE 8090
|
||||||
# Peerplays P2P:
|
# Peerplays P2P:
|
||||||
EXPOSE 9777
|
EXPOSE 9777
|
||||||
|
|
||||||
# Peerplays
|
|
||||||
CMD ["./witness_node", "-d", "./witness_node_data_dir"]
|
|
||||||
|
|
|
||||||
|
|
@ -134,8 +134,11 @@ RUN \
|
||||||
libsodium-dev
|
libsodium-dev
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
git clone --branch version3.8.0 --depth 1 https://gitlab.com/PBSA/peerplays-1.0/libbitcoin-explorer.git && \
|
git clone https://github.com/libbitcoin/libbitcoin-build.git && \
|
||||||
cd libbitcoin-explorer && \
|
cd libbitcoin-build && \
|
||||||
|
git reset --hard 92c215fc1ffa272bab4d485d369d0306db52d69d && \
|
||||||
|
./generate3.sh && \
|
||||||
|
cd ../libbitcoin-explorer && \
|
||||||
./install.sh && \
|
./install.sh && \
|
||||||
ldconfig && \
|
ldconfig && \
|
||||||
rm -rf /home/peerplays/src/*
|
rm -rf /home/peerplays/src/*
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,11 @@ sudo ldconfig
|
||||||
|
|
||||||
libbitcoin-explorer setup:
|
libbitcoin-explorer setup:
|
||||||
```
|
```
|
||||||
git clone --branch version3.8.0 --depth 1 https://gitlab.com/PBSA/peerplays-1.0/libbitcoin-explorer.git
|
git clone https://github.com/libbitcoin/libbitcoin-build.git
|
||||||
cd libbitcoin-explorer
|
cd libbitcoin-build
|
||||||
|
git reset --hard 92c215fc1ffa272bab4d485d369d0306db52d69d
|
||||||
|
./generate3.sh
|
||||||
|
cd ../libbitcoin-explorer
|
||||||
sudo ./install.sh
|
sudo ./install.sh
|
||||||
sudo ldconfig
|
sudo ldconfig
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -2197,7 +2197,7 @@ vector<variant> database_api_impl::lookup_vote_ids(const vector<vote_id_type> &v
|
||||||
case vote_id_type::committee: {
|
case vote_id_type::committee: {
|
||||||
auto itr = committee_idx.find(id);
|
auto itr = committee_idx.find(id);
|
||||||
if (itr != committee_idx.end())
|
if (itr != committee_idx.end())
|
||||||
result.emplace_back(variant(*itr, 2)); // Depth of committee_member_object is 1, add 1 to be safe
|
result.emplace_back(variant(*itr, 1));
|
||||||
else
|
else
|
||||||
result.emplace_back(variant());
|
result.emplace_back(variant());
|
||||||
break;
|
break;
|
||||||
|
|
@ -2205,7 +2205,7 @@ vector<variant> database_api_impl::lookup_vote_ids(const vector<vote_id_type> &v
|
||||||
case vote_id_type::witness: {
|
case vote_id_type::witness: {
|
||||||
auto itr = witness_idx.find(id);
|
auto itr = witness_idx.find(id);
|
||||||
if (itr != witness_idx.end())
|
if (itr != witness_idx.end())
|
||||||
result.emplace_back(variant(*itr, 2)); // Depth of witness_object is 1, add 1 here to be safe
|
result.emplace_back(variant(*itr, 1));
|
||||||
else
|
else
|
||||||
result.emplace_back(variant());
|
result.emplace_back(variant());
|
||||||
break;
|
break;
|
||||||
|
|
@ -2213,15 +2213,11 @@ vector<variant> database_api_impl::lookup_vote_ids(const vector<vote_id_type> &v
|
||||||
case vote_id_type::worker: {
|
case vote_id_type::worker: {
|
||||||
auto itr = for_worker_idx.find(id);
|
auto itr = for_worker_idx.find(id);
|
||||||
if (itr != for_worker_idx.end()) {
|
if (itr != for_worker_idx.end()) {
|
||||||
result.emplace_back(variant(*itr, 4)); // Depth of worker_object is 3, add 1 here to be safe.
|
result.emplace_back(variant(*itr, 1));
|
||||||
// If we want to extract the balance object inside,
|
|
||||||
// need to increase this value
|
|
||||||
} else {
|
} else {
|
||||||
auto itr = against_worker_idx.find(id);
|
auto itr = against_worker_idx.find(id);
|
||||||
if (itr != against_worker_idx.end()) {
|
if (itr != against_worker_idx.end()) {
|
||||||
result.emplace_back(variant(*itr, 4)); // Depth of worker_object is 3, add 1 here to be safe.
|
result.emplace_back(variant(*itr, 1));
|
||||||
// If we want to extract the balance object inside,
|
|
||||||
// need to increase this value
|
|
||||||
} else {
|
} else {
|
||||||
result.emplace_back(variant());
|
result.emplace_back(variant());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,163 +33,45 @@ namespace graphene { namespace chain {
|
||||||
|
|
||||||
void_result transfer_to_blind_evaluator::do_evaluate( const transfer_to_blind_operation& o )
|
void_result transfer_to_blind_evaluator::do_evaluate( const transfer_to_blind_operation& o )
|
||||||
{ try {
|
{ try {
|
||||||
const auto& d = db();
|
|
||||||
if( d.head_block_time() < HARDFORK_SON_FOR_ETHEREUM_TIME )
|
|
||||||
{
|
|
||||||
const auto& atype = o.amount.asset_id(d);
|
|
||||||
FC_ASSERT( atype.allow_confidential() );
|
|
||||||
FC_ASSERT( !atype.is_transfer_restricted() );
|
|
||||||
FC_ASSERT( !(atype.options.flags & white_list) );
|
|
||||||
|
|
||||||
for( const auto& out : o.outputs )
|
|
||||||
{
|
|
||||||
for( const auto& a : out.owner.account_auths )
|
|
||||||
a.first(d); // verify all accounts exist and are valid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return void_result();
|
return void_result();
|
||||||
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
||||||
|
|
||||||
|
|
||||||
void_result transfer_to_blind_evaluator::do_apply( const transfer_to_blind_operation& o )
|
void_result transfer_to_blind_evaluator::do_apply( const transfer_to_blind_operation& o )
|
||||||
{ try {
|
{ try {
|
||||||
if( db().head_block_time() < HARDFORK_SON_FOR_ETHEREUM_TIME ) {
|
|
||||||
db().adjust_balance(o.from, -o.amount);
|
|
||||||
|
|
||||||
const auto &add = o.amount.asset_id(db()).dynamic_asset_data_id(db()); // verify fee is a legit asset
|
|
||||||
db().modify(add, [&](asset_dynamic_data_object &obj) {
|
|
||||||
obj.confidential_supply += o.amount.amount;
|
|
||||||
FC_ASSERT(obj.confidential_supply >= 0);
|
|
||||||
});
|
|
||||||
for (const auto &out : o.outputs) {
|
|
||||||
db().create<blinded_balance_object>([&](blinded_balance_object &obj) {
|
|
||||||
obj.asset_id = o.amount.asset_id;
|
|
||||||
obj.owner = out.owner;
|
|
||||||
obj.commitment = out.commitment;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return void_result();
|
return void_result();
|
||||||
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
||||||
|
|
||||||
void transfer_to_blind_evaluator::pay_fee()
|
void transfer_to_blind_evaluator::pay_fee()
|
||||||
{
|
{
|
||||||
const auto& d = db();
|
|
||||||
if( d.head_block_time() < HARDFORK_SON_FOR_ETHEREUM_TIME ) {
|
|
||||||
if (d.head_block_time() >= HARDFORK_563_TIME)
|
|
||||||
pay_fba_fee(fba_accumulator_id_transfer_to_blind);
|
|
||||||
else
|
|
||||||
generic_evaluator::pay_fee();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void_result transfer_from_blind_evaluator::do_evaluate( const transfer_from_blind_operation& o )
|
void_result transfer_from_blind_evaluator::do_evaluate( const transfer_from_blind_operation& o )
|
||||||
{ try {
|
{ try {
|
||||||
const auto& d = db();
|
|
||||||
if( d.head_block_time() < HARDFORK_SON_FOR_ETHEREUM_TIME ) {
|
|
||||||
o.fee.asset_id(d); // verify fee is a legit asset
|
|
||||||
const auto &bbi = d.get_index_type<blinded_balance_index>();
|
|
||||||
const auto &cidx = bbi.indices().get<by_commitment>();
|
|
||||||
for (const auto &in : o.inputs) {
|
|
||||||
auto itr = cidx.find(in.commitment);
|
|
||||||
FC_ASSERT(itr != cidx.end());
|
|
||||||
FC_ASSERT(itr->asset_id == o.fee.asset_id);
|
|
||||||
FC_ASSERT(itr->owner == in.owner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return void_result();
|
return void_result();
|
||||||
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
||||||
|
|
||||||
void_result transfer_from_blind_evaluator::do_apply( const transfer_from_blind_operation& o )
|
void_result transfer_from_blind_evaluator::do_apply( const transfer_from_blind_operation& o )
|
||||||
{ try {
|
{ try {
|
||||||
if( db().head_block_time() < HARDFORK_SON_FOR_ETHEREUM_TIME ) {
|
|
||||||
db().adjust_balance(o.fee_payer(), o.fee);
|
|
||||||
db().adjust_balance(o.to, o.amount);
|
|
||||||
const auto &bbi = db().get_index_type<blinded_balance_index>();
|
|
||||||
const auto &cidx = bbi.indices().get<by_commitment>();
|
|
||||||
for (const auto &in : o.inputs) {
|
|
||||||
auto itr = cidx.find(in.commitment);
|
|
||||||
FC_ASSERT(itr != cidx.end());
|
|
||||||
db().remove(*itr);
|
|
||||||
}
|
|
||||||
const auto &add = o.amount.asset_id(db()).dynamic_asset_data_id(db()); // verify fee is a legit asset
|
|
||||||
db().modify(add, [&](asset_dynamic_data_object &obj) {
|
|
||||||
obj.confidential_supply -= o.amount.amount + o.fee.amount;
|
|
||||||
FC_ASSERT(obj.confidential_supply >= 0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return void_result();
|
return void_result();
|
||||||
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
||||||
|
|
||||||
void transfer_from_blind_evaluator::pay_fee()
|
void transfer_from_blind_evaluator::pay_fee()
|
||||||
{
|
{
|
||||||
const auto& d = db();
|
|
||||||
if( d.head_block_time() < HARDFORK_SON_FOR_ETHEREUM_TIME ) {
|
|
||||||
if (d.head_block_time() >= HARDFORK_563_TIME)
|
|
||||||
pay_fba_fee(fba_accumulator_id_transfer_from_blind);
|
|
||||||
else
|
|
||||||
generic_evaluator::pay_fee();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void_result blind_transfer_evaluator::do_evaluate( const blind_transfer_operation& o )
|
void_result blind_transfer_evaluator::do_evaluate( const blind_transfer_operation& o )
|
||||||
{ try {
|
{ try {
|
||||||
const auto& d = db();
|
|
||||||
if( d.head_block_time() < HARDFORK_SON_FOR_ETHEREUM_TIME ) {
|
|
||||||
o.fee.asset_id(d); // verify fee is a legit asset
|
|
||||||
const auto &bbi = d.get_index_type<blinded_balance_index>();
|
|
||||||
const auto &cidx = bbi.indices().get<by_commitment>();
|
|
||||||
for (const auto &out : o.outputs) {
|
|
||||||
for (const auto &a : out.owner.account_auths)
|
|
||||||
a.first(d); // verify all accounts exist and are valid
|
|
||||||
}
|
|
||||||
for (const auto &in : o.inputs) {
|
|
||||||
auto itr = cidx.find(in.commitment);
|
|
||||||
GRAPHENE_ASSERT(itr != cidx.end(), blind_transfer_unknown_commitment, "", ("commitment", in.commitment));
|
|
||||||
FC_ASSERT(itr->asset_id == o.fee.asset_id);
|
|
||||||
FC_ASSERT(itr->owner == in.owner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return void_result();
|
return void_result();
|
||||||
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
||||||
|
|
||||||
void_result blind_transfer_evaluator::do_apply( const blind_transfer_operation& o )
|
void_result blind_transfer_evaluator::do_apply( const blind_transfer_operation& o )
|
||||||
{ try {
|
{ try {
|
||||||
if( db().head_block_time() < HARDFORK_SON_FOR_ETHEREUM_TIME ) {
|
|
||||||
db().adjust_balance(o.fee_payer(), o.fee); // deposit the fee to the temp account
|
|
||||||
const auto &bbi = db().get_index_type<blinded_balance_index>();
|
|
||||||
const auto &cidx = bbi.indices().get<by_commitment>();
|
|
||||||
for (const auto &in : o.inputs) {
|
|
||||||
auto itr = cidx.find(in.commitment);
|
|
||||||
GRAPHENE_ASSERT(itr != cidx.end(), blind_transfer_unknown_commitment, "", ("commitment", in.commitment));
|
|
||||||
db().remove(*itr);
|
|
||||||
}
|
|
||||||
for (const auto &out : o.outputs) {
|
|
||||||
db().create<blinded_balance_object>([&](blinded_balance_object &obj) {
|
|
||||||
obj.asset_id = o.fee.asset_id;
|
|
||||||
obj.owner = out.owner;
|
|
||||||
obj.commitment = out.commitment;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const auto &add = o.fee.asset_id(db()).dynamic_asset_data_id(db());
|
|
||||||
db().modify(add, [&](asset_dynamic_data_object &obj) {
|
|
||||||
obj.confidential_supply -= o.fee.amount;
|
|
||||||
FC_ASSERT(obj.confidential_supply >= 0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return void_result();
|
return void_result();
|
||||||
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
||||||
|
|
||||||
void blind_transfer_evaluator::pay_fee()
|
void blind_transfer_evaluator::pay_fee()
|
||||||
{
|
{
|
||||||
const auto& d = db();
|
|
||||||
if( d.head_block_time() < HARDFORK_SON_FOR_ETHEREUM_TIME ) {
|
|
||||||
if (d.head_block_time() >= HARDFORK_563_TIME)
|
|
||||||
pay_fba_fee(fba_accumulator_id_blind_transfer);
|
|
||||||
else
|
|
||||||
generic_evaluator::pay_fee();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
|
||||||
|
|
@ -739,11 +739,13 @@ void database::_apply_block( const signed_block& next_block )
|
||||||
|
|
||||||
if (global_props.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SCHEDULED_ALGORITHM) {
|
if (global_props.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SCHEDULED_ALGORITHM) {
|
||||||
update_witness_schedule(next_block);
|
update_witness_schedule(next_block);
|
||||||
|
bool need_to_update_son_schedule = false;
|
||||||
for(const auto& active_sons : global_props.active_sons){
|
for(const auto& active_sons : global_props.active_sons){
|
||||||
if(!active_sons.second.empty()) {
|
if(!active_sons.second.empty())
|
||||||
update_son_schedule(active_sons.first, next_block);
|
need_to_update_son_schedule = true;
|
||||||
}
|
}
|
||||||
|
if(need_to_update_son_schedule) {
|
||||||
|
update_son_schedule(next_block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -781,11 +783,15 @@ void database::_apply_block( const signed_block& next_block )
|
||||||
if (global_props.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SHUFFLED_ALGORITHM) {
|
if (global_props.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SHUFFLED_ALGORITHM) {
|
||||||
update_witness_schedule();
|
update_witness_schedule();
|
||||||
|
|
||||||
|
bool need_update_son_schedule = false;
|
||||||
for(const auto& active_sidechain_type : active_sidechain_types(dynamic_global_props.time)) {
|
for(const auto& active_sidechain_type : active_sidechain_types(dynamic_global_props.time)) {
|
||||||
if(global_props.active_sons.at(active_sidechain_type).size() > 0) {
|
if(global_props.active_sons.at(active_sidechain_type).size() > 0) {
|
||||||
update_son_schedule(active_sidechain_type);
|
need_update_son_schedule = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(need_update_son_schedule) {
|
||||||
|
update_son_schedule();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !_node_property_object.debug_updates.empty() )
|
if( !_node_property_object.debug_updates.empty() )
|
||||||
|
|
|
||||||
|
|
@ -305,14 +305,16 @@ bool database::is_son_dereg_valid( son_id_type son_id )
|
||||||
}
|
}
|
||||||
|
|
||||||
bool status_son_dereg_valid = true;
|
bool status_son_dereg_valid = true;
|
||||||
for (const auto &active_sidechain_type : active_sidechain_types(head_block_time())) {
|
for(const auto& status : son->statuses)
|
||||||
if(son->statuses.at(active_sidechain_type) != son_status::in_maintenance)
|
{
|
||||||
|
const auto& sidechain = status.first;
|
||||||
|
if(status.second != son_status::in_maintenance)
|
||||||
status_son_dereg_valid = false;
|
status_son_dereg_valid = false;
|
||||||
|
|
||||||
if(status_son_dereg_valid)
|
if(status_son_dereg_valid)
|
||||||
{
|
{
|
||||||
if(son->statistics(*this).last_active_timestamp.contains(active_sidechain_type)) {
|
if(son->statistics(*this).last_active_timestamp.contains(sidechain)) {
|
||||||
if (head_block_time() - son->statistics(*this).last_active_timestamp.at(active_sidechain_type) < fc::seconds(get_global_properties().parameters.son_deregister_time())) {
|
if (head_block_time() - son->statistics(*this).last_active_timestamp.at(sidechain) < fc::seconds(get_global_properties().parameters.son_deregister_time())) {
|
||||||
status_son_dereg_valid = false;
|
status_son_dereg_valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -386,14 +388,23 @@ vector<uint64_t> database::get_random_numbers(uint64_t minimum, uint64_t maximum
|
||||||
|
|
||||||
bool database::is_asset_creation_allowed(const string &symbol)
|
bool database::is_asset_creation_allowed(const string &symbol)
|
||||||
{
|
{
|
||||||
|
time_point_sec now = head_block_time();
|
||||||
|
std::unordered_set<std::string> post_son_hf_symbols = {"ETH", "USDT", "BNB", "ADA", "DOGE", "XRP", "USDC", "DOT", "UNI", "BUSD", "BCH", "LTC", "SOL", "LINK", "MATIC", "THETA",
|
||||||
|
"WBTC", "XLM", "ICP", "DAI", "VET", "ETC", "TRX", "FIL", "XMR", "EGR", "EOS", "SHIB", "AAVE", "CRO", "ALGO", "AMP", "BTCB",
|
||||||
|
"BSV", "KLAY", "CAKE", "FTT", "LEO", "XTZ", "TFUEL", "MIOTA", "LUNA", "NEO", "ATOM", "MKR", "FEI", "WBNB", "UST", "AVAX",
|
||||||
|
"STEEM", "HIVE", "HBD", "SBD", "BTS"};
|
||||||
if (symbol == "BTC")
|
if (symbol == "BTC")
|
||||||
{
|
{
|
||||||
if (head_block_time() < HARDFORK_SON_TIME)
|
if (now < HARDFORK_SON_TIME)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (post_son_hf_symbols.find(symbol) != post_son_hf_symbols.end())
|
||||||
|
{
|
||||||
|
if (now >= HARDFORK_SON_TIME)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} }
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,6 @@ struct worker_pay_visitor
|
||||||
worker.pay_worker(pay, db);
|
worker.pay_worker(pay, db);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void database::update_worker_votes()
|
void database::update_worker_votes()
|
||||||
{
|
{
|
||||||
auto& idx = get_index_type<worker_index>();
|
auto& idx = get_index_type<worker_index>();
|
||||||
|
|
@ -186,131 +185,13 @@ void database::update_worker_votes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::hotfix_2024()
|
void database::pay_sons()
|
||||||
{
|
|
||||||
if (head_block_time() >= HARDFORK_HOTFIX_2024_TIME)
|
|
||||||
{
|
|
||||||
if (get_chain_id().str() == "6b6b5f0ce7a36d323768e534f3edb41c6d6332a541a95725b98e28d140850134")
|
|
||||||
{
|
|
||||||
const auto& vb_idx = get_index_type<vesting_balance_index>().indices().get<by_id>();
|
|
||||||
auto vbo = vb_idx.find(vesting_balance_id_type(388));
|
|
||||||
if (vbo != vb_idx.end())
|
|
||||||
{
|
|
||||||
if (vbo->owner == account_id_type(14786))
|
|
||||||
{
|
|
||||||
modify(*vbo, [&]( vesting_balance_object& _vbo)
|
|
||||||
{
|
|
||||||
_vbo.owner = account_id_type(0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void database::pay_sons_before_hf_ethereum()
|
|
||||||
{
|
|
||||||
const auto now = head_block_time();
|
|
||||||
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
|
|
||||||
// Current requirement is that we have to pay every 24 hours, so the following check
|
|
||||||
if( dpo.son_budget.value > 0 && ((now - dpo.last_son_payout_time) >= fc::seconds(get_global_properties().parameters.son_pay_time())))
|
|
||||||
{
|
|
||||||
const sidechain_type st = sidechain_type::bitcoin;
|
|
||||||
const auto sons = sort_votable_objects<son_index>(st, get_global_properties().parameters.maximum_son_count());
|
|
||||||
|
|
||||||
// After SON2 HF
|
|
||||||
uint64_t total_votes = 0;
|
|
||||||
for( const son_object& son : sons )
|
|
||||||
{
|
|
||||||
FC_ASSERT(son.get_sidechain_vote_id(st).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", st)("son", son));
|
|
||||||
total_votes += _vote_tally_buffer[*son.get_sidechain_vote_id(st)];
|
|
||||||
}
|
|
||||||
const int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0);
|
|
||||||
auto get_weight = [&bits_to_drop]( uint64_t son_votes ) {
|
|
||||||
const uint16_t weight = std::max((son_votes >> bits_to_drop), uint64_t(1) );
|
|
||||||
return weight;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Before SON2 HF
|
|
||||||
auto get_weight_before_son2_hf = []( uint64_t son_votes ) {
|
|
||||||
const int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(son_votes)) - 15, 0);
|
|
||||||
const uint16_t weight = std::max((son_votes >> bits_to_drop), uint64_t(1) );
|
|
||||||
return weight;
|
|
||||||
};
|
|
||||||
|
|
||||||
uint64_t weighted_total_txs_signed = 0;
|
|
||||||
const share_type son_budget = dpo.son_budget;
|
|
||||||
get_index_type<son_stats_index>().inspect_all_objects([this, &weighted_total_txs_signed, &get_weight, &now, &get_weight_before_son2_hf, &st](const object& o) {
|
|
||||||
const son_statistics_object& s = static_cast<const son_statistics_object&>(o);
|
|
||||||
const auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
|
||||||
const auto son_obj = idx.find( s.owner );
|
|
||||||
uint16_t son_weight = 0;
|
|
||||||
FC_ASSERT(son_obj->get_sidechain_vote_id(st).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", st)("son", *son_obj));
|
|
||||||
if( now >= HARDFORK_SON2_TIME ) {
|
|
||||||
son_weight += get_weight(_vote_tally_buffer[*son_obj->get_sidechain_vote_id(st)]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
son_weight += get_weight_before_son2_hf(_vote_tally_buffer[*son_obj->get_sidechain_vote_id(st)]);
|
|
||||||
}
|
|
||||||
const uint64_t txs_signed_bitcoin = s.txs_signed.contains(sidechain_type::bitcoin) ? s.txs_signed.at(sidechain_type::bitcoin) : 0;
|
|
||||||
const uint64_t txs_signed_hive = s.txs_signed.contains(sidechain_type::hive) ? s.txs_signed.at(sidechain_type::hive) : 0;
|
|
||||||
weighted_total_txs_signed += ((txs_signed_bitcoin + txs_signed_hive) * son_weight);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Now pay off each SON proportional to the number of transactions signed.
|
|
||||||
get_index_type<son_stats_index>().inspect_all_objects([this, &weighted_total_txs_signed, &dpo, &son_budget, &get_weight, &get_weight_before_son2_hf, &now, &st](const object& o) {
|
|
||||||
const son_statistics_object& s = static_cast<const son_statistics_object&>(o);
|
|
||||||
const uint64_t txs_signed_bitcoin = s.txs_signed.contains(sidechain_type::bitcoin) ? s.txs_signed.at(sidechain_type::bitcoin) : 0;
|
|
||||||
const uint64_t txs_signed_hive = s.txs_signed.contains(sidechain_type::hive) ? s.txs_signed.at(sidechain_type::hive) : 0;
|
|
||||||
|
|
||||||
if(txs_signed_bitcoin > 0 || txs_signed_hive > 0) {
|
|
||||||
const auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
|
||||||
auto son_obj = idx.find( s.owner );
|
|
||||||
uint16_t son_weight = 0;
|
|
||||||
FC_ASSERT(son_obj->get_sidechain_vote_id(st).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", st)("son", *son_obj));
|
|
||||||
if( now >= HARDFORK_SON2_TIME ) {
|
|
||||||
son_weight += get_weight(_vote_tally_buffer[*son_obj->get_sidechain_vote_id(st)]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
son_weight += get_weight_before_son2_hf(_vote_tally_buffer[*son_obj->get_sidechain_vote_id(st)]);
|
|
||||||
}
|
|
||||||
const share_type pay = ((txs_signed_bitcoin + txs_signed_hive) * son_weight * son_budget.value)/weighted_total_txs_signed;
|
|
||||||
modify( *son_obj, [&]( son_object& _son_obj)
|
|
||||||
{
|
|
||||||
_son_obj.pay_son_fee(pay, *this);
|
|
||||||
});
|
|
||||||
//Remove the amount paid out to SON from global SON Budget
|
|
||||||
modify( dpo, [&]( dynamic_global_property_object& _dpo )
|
|
||||||
{
|
|
||||||
_dpo.son_budget -= pay;
|
|
||||||
} );
|
|
||||||
//Reset the tx counter in each son statistics object
|
|
||||||
modify( s, [&]( son_statistics_object& _s)
|
|
||||||
{
|
|
||||||
if(_s.txs_signed.contains(sidechain_type::bitcoin))
|
|
||||||
_s.txs_signed.at(sidechain_type::bitcoin) = 0;
|
|
||||||
if(_s.txs_signed.contains(sidechain_type::hive))
|
|
||||||
_s.txs_signed.at(sidechain_type::hive) = 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Note the last son pay out time
|
|
||||||
modify( dpo, [&]( dynamic_global_property_object& _dpo )
|
|
||||||
{
|
|
||||||
_dpo.last_son_payout_time = now;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void database::pay_sons_after_hf_ethereum()
|
|
||||||
{
|
{
|
||||||
const time_point_sec now = head_block_time();
|
const time_point_sec now = head_block_time();
|
||||||
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
|
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
|
||||||
// Current requirement is that we have to pay every 24 hours, so the following check
|
// Current requirement is that we have to pay every 24 hours, so the following check
|
||||||
if( dpo.son_budget.value > 0 && ((now - dpo.last_son_payout_time) >= fc::seconds(get_global_properties().parameters.son_pay_time())))
|
if( dpo.son_budget.value > 0 && ((now - dpo.last_son_payout_time) >= fc::seconds(get_global_properties().parameters.son_pay_time())))
|
||||||
{
|
{
|
||||||
flat_map<sidechain_type, int8_t> bits_to_drop;
|
|
||||||
for(const auto& active_sidechain_type : active_sidechain_types(now))
|
for(const auto& active_sidechain_type : active_sidechain_types(now))
|
||||||
{
|
{
|
||||||
assert( _son_count_histogram_buffer.at(active_sidechain_type).size() > 0 );
|
assert( _son_count_histogram_buffer.at(active_sidechain_type).size() > 0 );
|
||||||
|
|
@ -328,67 +209,87 @@ void database::pay_sons_after_hf_ethereum()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto sons = sort_votable_objects<son_index>(active_sidechain_type, (std::max(son_count*2+1, (size_t)get_chain_properties().immutable_parameters.min_son_count)));
|
const sidechain_type st = [&now, &active_sidechain_type]{
|
||||||
|
if( now < HARDFORK_SON_FOR_ETHEREUM_TIME )
|
||||||
|
return sidechain_type::bitcoin;
|
||||||
|
else
|
||||||
|
return active_sidechain_type;
|
||||||
|
}();
|
||||||
|
|
||||||
|
const auto sons = sort_votable_objects<son_index>(st,
|
||||||
|
(std::max(son_count*2+1, (size_t)get_chain_properties().immutable_parameters.min_son_count))
|
||||||
|
);
|
||||||
|
|
||||||
// After SON2 HF
|
// After SON2 HF
|
||||||
uint64_t total_votes = 0;
|
uint64_t total_votes = 0;
|
||||||
for( const son_object& son : sons )
|
for( const son_object& son : sons )
|
||||||
{
|
{
|
||||||
FC_ASSERT(son.get_sidechain_vote_id(active_sidechain_type).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", active_sidechain_type)("son", son));
|
FC_ASSERT(son.get_sidechain_vote_id(st).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", st)("son", son));
|
||||||
total_votes += _vote_tally_buffer[*son.get_sidechain_vote_id(active_sidechain_type)];
|
total_votes += _vote_tally_buffer[*son.get_sidechain_vote_id(st)];
|
||||||
}
|
}
|
||||||
bits_to_drop[active_sidechain_type] = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0);
|
const int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0);
|
||||||
}
|
auto get_weight = [&bits_to_drop]( uint64_t son_votes ) {
|
||||||
|
const uint16_t weight = std::max((son_votes >> bits_to_drop), uint64_t(1) );
|
||||||
auto get_weight = [&bits_to_drop]( sidechain_type sidechain, uint64_t son_votes ) {
|
return weight;
|
||||||
const uint16_t weight = std::max((son_votes >> bits_to_drop.at(sidechain)), uint64_t(1) );
|
};
|
||||||
|
// Before SON2 HF
|
||||||
|
auto get_weight_before_son2_hf = []( uint64_t son_votes ) {
|
||||||
|
const int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(son_votes)) - 15, 0);
|
||||||
|
const uint16_t weight = std::max((son_votes >> bits_to_drop), uint64_t(1) );
|
||||||
return weight;
|
return weight;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate weighted_total_txs_signed
|
|
||||||
uint64_t weighted_total_txs_signed = 0;
|
uint64_t weighted_total_txs_signed = 0;
|
||||||
get_index_type<son_stats_index>().inspect_all_objects([this, &weighted_total_txs_signed, &get_weight, &now](const object& o) {
|
const share_type son_budget = dpo.son_budget;
|
||||||
for(const auto& active_sidechain_type : active_sidechain_types(now)) {
|
get_index_type<son_stats_index>().inspect_all_objects([this, &weighted_total_txs_signed, &get_weight, &now, &get_weight_before_son2_hf, &active_sidechain_type, &st](const object& o) {
|
||||||
const son_statistics_object& s = static_cast<const son_statistics_object&>(o);
|
const son_statistics_object& s = static_cast<const son_statistics_object&>(o);
|
||||||
const auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
const auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
||||||
const auto son_obj = idx.find( s.owner );
|
const auto son_obj = idx.find( s.owner );
|
||||||
FC_ASSERT(son_obj->get_sidechain_vote_id(active_sidechain_type).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", active_sidechain_type)("son", *son_obj));
|
uint16_t son_weight = 0;
|
||||||
const uint16_t son_weight = get_weight(active_sidechain_type, _vote_tally_buffer[*son_obj->get_sidechain_vote_id(active_sidechain_type)]);
|
FC_ASSERT(son_obj->get_sidechain_vote_id(st).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", st)("son", *son_obj));
|
||||||
|
if( now >= HARDFORK_SON2_TIME ) {
|
||||||
|
son_weight += get_weight(_vote_tally_buffer[*son_obj->get_sidechain_vote_id(st)]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
son_weight += get_weight_before_son2_hf(_vote_tally_buffer[*son_obj->get_sidechain_vote_id(st)]);
|
||||||
|
}
|
||||||
const uint64_t txs_signed = s.txs_signed.contains(active_sidechain_type) ? s.txs_signed.at(active_sidechain_type) : 0;
|
const uint64_t txs_signed = s.txs_signed.contains(active_sidechain_type) ? s.txs_signed.at(active_sidechain_type) : 0;
|
||||||
weighted_total_txs_signed += (txs_signed * son_weight);
|
weighted_total_txs_signed += (txs_signed * son_weight);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Now pay off each SON proportional to the number of transactions signed
|
// Now pay off each SON proportional to the number of transactions signed.
|
||||||
const share_type son_budget = dpo.son_budget;
|
get_index_type<son_stats_index>().inspect_all_objects([this, &weighted_total_txs_signed, &dpo, &son_budget, &get_weight, &get_weight_before_son2_hf, &now, &active_sidechain_type, &st](const object& o) {
|
||||||
get_index_type<son_stats_index>().inspect_all_objects([this, &now, &get_weight, &weighted_total_txs_signed, &dpo, &son_budget](const object& o) {
|
|
||||||
for(const auto& active_sidechain_type : active_sidechain_types(now)) {
|
|
||||||
const son_statistics_object& s = static_cast<const son_statistics_object&>(o);
|
const son_statistics_object& s = static_cast<const son_statistics_object&>(o);
|
||||||
|
|
||||||
const uint64_t txs_signed = s.txs_signed.contains(active_sidechain_type) ? s.txs_signed.at(active_sidechain_type) : 0;
|
const uint64_t txs_signed = s.txs_signed.contains(active_sidechain_type) ? s.txs_signed.at(active_sidechain_type) : 0;
|
||||||
|
|
||||||
if(txs_signed > 0) {
|
if(txs_signed > 0) {
|
||||||
const auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
const auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
||||||
auto son_obj = idx.find( s.owner );
|
auto son_obj = idx.find( s.owner );
|
||||||
uint16_t son_weight = 0;
|
uint16_t son_weight = 0;
|
||||||
FC_ASSERT(son_obj->get_sidechain_vote_id(active_sidechain_type).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", active_sidechain_type)("son", *son_obj));
|
FC_ASSERT(son_obj->get_sidechain_vote_id(st).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", st)("son", *son_obj));
|
||||||
son_weight += get_weight(active_sidechain_type, _vote_tally_buffer[*son_obj->get_sidechain_vote_id(active_sidechain_type)]);
|
if( now >= HARDFORK_SON2_TIME ) {
|
||||||
|
son_weight += get_weight(_vote_tally_buffer[*son_obj->get_sidechain_vote_id(st)]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
son_weight += get_weight_before_son2_hf(_vote_tally_buffer[*son_obj->get_sidechain_vote_id(st)]);
|
||||||
|
}
|
||||||
const share_type pay = (txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed;
|
const share_type pay = (txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed;
|
||||||
modify(*son_obj, [&](son_object &_son_obj) {
|
modify( *son_obj, [&]( son_object& _son_obj)
|
||||||
|
{
|
||||||
_son_obj.pay_son_fee(pay, *this);
|
_son_obj.pay_son_fee(pay, *this);
|
||||||
});
|
});
|
||||||
//Remove the amount paid out to SON from global SON Budget
|
//Remove the amount paid out to SON from global SON Budget
|
||||||
modify(dpo, [&](dynamic_global_property_object &_dpo) {
|
modify( dpo, [&]( dynamic_global_property_object& _dpo )
|
||||||
|
{
|
||||||
_dpo.son_budget -= pay;
|
_dpo.son_budget -= pay;
|
||||||
} );
|
} );
|
||||||
//Reset the tx counter in each son statistics object
|
//Reset the tx counter in each son statistics object
|
||||||
modify(s, [&](son_statistics_object &_s) {
|
modify( s, [&]( son_statistics_object& _s)
|
||||||
|
{
|
||||||
if(_s.txs_signed.contains(active_sidechain_type))
|
if(_s.txs_signed.contains(active_sidechain_type))
|
||||||
_s.txs_signed.at(active_sidechain_type) = 0;
|
_s.txs_signed.at(active_sidechain_type) = 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Note the last son pay out time
|
//Note the last son pay out time
|
||||||
modify( dpo, [&]( dynamic_global_property_object& _dpo )
|
modify( dpo, [&]( dynamic_global_property_object& _dpo )
|
||||||
{
|
{
|
||||||
|
|
@ -396,6 +297,7 @@ void database::pay_sons_after_hf_ethereum()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void database::update_son_metrics(const flat_map<sidechain_type, vector<son_sidechain_info> >& curr_active_sons)
|
void database::update_son_metrics(const flat_map<sidechain_type, vector<son_sidechain_info> >& curr_active_sons)
|
||||||
{
|
{
|
||||||
|
|
@ -2290,10 +2192,7 @@ void database::perform_son_tasks()
|
||||||
// Before making a budget we should pay out SONs
|
// Before making a budget we should pay out SONs
|
||||||
// This function should check if its time to pay sons
|
// This function should check if its time to pay sons
|
||||||
// and modify the global son funds accordingly, whatever is left is passed on to next budget
|
// and modify the global son funds accordingly, whatever is left is passed on to next budget
|
||||||
if(head_block_time() < HARDFORK_SON_FOR_ETHEREUM_TIME)
|
pay_sons();
|
||||||
pay_sons_before_hf_ethereum();
|
|
||||||
else
|
|
||||||
pay_sons_after_hf_ethereum();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split vote_ids
|
// Split vote_ids
|
||||||
|
|
@ -2306,7 +2205,7 @@ void database::perform_son_tasks()
|
||||||
// Add vote_ids for HIVE and ETHEREUM to all existing SONs
|
// Add vote_ids for HIVE and ETHEREUM to all existing SONs
|
||||||
const auto &all_sons = get_index_type<son_index>().indices().get<by_id>();
|
const auto &all_sons = get_index_type<son_index>().indices().get<by_id>();
|
||||||
for (const son_object &son : all_sons) {
|
for (const son_object &son : all_sons) {
|
||||||
const auto existing_vote_id_bitcoin = son.get_bitcoin_vote_id();
|
vote_id_type existing_vote_id_bitcoin;
|
||||||
vote_id_type new_vote_id_hive;
|
vote_id_type new_vote_id_hive;
|
||||||
vote_id_type new_vote_id_eth;
|
vote_id_type new_vote_id_eth;
|
||||||
|
|
||||||
|
|
@ -2323,7 +2222,7 @@ void database::perform_son_tasks()
|
||||||
// Duplicate all votes from bitcoin to hive
|
// Duplicate all votes from bitcoin to hive
|
||||||
const auto &all_accounts = get_index_type<account_index>().indices().get<by_id>();
|
const auto &all_accounts = get_index_type<account_index>().indices().get<by_id>();
|
||||||
for (const auto &account : all_accounts) {
|
for (const auto &account : all_accounts) {
|
||||||
if (existing_vote_id_bitcoin.valid() && account.options.votes.count(*existing_vote_id_bitcoin) != 0) {
|
if (account.options.votes.count(existing_vote_id_bitcoin) != 0) {
|
||||||
modify(account, [new_vote_id_hive](account_object &a) {
|
modify(account, [new_vote_id_hive](account_object &a) {
|
||||||
a.options.votes.insert(new_vote_id_hive);
|
a.options.votes.insert(new_vote_id_hive);
|
||||||
});
|
});
|
||||||
|
|
@ -2533,7 +2432,6 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
|
||||||
update_active_committee_members();
|
update_active_committee_members();
|
||||||
update_active_sons();
|
update_active_sons();
|
||||||
update_worker_votes();
|
update_worker_votes();
|
||||||
hotfix_2024();
|
|
||||||
|
|
||||||
const dynamic_global_property_object& dgpo = get_dynamic_global_properties();
|
const dynamic_global_property_object& dgpo = get_dynamic_global_properties();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,20 +200,22 @@ void database::update_witness_schedule()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::update_son_schedule(sidechain_type type)
|
void database::update_son_schedule()
|
||||||
{
|
{
|
||||||
const global_property_object& gpo = get_global_properties();
|
const global_property_object& gpo = get_global_properties();
|
||||||
|
|
||||||
const son_schedule_object& sidechain_sso = get(son_schedule_id_type(get_son_schedule_id(type)));
|
for(const auto& active_sidechain_type : active_sidechain_types(head_block_time()))
|
||||||
if( gpo.active_sons.at(type).size() != 0 &&
|
{
|
||||||
head_block_num() % gpo.active_sons.at(type).size() == 0)
|
const son_schedule_object& sidechain_sso = get(son_schedule_id_type(get_son_schedule_id(active_sidechain_type)));
|
||||||
|
if( gpo.active_sons.at(active_sidechain_type).size() != 0 &&
|
||||||
|
head_block_num() % gpo.active_sons.at(active_sidechain_type).size() == 0)
|
||||||
{
|
{
|
||||||
modify( sidechain_sso, [&]( son_schedule_object& _sso )
|
modify( sidechain_sso, [&]( son_schedule_object& _sso )
|
||||||
{
|
{
|
||||||
_sso.current_shuffled_sons.clear();
|
_sso.current_shuffled_sons.clear();
|
||||||
_sso.current_shuffled_sons.reserve( gpo.active_sons.at(type).size() );
|
_sso.current_shuffled_sons.reserve( gpo.active_sons.at(active_sidechain_type).size() );
|
||||||
|
|
||||||
for ( const auto &w : gpo.active_sons.at(type) ) {
|
for ( const auto &w : gpo.active_sons.at(active_sidechain_type) ) {
|
||||||
_sso.current_shuffled_sons.push_back(w.son_id);
|
_sso.current_shuffled_sons.push_back(w.son_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -237,6 +239,7 @@ void database::update_son_schedule(sidechain_type type)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vector<witness_id_type> database::get_near_witness_schedule()const
|
vector<witness_id_type> database::get_near_witness_schedule()const
|
||||||
{
|
{
|
||||||
|
|
@ -318,15 +321,23 @@ void database::update_witness_schedule(const signed_block& next_block)
|
||||||
idump( ( double(total_time/1000000.0)/calls) );
|
idump( ( double(total_time/1000000.0)/calls) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::update_son_schedule(sidechain_type type, const signed_block& next_block)
|
void database::update_son_schedule(const signed_block& next_block)
|
||||||
{
|
{
|
||||||
auto start = fc::time_point::now();
|
auto start = fc::time_point::now();
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
const son_schedule_object& sso = get(son_schedule_id_type());
|
const son_schedule_object& sso = get(son_schedule_id_type());
|
||||||
#endif
|
#endif
|
||||||
const global_property_object& gpo = get_global_properties();
|
const global_property_object& gpo = get_global_properties();
|
||||||
const uint32_t schedule_needs_filled = gpo.active_sons.at(type).size();
|
const flat_map<sidechain_type, uint32_t> schedule_needs_filled = [&gpo]()
|
||||||
const uint32_t schedule_slot = get_slot_at_time(next_block.timestamp);
|
{
|
||||||
|
flat_map<sidechain_type, uint32_t> schedule_needs_filled;
|
||||||
|
for(const auto& sidechain_active_sons : gpo.active_sons)
|
||||||
|
{
|
||||||
|
schedule_needs_filled[sidechain_active_sons.first] = sidechain_active_sons.second.size();
|
||||||
|
}
|
||||||
|
return schedule_needs_filled;
|
||||||
|
}();
|
||||||
|
uint32_t schedule_slot = get_slot_at_time(next_block.timestamp);
|
||||||
|
|
||||||
// We shouldn't be able to generate _pending_block with timestamp
|
// We shouldn't be able to generate _pending_block with timestamp
|
||||||
// in the past, and incoming blocks from the network with timestamp
|
// in the past, and incoming blocks from the network with timestamp
|
||||||
|
|
@ -340,7 +351,9 @@ void database::update_son_schedule(sidechain_type type, const signed_block& next
|
||||||
assert( dpo.random.data_size() == witness_scheduler_rng::seed_length );
|
assert( dpo.random.data_size() == witness_scheduler_rng::seed_length );
|
||||||
assert( witness_scheduler_rng::seed_length == sso.rng_seed.size() );
|
assert( witness_scheduler_rng::seed_length == sso.rng_seed.size() );
|
||||||
|
|
||||||
const son_schedule_object& sidechain_sso = get(son_schedule_id_type(get_son_schedule_id(type)));
|
for(const auto& active_sidechain_type : active_sidechain_types(head_block_time()))
|
||||||
|
{
|
||||||
|
const son_schedule_object& sidechain_sso = get(son_schedule_id_type(get_son_schedule_id(active_sidechain_type)));
|
||||||
son_id_type first_son;
|
son_id_type first_son;
|
||||||
bool slot_is_near = sidechain_sso.scheduler.get_slot( schedule_slot-1, first_son );
|
bool slot_is_near = sidechain_sso.scheduler.get_slot( schedule_slot-1, first_son );
|
||||||
son_id_type son_id;
|
son_id_type son_id;
|
||||||
|
|
@ -350,7 +363,7 @@ void database::update_son_schedule(sidechain_type type, const signed_block& next
|
||||||
_sso.slots_since_genesis += schedule_slot;
|
_sso.slots_since_genesis += schedule_slot;
|
||||||
witness_scheduler_rng rng(_sso.rng_seed.data, _sso.slots_since_genesis);
|
witness_scheduler_rng rng(_sso.rng_seed.data, _sso.slots_since_genesis);
|
||||||
|
|
||||||
_sso.scheduler._min_token_count = std::max(int(gpo.active_sons.at(type).size()) / 2, 1);
|
_sso.scheduler._min_token_count = std::max(int(gpo.active_sons.at(active_sidechain_type).size()) / 2, 1);
|
||||||
|
|
||||||
if( slot_is_near )
|
if( slot_is_near )
|
||||||
{
|
{
|
||||||
|
|
@ -367,7 +380,7 @@ void database::update_son_schedule(sidechain_type type, const signed_block& next
|
||||||
{
|
{
|
||||||
_sso.scheduler.reset_schedule( first_son );
|
_sso.scheduler.reset_schedule( first_son );
|
||||||
}
|
}
|
||||||
while( !_sso.scheduler.get_slot(schedule_needs_filled, son_id) )
|
while( !_sso.scheduler.get_slot(schedule_needs_filled.at(active_sidechain_type), son_id) )
|
||||||
{
|
{
|
||||||
if( _sso.scheduler.produce_schedule(rng) & emit_turn )
|
if( _sso.scheduler.produce_schedule(rng) & emit_turn )
|
||||||
memcpy(_sso.rng_seed.begin(), dpo.random.data(), dpo.random.data_size());
|
memcpy(_sso.rng_seed.begin(), dpo.random.data(), dpo.random.data_size());
|
||||||
|
|
@ -377,6 +390,7 @@ void database::update_son_schedule(sidechain_type type, const signed_block& next
|
||||||
(_sso.recent_slots_filled << 1)
|
(_sso.recent_slots_filled << 1)
|
||||||
+ 1) << (schedule_slot - 1);
|
+ 1) << (schedule_slot - 1);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
auto end = fc::time_point::now();
|
auto end = fc::time_point::now();
|
||||||
static uint64_t total_time = 0;
|
static uint64_t total_time = 0;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
#ifndef HARDFORK_HOTFIX_2024_TIME
|
|
||||||
#ifdef BUILD_PEERPLAYS_TESTNET
|
|
||||||
#define HARDFORK_HOTFIX_2024_TIME (fc::time_point_sec::from_iso_string("2023-12-20T00:00:00"))
|
|
||||||
#else
|
|
||||||
#define HARDFORK_HOTFIX_2024_TIME (fc::time_point_sec::from_iso_string("2023-12-20T00:00:00"))
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef HARDFORK_SON_FOR_ETHEREUM_TIME
|
#ifndef HARDFORK_SON_FOR_ETHEREUM_TIME
|
||||||
#ifdef BUILD_PEERPLAYS_TESTNET
|
#ifdef BUILD_PEERPLAYS_TESTNET
|
||||||
#define HARDFORK_SON_FOR_ETHEREUM_TIME (fc::time_point_sec::from_iso_string("2023-07-17T12:00:00"))
|
#define HARDFORK_SON_FOR_ETHEREUM_TIME (fc::time_point_sec::from_iso_string("2023-01-24T00:00:00"))
|
||||||
#else
|
#else
|
||||||
#define HARDFORK_SON_FOR_ETHEREUM_TIME (fc::time_point_sec::from_iso_string("2023-10-24T12:00:00"))
|
#define HARDFORK_SON_FOR_ETHEREUM_TIME (fc::time_point_sec::from_iso_string("2023-03-24T00:00:00"))
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@
|
||||||
#define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4
|
#define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4
|
||||||
#define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3
|
#define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3
|
||||||
|
|
||||||
#define GRAPHENE_CURRENT_DB_VERSION "PPY2.5"
|
#define GRAPHENE_CURRENT_DB_VERSION "PPY2.4"
|
||||||
|
|
||||||
#define GRAPHENE_IRREVERSIBLE_THRESHOLD (70 * GRAPHENE_1_PERCENT)
|
#define GRAPHENE_IRREVERSIBLE_THRESHOLD (70 * GRAPHENE_1_PERCENT)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -292,8 +292,8 @@ namespace graphene { namespace chain {
|
||||||
vector<witness_id_type> get_near_witness_schedule()const;
|
vector<witness_id_type> get_near_witness_schedule()const;
|
||||||
void update_witness_schedule();
|
void update_witness_schedule();
|
||||||
void update_witness_schedule(const signed_block& next_block);
|
void update_witness_schedule(const signed_block& next_block);
|
||||||
void update_son_schedule(sidechain_type type);
|
void update_son_schedule();
|
||||||
void update_son_schedule(sidechain_type type, const signed_block& next_block);
|
void update_son_schedule(const signed_block& next_block);
|
||||||
|
|
||||||
void check_lottery_end_by_participants( asset_id_type asset_id );
|
void check_lottery_end_by_participants( asset_id_type asset_id );
|
||||||
void check_ending_lotteries();
|
void check_ending_lotteries();
|
||||||
|
|
@ -579,8 +579,7 @@ namespace graphene { namespace chain {
|
||||||
void initialize_budget_record( fc::time_point_sec now, budget_record& rec )const;
|
void initialize_budget_record( fc::time_point_sec now, budget_record& rec )const;
|
||||||
void process_budget();
|
void process_budget();
|
||||||
void pay_workers( share_type& budget );
|
void pay_workers( share_type& budget );
|
||||||
void pay_sons_before_hf_ethereum();
|
void pay_sons();
|
||||||
void pay_sons_after_hf_ethereum();
|
|
||||||
void perform_son_tasks();
|
void perform_son_tasks();
|
||||||
void perform_chain_maintenance(const signed_block& next_block, const global_property_object& global_props);
|
void perform_chain_maintenance(const signed_block& next_block, const global_property_object& global_props);
|
||||||
void update_active_witnesses();
|
void update_active_witnesses();
|
||||||
|
|
@ -594,7 +593,6 @@ namespace graphene { namespace chain {
|
||||||
const flat_map<sidechain_type, vector<son_sidechain_info> >& new_active_sons );
|
const flat_map<sidechain_type, vector<son_sidechain_info> >& new_active_sons );
|
||||||
void update_son_wallet( const flat_map<sidechain_type, vector<son_sidechain_info> >& new_active_sons );
|
void update_son_wallet( const flat_map<sidechain_type, vector<son_sidechain_info> >& new_active_sons );
|
||||||
void update_worker_votes();
|
void update_worker_votes();
|
||||||
void hotfix_2024();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
double calculate_vesting_factor(const account_object& stake_account);
|
double calculate_vesting_factor(const account_object& stake_account);
|
||||||
|
|
|
||||||
|
|
@ -182,9 +182,6 @@ namespace graphene { namespace chain {
|
||||||
GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( override_transfer );
|
GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( override_transfer );
|
||||||
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( not_permitted, override_transfer, 1, "not permitted" )
|
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( not_permitted, override_transfer, 1, "not permitted" )
|
||||||
|
|
||||||
GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( blind_transfer );
|
|
||||||
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( unknown_commitment, blind_transfer, 1, "Attempting to claim an unknown prior commitment" );
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
FC_DECLARE_DERIVED_EXCEPTION( addition_overflow, graphene::chain::chain_exception, 30002, "addition overflow" )
|
FC_DECLARE_DERIVED_EXCEPTION( addition_overflow, graphene::chain::chain_exception, 30002, "addition overflow" )
|
||||||
FC_DECLARE_DERIVED_EXCEPTION( subtraction_overflow, graphene::chain::chain_exception, 30003, "subtraction overflow" )
|
FC_DECLARE_DERIVED_EXCEPTION( subtraction_overflow, graphene::chain::chain_exception, 30003, "subtraction overflow" )
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,9 @@ struct transfer_to_blind_operation : public base_operation
|
||||||
blind_factor_type blinding_factor;
|
blind_factor_type blinding_factor;
|
||||||
vector<blind_output> outputs;
|
vector<blind_output> outputs;
|
||||||
|
|
||||||
account_id_type fee_payer()const { return from; }
|
account_id_type fee_payer()const { return account_id_type{}; }
|
||||||
|
|
||||||
|
//account_id_type fee_payer()const { return from; }
|
||||||
//void validate()const;
|
//void validate()const;
|
||||||
//share_type calculate_fee(const fee_parameters_type& )const;
|
//share_type calculate_fee(const fee_parameters_type& )const;
|
||||||
};
|
};
|
||||||
|
|
@ -179,7 +181,9 @@ struct transfer_from_blind_operation : public base_operation
|
||||||
blind_factor_type blinding_factor;
|
blind_factor_type blinding_factor;
|
||||||
vector<blind_input> inputs;
|
vector<blind_input> inputs;
|
||||||
|
|
||||||
account_id_type fee_payer()const { return GRAPHENE_TEMP_ACCOUNT; }
|
account_id_type fee_payer()const { return account_id_type{}; }
|
||||||
|
|
||||||
|
//account_id_type fee_payer()const { return GRAPHENE_TEMP_ACCOUNT; }
|
||||||
//void validate()const;
|
//void validate()const;
|
||||||
//void get_required_authorities( vector<authority>& a )const
|
//void get_required_authorities( vector<authority>& a )const
|
||||||
//{
|
//{
|
||||||
|
|
@ -242,8 +246,10 @@ struct blind_transfer_operation : public base_operation
|
||||||
vector<blind_input> inputs;
|
vector<blind_input> inputs;
|
||||||
vector<blind_output> outputs;
|
vector<blind_output> outputs;
|
||||||
|
|
||||||
|
account_id_type fee_payer()const { return account_id_type{}; }
|
||||||
|
|
||||||
/** graphene TEMP account */
|
/** graphene TEMP account */
|
||||||
account_id_type fee_payer()const { return GRAPHENE_TEMP_ACCOUNT; }
|
//account_id_type fee_payer()const;
|
||||||
//void validate()const;
|
//void validate()const;
|
||||||
//share_type calculate_fee( const fee_parameters_type& k )const;
|
//share_type calculate_fee( const fee_parameters_type& k )const;
|
||||||
//void get_required_authorities( vector<authority>& a )const
|
//void get_required_authorities( vector<authority>& a )const
|
||||||
|
|
|
||||||
|
|
@ -36,15 +36,6 @@ namespace graphene { namespace chain {
|
||||||
deposit_address(""),
|
deposit_address(""),
|
||||||
withdraw_public_key(""),
|
withdraw_public_key(""),
|
||||||
withdraw_address("") {}
|
withdraw_address("") {}
|
||||||
|
|
||||||
inline string get_deposit_address() const {
|
|
||||||
if(sidechain_type::ethereum != sidechain)
|
|
||||||
return deposit_address;
|
|
||||||
|
|
||||||
auto deposit_address_lower = deposit_address;
|
|
||||||
std::transform(deposit_address_lower.begin(), deposit_address_lower.end(), deposit_address_lower.begin(), ::tolower);
|
|
||||||
return deposit_address_lower;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct by_account;
|
struct by_account;
|
||||||
|
|
@ -85,7 +76,7 @@ namespace graphene { namespace chain {
|
||||||
ordered_non_unique< tag<by_sidechain_and_deposit_address_and_expires>,
|
ordered_non_unique< tag<by_sidechain_and_deposit_address_and_expires>,
|
||||||
composite_key<sidechain_address_object,
|
composite_key<sidechain_address_object,
|
||||||
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>,
|
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>,
|
||||||
const_mem_fun<sidechain_address_object, string, &sidechain_address_object::get_deposit_address>,
|
member<sidechain_address_object, string, &sidechain_address_object::deposit_address>,
|
||||||
member<sidechain_address_object, time_point_sec, &sidechain_address_object::expires>
|
member<sidechain_address_object, time_point_sec, &sidechain_address_object::expires>
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -97,18 +97,10 @@ void_result update_son_wallet_evaluator::do_evaluate(const son_wallet_update_ope
|
||||||
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK");
|
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK");
|
||||||
FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." );
|
FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." );
|
||||||
|
|
||||||
const son_wallet_id_type son_wallet_id = [&]{
|
const auto& idx = db().get_index_type<son_wallet_index>().indices().get<by_id>();
|
||||||
if(db().head_block_time() >= HARDFORK_SON_FOR_ETHEREUM_TIME)
|
|
||||||
{
|
|
||||||
const auto ast = active_sidechain_types(db().head_block_time());
|
const auto ast = active_sidechain_types(db().head_block_time());
|
||||||
const auto id = (op.son_wallet_id.instance.value - std::distance(ast.begin(), ast.find(op.sidechain))) / ast.size();
|
const auto id = (op.son_wallet_id.instance.value - std::distance(ast.begin(), ast.find(op.sidechain))) / ast.size();
|
||||||
return son_wallet_id_type{ id };
|
const son_wallet_id_type son_wallet_id{ id };
|
||||||
}
|
|
||||||
|
|
||||||
return op.son_wallet_id;
|
|
||||||
}();
|
|
||||||
|
|
||||||
const auto& idx = db().get_index_type<son_wallet_index>().indices().get<by_id>();
|
|
||||||
FC_ASSERT( idx.find(son_wallet_id) != idx.end() );
|
FC_ASSERT( idx.find(son_wallet_id) != idx.end() );
|
||||||
//auto itr = idx.find(op.son_wallet_id);
|
//auto itr = idx.find(op.son_wallet_id);
|
||||||
//FC_ASSERT( itr->addresses.find(op.sidechain) == itr->addresses.end() ||
|
//FC_ASSERT( itr->addresses.find(op.sidechain) == itr->addresses.end() ||
|
||||||
|
|
@ -118,18 +110,10 @@ void_result update_son_wallet_evaluator::do_evaluate(const son_wallet_update_ope
|
||||||
|
|
||||||
object_id_type update_son_wallet_evaluator::do_apply(const son_wallet_update_operation& op)
|
object_id_type update_son_wallet_evaluator::do_apply(const son_wallet_update_operation& op)
|
||||||
{ try {
|
{ try {
|
||||||
const son_wallet_id_type son_wallet_id = [&]{
|
const auto& idx = db().get_index_type<son_wallet_index>().indices().get<by_id>();
|
||||||
if(db().head_block_time() >= HARDFORK_SON_FOR_ETHEREUM_TIME)
|
|
||||||
{
|
|
||||||
const auto ast = active_sidechain_types(db().head_block_time());
|
const auto ast = active_sidechain_types(db().head_block_time());
|
||||||
const auto id = (op.son_wallet_id.instance.value - std::distance(ast.begin(), ast.find(op.sidechain))) / ast.size();
|
const auto id = (op.son_wallet_id.instance.value - std::distance(ast.begin(), ast.find(op.sidechain))) / ast.size();
|
||||||
return son_wallet_id_type{ id };
|
const son_wallet_id_type son_wallet_id{ id };
|
||||||
}
|
|
||||||
|
|
||||||
return op.son_wallet_id;
|
|
||||||
}();
|
|
||||||
|
|
||||||
const auto& idx = db().get_index_type<son_wallet_index>().indices().get<by_id>();
|
|
||||||
auto itr = idx.find(son_wallet_id);
|
auto itr = idx.find(son_wallet_id);
|
||||||
if (itr != idx.end())
|
if (itr != idx.end())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -137,9 +137,8 @@ std::string rlp_encoder::encode_length(int len, int offset) {
|
||||||
|
|
||||||
std::string rlp_encoder::hex2bytes(const std::string &s) {
|
std::string rlp_encoder::hex2bytes(const std::string &s) {
|
||||||
std::string dest;
|
std::string dest;
|
||||||
const auto s_final = s.size() % 2 == 0 ? s : "0" + s;
|
dest.resize(s.size() / 2);
|
||||||
dest.resize(s_final.size() / 2);
|
hex2bin(s.c_str(), &dest[0]);
|
||||||
hex2bin(s_final.c_str(), &dest[0]);
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,6 @@ private:
|
||||||
uint16_t retries_threshold = 150;
|
uint16_t retries_threshold = 150;
|
||||||
|
|
||||||
bool first_block_skipped;
|
bool first_block_skipped;
|
||||||
bool son_processing_enabled;
|
|
||||||
void on_applied_block(const signed_block &b);
|
void on_applied_block(const signed_block &b);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -136,8 +135,7 @@ peerplays_sidechain_plugin_impl::peerplays_sidechain_plugin_impl(peerplays_sidec
|
||||||
}
|
}
|
||||||
return net_handlers;
|
return net_handlers;
|
||||||
}()),
|
}()),
|
||||||
first_block_skipped(false),
|
first_block_skipped(false) {
|
||||||
son_processing_enabled(false) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peerplays_sidechain_plugin_impl::~peerplays_sidechain_plugin_impl() {
|
peerplays_sidechain_plugin_impl::~peerplays_sidechain_plugin_impl() {
|
||||||
|
|
@ -873,16 +871,7 @@ void peerplays_sidechain_plugin_impl::settle_sidechain_transactions(sidechain_ty
|
||||||
|
|
||||||
void peerplays_sidechain_plugin_impl::on_applied_block(const signed_block &b) {
|
void peerplays_sidechain_plugin_impl::on_applied_block(const signed_block &b) {
|
||||||
if (first_block_skipped) {
|
if (first_block_skipped) {
|
||||||
if (son_processing_enabled) {
|
|
||||||
schedule_son_processing();
|
schedule_son_processing();
|
||||||
} else {
|
|
||||||
const fc::time_point now_fine = fc::time_point::now();
|
|
||||||
const fc::time_point_sec now = now_fine + fc::microseconds(500000);
|
|
||||||
if (plugin.database().get_slot_time(1) >= now) {
|
|
||||||
son_processing_enabled = true;
|
|
||||||
schedule_son_processing();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
first_block_skipped = true;
|
first_block_skipped = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -680,7 +680,8 @@ void sidechain_net_handler::on_applied_block(const signed_block &b) {
|
||||||
const bool is_tracked_asset =
|
const bool is_tracked_asset =
|
||||||
((sidechain == sidechain_type::bitcoin) && (transfer_op.amount.asset_id == gpo.parameters.btc_asset())) ||
|
((sidechain == sidechain_type::bitcoin) && (transfer_op.amount.asset_id == gpo.parameters.btc_asset())) ||
|
||||||
((sidechain == sidechain_type::ethereum) && (transfer_op.amount.asset_id == gpo.parameters.eth_asset())) ||
|
((sidechain == sidechain_type::ethereum) && (transfer_op.amount.asset_id == gpo.parameters.eth_asset())) ||
|
||||||
((sidechain == sidechain_type::ethereum) && (transfer_op.amount.asset_id != gpo.parameters.btc_asset()) && (transfer_op.amount.asset_id != gpo.parameters.hbd_asset()) && (transfer_op.amount.asset_id != gpo.parameters.hive_asset()) && (transfer_op.amount.asset_id != asset_id_type())) ||
|
((sidechain == sidechain_type::ethereum) && (transfer_op.amount.asset_id != gpo.parameters.btc_asset())
|
||||||
|
&& (transfer_op.amount.asset_id != gpo.parameters.hbd_asset()) && (transfer_op.amount.asset_id != gpo.parameters.hive_asset())) ||
|
||||||
((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hbd_asset())) ||
|
((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hbd_asset())) ||
|
||||||
((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hive_asset()));
|
((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hive_asset()));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -684,18 +684,13 @@ std::string sidechain_net_handler_ethereum::send_sidechain_transaction(const sid
|
||||||
|
|
||||||
const ethereum::signature_encoder encoder{function_signature};
|
const ethereum::signature_encoder encoder{function_signature};
|
||||||
#ifdef SEND_RAW_TRANSACTION
|
#ifdef SEND_RAW_TRANSACTION
|
||||||
const auto data = encoder.encode(transactions);
|
|
||||||
const std::string params = "[{\"from\":\"" + ethereum::add_0x(public_key) + "\", \"to\":\"" + wallet_contract_address + "\", \"data\":\"" + data + "\"}]";
|
|
||||||
|
|
||||||
ethereum::raw_transaction raw_tr;
|
ethereum::raw_transaction raw_tr;
|
||||||
raw_tr.nonce = rpc_client->get_nonce(ethereum::add_0x(public_key));
|
raw_tr.nonce = rpc_client->get_nonce(ethereum::add_0x(public_key));
|
||||||
raw_tr.gas_price = rpc_client->get_gas_price();
|
raw_tr.gas_price = rpc_client->get_gas_price();
|
||||||
raw_tr.gas_limit = rpc_client->get_estimate_gas(params);
|
|
||||||
if (raw_tr.gas_limit.empty())
|
|
||||||
raw_tr.gas_limit = rpc_client->get_gas_limit();
|
raw_tr.gas_limit = rpc_client->get_gas_limit();
|
||||||
raw_tr.to = wallet_contract_address;
|
raw_tr.to = wallet_contract_address;
|
||||||
raw_tr.value = "";
|
raw_tr.value = "";
|
||||||
raw_tr.data = data;
|
raw_tr.data = encoder.encode(transactions);
|
||||||
raw_tr.chain_id = ethereum::add_0x(ethereum::to_hex(chain_id));
|
raw_tr.chain_id = ethereum::add_0x(ethereum::to_hex(chain_id));
|
||||||
|
|
||||||
const auto sign_tr = raw_tr.sign(get_private_key(public_key));
|
const auto sign_tr = raw_tr.sign(get_private_key(public_key));
|
||||||
|
|
@ -809,7 +804,7 @@ optional<asset> sidechain_net_handler_ethereum::estimate_withdrawal_transaction_
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto &public_key = son->sidechain_public_keys.at(sidechain);
|
const auto &public_key = son->sidechain_public_keys.at(sidechain);
|
||||||
const auto data = ethereum::withdrawal_encoder::encode(public_key, boost::multiprecision::uint256_t{1} * boost::multiprecision::uint256_t{10000000000}, "0");
|
const auto data = ethereum::withdrawal_encoder::encode(public_key, boost::multiprecision::uint256_t{1} * boost::multiprecision::uint256_t{10000000000}, son_wallet_withdraw_id_type{0}.operator object_id_type().operator std::string());
|
||||||
const std::string params = "[{\"from\":\"" + ethereum::add_0x(public_key) + "\", \"to\":\"" + wallet_contract_address + "\", \"data\":\"" + data + "\"}]";
|
const std::string params = "[{\"from\":\"" + ethereum::add_0x(public_key) + "\", \"to\":\"" + wallet_contract_address + "\", \"data\":\"" + data + "\"}]";
|
||||||
|
|
||||||
const auto estimate_gas = ethereum::from_hex<int64_t>(rpc_client->get_estimate_gas(params));
|
const auto estimate_gas = ethereum::from_hex<int64_t>(rpc_client->get_estimate_gas(params));
|
||||||
|
|
@ -914,9 +909,8 @@ void sidechain_net_handler_ethereum::handle_event(const std::string &block_numbe
|
||||||
const boost::property_tree::ptree tx = tx_child.second;
|
const boost::property_tree::ptree tx = tx_child.second;
|
||||||
tx_idx = tx_idx + 1;
|
tx_idx = tx_idx + 1;
|
||||||
|
|
||||||
|
const std::string from = tx.get<std::string>("from");
|
||||||
const std::string to = tx.get<std::string>("to");
|
const std::string to = tx.get<std::string>("to");
|
||||||
std::string from = tx.get<std::string>("from");
|
|
||||||
std::transform(from.begin(), from.end(), from.begin(), ::tolower);
|
|
||||||
|
|
||||||
std::string cmp_to = to;
|
std::string cmp_to = to;
|
||||||
std::transform(cmp_to.begin(), cmp_to.end(), cmp_to.begin(), ::toupper);
|
std::transform(cmp_to.begin(), cmp_to.end(), cmp_to.begin(), ::toupper);
|
||||||
|
|
|
||||||
|
|
@ -2773,21 +2773,12 @@ public:
|
||||||
FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
|
FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
|
||||||
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive || sidechain == sidechain_type::ethereum, "Unexpected sidechain type");
|
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive || sidechain == sidechain_type::ethereum, "Unexpected sidechain type");
|
||||||
|
|
||||||
bool update_vote_time = false;
|
|
||||||
if (approve)
|
if (approve)
|
||||||
{
|
{
|
||||||
FC_ASSERT(son_obj->get_sidechain_vote_id(sidechain).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", sidechain)("son", *son_obj));
|
FC_ASSERT(son_obj->get_sidechain_vote_id(sidechain).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", sidechain)("son", *son_obj));
|
||||||
account_id_type stake_account = get_account_id(voting_account);
|
|
||||||
const auto gpos_info = _remote_db->get_gpos_info(stake_account);
|
|
||||||
const auto vesting_subperiod = _remote_db->get_global_properties().parameters.gpos_subperiod();
|
|
||||||
const auto gpos_start_time = fc::time_point_sec(_remote_db->get_global_properties().parameters.gpos_period_start());
|
|
||||||
const auto subperiod_start_time = gpos_start_time.sec_since_epoch() + (gpos_info.current_subperiod - 1) * vesting_subperiod;
|
|
||||||
|
|
||||||
auto insert_result = voting_account_object.options.votes.insert(*son_obj->get_sidechain_vote_id(sidechain));
|
auto insert_result = voting_account_object.options.votes.insert(*son_obj->get_sidechain_vote_id(sidechain));
|
||||||
if (!insert_result.second && (gpos_info.last_voted_time.sec_since_epoch() >= subperiod_start_time))
|
if (!insert_result.second)
|
||||||
FC_THROW("Account ${account} was already voting for son ${son} in the current GPOS sub-period", ("account", voting_account)("son", son));
|
FC_THROW("Account ${account} has already voted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
|
||||||
else
|
|
||||||
update_vote_time = true; //Allow user to vote in each sub-period(Update voting time, which is reference in calculating VF)
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -2796,11 +2787,9 @@ public:
|
||||||
if (!votes_removed)
|
if (!votes_removed)
|
||||||
FC_THROW("Account ${account} has already unvoted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
|
FC_THROW("Account ${account} has already unvoted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
|
||||||
}
|
}
|
||||||
|
|
||||||
account_update_operation account_update_op;
|
account_update_operation account_update_op;
|
||||||
account_update_op.account = voting_account_object.id;
|
account_update_op.account = voting_account_object.id;
|
||||||
account_update_op.new_options = voting_account_object.options;
|
account_update_op.new_options = voting_account_object.options;
|
||||||
account_update_op.extensions.value.update_last_voting_time = update_vote_time;
|
|
||||||
|
|
||||||
signed_transaction tx;
|
signed_transaction tx;
|
||||||
tx.operations.push_back( account_update_op );
|
tx.operations.push_back( account_update_op );
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ public:
|
||||||
{
|
{
|
||||||
fixture_.init_nathan();
|
fixture_.init_nathan();
|
||||||
fixture_.generate_blocks(HARDFORK_SON_FOR_ETHEREUM_TIME);
|
fixture_.generate_blocks(HARDFORK_SON_FOR_ETHEREUM_TIME);
|
||||||
fixture_.generate_maintenance_block();
|
fixture_.generate_block();
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_son(const std::string& account_name, const std::string& son_url,
|
void create_son(const std::string& account_name, const std::string& son_url,
|
||||||
|
|
|
||||||
|
|
@ -574,7 +574,7 @@ BOOST_AUTO_TEST_CASE( son_pay_test )
|
||||||
BOOST_REQUIRE_EQUAL(son_stats_obj2->total_sidechain_txs_reported.at(sidechain_type::hive), 12);
|
BOOST_REQUIRE_EQUAL(son_stats_obj2->total_sidechain_txs_reported.at(sidechain_type::hive), 12);
|
||||||
BOOST_REQUIRE_EQUAL(son_stats_obj2->total_sidechain_txs_reported.at(sidechain_type::ethereum), 18);
|
BOOST_REQUIRE_EQUAL(son_stats_obj2->total_sidechain_txs_reported.at(sidechain_type::ethereum), 18);
|
||||||
// Check that Alice and Bob are paid for signing the transactions in the previous day/cycle
|
// Check that Alice and Bob are paid for signing the transactions in the previous day/cycle
|
||||||
BOOST_REQUIRE_EQUAL(db.get_balance(obj1->son_account, asset_id_type()).amount.value, 79+obj1_balance);
|
BOOST_REQUIRE_EQUAL(db.get_balance(obj1->son_account, asset_id_type()).amount.value, 80+obj1_balance);
|
||||||
BOOST_REQUIRE_EQUAL(db.get_balance(obj2->son_account, asset_id_type()).amount.value, 120+obj2_balance);
|
BOOST_REQUIRE_EQUAL(db.get_balance(obj2->son_account, asset_id_type()).amount.value, 120+obj2_balance);
|
||||||
// Check the SON Budget is again allocated after maintenance
|
// Check the SON Budget is again allocated after maintenance
|
||||||
BOOST_CHECK( dpo.son_budget.value == 200);
|
BOOST_CHECK( dpo.son_budget.value == 200);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue