Skip to content

Commit 9570395

Browse files
committed
Using PBFT_STAT for dappnet2 treasury
1 parent b50bd74 commit 9570395

File tree

4 files changed

+82
-20
lines changed

4 files changed

+82
-20
lines changed

core/block_crypt.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,10 +2273,10 @@ namespace beam
22732273

22742274
case Network::dappnet2:
22752275
TreasuryChecksum = {
2276-
0xd6, 0x26, 0xdd, 0xfa, 0xf1, 0x5e, 0x59, 0x77,
2277-
0xcb, 0x06, 0xa0, 0x74, 0xb8, 0xbe, 0x4e, 0x51,
2278-
0x82, 0x0e, 0x8d, 0x6d, 0xf6, 0x21, 0x5d, 0x86,
2279-
0x07, 0x21, 0x15, 0x12, 0xd8, 0xcf, 0x2a, 0xe7
2276+
0x60, 0xda, 0x1a, 0xf0, 0xed, 0x88, 0x0f, 0x9a,
2277+
0xea, 0x06, 0x5c, 0xe6, 0xc8, 0x97, 0xb7, 0x31,
2278+
0x74, 0x94, 0x75, 0xb0, 0x3e, 0x1c, 0xe2, 0xe1,
2279+
0x76, 0x3e, 0xe5, 0xba, 0x6b, 0x5e, 0xc9, 0xa1,
22802280
};
22812281

22822282
break;

treasury/dappnet2.bin

-13 KB
Binary file not shown.

wallet/unittests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ configure_file("../../bvm/Shaders/l2tst1/contract_l1.wasm" "${CMAKE_CURRENT_BINA
2525
configure_file("../../bvm/Shaders/l2tst1/contract_l2.wasm" "${CMAKE_CURRENT_BINARY_DIR}/l2tst1/contract_l2.wasm" COPYONLY)
2626
configure_file("../../bvm/Shaders/l2tst1/app.wasm" "${CMAKE_CURRENT_BINARY_DIR}/l2tst1/app.wasm" COPYONLY)
2727
configure_file("../../bvm/Shaders/pbft/pbft_dpos.wasm" "${CMAKE_CURRENT_BINARY_DIR}/pbft/pbft_dpos.wasm" COPYONLY)
28+
configure_file("../../bvm/Shaders/pbft/pbft_stat.wasm" "${CMAKE_CURRENT_BINARY_DIR}/pbft/pbft_stat.wasm" COPYONLY)
2829

2930

3031
add_test_snippet(wallet_test wallet node mnemonic wallet_client wallet_api wallet_test_node)

wallet/unittests/wallet_test.cpp

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ namespace Shaders {
7070
# define HOST_BUILD
7171
# include "../bvm/Shaders/common.h"
7272
# include "../bvm/Shaders/pbft/pbft_dpos.h"
73+
# include "../bvm/Shaders/pbft/pbft_stat.h"
7374
} // namespace Shaders
7475

7576
namespace
@@ -2956,14 +2957,31 @@ namespace
29562957
};
29572958

29582959

2959-
struct PbftTreasuryBuilder
2960+
struct PbftTreasuryBuilderBase
2961+
{
2962+
Treasury::Data::Group& m_Tg;
2963+
PbftTreasuryBuilderBase(Treasury::Data::Group& tg)
2964+
:m_Tg(tg)
2965+
{
2966+
}
2967+
2968+
void FixOffset(ECC::Scalar::Native& sk, bool isOutp)
2969+
{
2970+
if (isOutp)
2971+
sk = -sk;
2972+
m_Tg.m_Data.m_Offset = ECC::Scalar::Native(m_Tg.m_Data.m_Offset) + sk;
2973+
}
2974+
};
2975+
2976+
2977+
struct PbftTreasuryBuilder_Dpos
2978+
:public PbftTreasuryBuilderBase
29602979
{
2961-
Treasury::Data::Group& m_Tg;
29622980
ContractID m_Cid;
29632981
Shaders::PBFT_DPOS::Settings m_Settings;
29642982

2965-
PbftTreasuryBuilder(Treasury::Data::Group& tg)
2966-
:m_Tg(tg)
2983+
PbftTreasuryBuilder_Dpos(Treasury::Data::Group& tg)
2984+
:PbftTreasuryBuilderBase(tg)
29672985
{
29682986
ZeroObject(m_Settings);
29692987
}
@@ -2973,7 +2991,7 @@ namespace
29732991
m_Tg.m_Aid = m_Settings.m_aidStake;
29742992

29752993
auto pKrn = std::make_unique<beam::TxKernelContractCreate>();
2976-
MyManager::Compile(pKrn->m_Data, "pbft/pbft_dpos.wasm", beam::bvm2::Processor::Kind::Contract);
2994+
MyManager::Compile(pKrn->m_Data, "pbft/pbft_dpos.wasm", beam::bvm2::Processor::Kind::Contract);
29772995

29782996
pKrn->m_Args.resize(sizeof(Shaders::PBFT_DPOS::Method::Create));
29792997
auto& args = *(Shaders::PBFT_DPOS::Method::Create*) &pKrn->m_Args.front();
@@ -3021,13 +3039,58 @@ namespace
30213039

30223040
m_Tg.m_Value += MultiWord::From(stake);
30233041
}
3042+
};
30243043

3025-
void FixOffset(ECC::Scalar::Native& sk, bool isOutp)
3044+
struct PbftTreasuryBuilder_Stat
3045+
:public PbftTreasuryBuilderBase
3046+
{
3047+
typedef Shaders::PBFT_STAT::Method::Create::ValidatorInit ValidatorInit;
3048+
std::vector<ValidatorInit> m_vInit;
3049+
3050+
using PbftTreasuryBuilderBase::PbftTreasuryBuilderBase;
3051+
3052+
void AddValidator(const Block::Pbft::Address& addr, const ECC::Point& /* pkDelegator */, Amount stake)
3053+
{
3054+
AddValidator(addr, stake);
3055+
}
3056+
3057+
void AddValidator(const Block::Pbft::Address& addr, Amount stake)
3058+
{
3059+
auto& x = m_vInit.emplace_back();
3060+
x.m_Address = Cast::Down<ECC::uintBig>(addr);
3061+
x.m_Weight = stake;
3062+
}
3063+
3064+
void Export()
30263065
{
3027-
if (isOutp)
3028-
sk = -sk;
3029-
m_Tg.m_Data.m_Offset = ECC::Scalar::Native(m_Tg.m_Data.m_Offset) + sk;
3066+
WALLET_CHECK(!m_vInit.empty());
3067+
3068+
auto pKrn = std::make_unique<beam::TxKernelContractCreate>();
3069+
MyManager::Compile(pKrn->m_Data, "pbft/pbft_stat.wasm", beam::bvm2::Processor::Kind::Contract);
3070+
3071+
pKrn->m_Args.resize(sizeof(Shaders::PBFT_STAT::Method::Create) + sizeof(ValidatorInit) * m_vInit.size());
3072+
auto& args = *(Shaders::PBFT_STAT::Method::Create*) &pKrn->m_Args.front();
3073+
ZeroObject(args);
3074+
args.m_Count = ByteOrder::to_le(static_cast<uint32_t>(m_vInit.size()));
3075+
3076+
for (uint32_t i = 0; i < m_vInit.size(); i++)
3077+
{
3078+
const auto& src = m_vInit[i];
3079+
auto& dst = args.get_VI()[i];
3080+
3081+
dst.m_Address = src.m_Address;
3082+
dst.m_Weight = ByteOrder::to_le(src.m_Weight);
3083+
}
3084+
3085+
ECC::Scalar::Native sk;
3086+
sk.GenRandomNnz();
3087+
ECC::Point::Native ptFunds(beam::Zero);
3088+
pKrn->Sign(&sk, 1, ptFunds, nullptr);
3089+
3090+
m_Tg.m_Data.m_vKernels.push_back(std::move(pKrn));
3091+
FixOffset(sk, true);
30303092
}
3093+
30313094
};
30323095

30333096
void L2Params::RunInThread()
@@ -3046,7 +3109,7 @@ namespace
30463109
// add PBFT and bridge L2 contract deployment
30473110
{
30483111
Treasury::Data td;
3049-
PbftTreasuryBuilder tb(td.m_vGroups.emplace_back());
3112+
PbftTreasuryBuilder_Dpos tb(td.m_vGroups.emplace_back());
30503113
tb.m_Tg.m_Value = Zero;
30513114
tb.m_Tg.m_Data.m_Offset = Zero;
30523115

@@ -5567,13 +5630,9 @@ void MakeTreasury_dappnet2()
55675630

55685631
Treasury::Data td;
55695632

5570-
PbftTreasuryBuilder tb(td.m_vGroups.emplace_back());
5633+
PbftTreasuryBuilder_Stat tb(td.m_vGroups.emplace_back());
55715634
tb.m_Tg.m_Value = Zero;
55725635
tb.m_Tg.m_Data.m_Offset = Zero;
5573-
tb.m_Settings.m_hUnbondLock = 10;
5574-
tb.m_Settings.m_MinValidatorStake = Rules::Coin * 100;
5575-
tb.m_Settings.m_aidStake = 7;
5576-
tb.Init();
55775636

55785637
for (uint32_t i = 0; i < _countof(ppPhrases); i++)
55795638
{
@@ -5637,6 +5696,8 @@ void MakeTreasury_dappnet2()
56375696
tb.AddValidator(addr, ptD, Rules::Coin * 5000);
56385697
}
56395698

5699+
tb.Export();
5700+
56405701
td.m_sCustomMsg = "dappnet2 treasury";
56415702
tres.Build(td);
56425703

@@ -5672,7 +5733,7 @@ void MakeTreasury_l2_test1()
56725733
auto& tg = td.m_vGroups.emplace_back();
56735734
tg.m_Value = Zero;
56745735

5675-
PbftTreasuryBuilder tb(tg);
5736+
PbftTreasuryBuilder_Dpos tb(tg);
56765737
tb.m_Tg.m_Value = Zero;
56775738
tb.m_Tg.m_Data.m_Offset = Zero;
56785739
tb.m_Settings.m_hUnbondLock = 10;

0 commit comments

Comments
 (0)