Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/groovy_gluon_7.2RC' into…
Browse files Browse the repository at this point in the history
… mainnet
  • Loading branch information
anatolse committed Oct 19, 2022
2 parents e24a853 + db858c2 commit af52e3c
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 144 deletions.
11 changes: 1 addition & 10 deletions bvm/bvm2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,6 @@ namespace bvm2 {
get_CidViaSid(cid, sid, args);
}

void get_AssetOwner(PeerID& pidOwner, const ContractID& cid, const Asset::Metadata& md)
{
ECC::Hash::Processor()
<< "bvm.a.own"
<< cid
<< md.m_Hash
>> pidOwner;
}

/////////////////////////////////////////////
// Processor
#pragma pack (push, 1)
Expand Down Expand Up @@ -1516,7 +1507,7 @@ namespace bvm2 {
md.UpdateHash();

AssetVar av;
get_AssetOwner(av.m_Owner, m_FarCalls.m_Stack.back().m_Cid, md);
md.get_Owner(av.m_Owner, m_FarCalls.m_Stack.back().m_Cid);

Amount valDeposit;
Asset::ID ret = AssetCreate(md, av.m_Owner, valDeposit);
Expand Down
6 changes: 2 additions & 4 deletions bvm/bvm2.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ namespace Shaders {
typedef ECC::Point::Storage Secp_point_dataEx;
typedef ECC::Scalar Secp_scalar_data;
typedef beam::Asset::ID AssetID;
typedef ECC::uintBig ContractID;
typedef ECC::uintBig ShaderID;
typedef ECC::uintBig HashValue;
typedef beam::uintBig_t<64> HashValue512;
using beam::Amount;
using beam::ContractID;
using beam::Amount;
using beam::Height;
using beam::Timestamp;
using beam::HeightPos;
Expand Down Expand Up @@ -102,8 +102,6 @@ namespace bvm2 {
void get_Cid(ContractID&, const Blob& data, const Blob& args);
void get_CidViaSid(ContractID&, const ShaderID&, const Blob& args);

void get_AssetOwner(PeerID&, const ContractID&, const Asset::Metadata&);

class ProcessorContract;

class Processor
Expand Down
2 changes: 1 addition & 1 deletion bvm/invoke_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace beam::bvm2 {
struct ContractInvokeEntry
{
uint32_t m_Flags = 0;
ECC::uintBig m_Cid;
ContractID m_Cid;
uint32_t m_iMethod = 0;
ByteBuffer m_Data;
ByteBuffer m_Args;
Expand Down
18 changes: 18 additions & 0 deletions core/block_crypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2937,10 +2937,19 @@ namespace beam
{
m_Value = Zero;
m_Owner = Zero;
m_Cid = Zero;
m_LockHeight = 0;
m_Metadata.Reset();
}

void Asset::Info::SetCid(const ContractID* pCid)
{
if (pCid)
m_Cid = *pCid;
else
m_Cid = Zero;
}

bool Asset::Info::IsEmpty() const
{
return m_Value == Zero && m_Owner == Zero && m_LockHeight == Zero && m_Metadata.m_Value.empty();
Expand Down Expand Up @@ -3052,6 +3061,15 @@ namespace beam
res.Import(pt);
}

void Asset::Metadata::get_Owner(PeerID& res, const ContractID& cid) const
{
ECC::Hash::Processor()
<< "bvm.a.own"
<< cid
<< m_Hash
>> res;
}

bool Asset::Info::Recognize(Key::IPKdf& pkdf) const
{
PeerID pid;
Expand Down
7 changes: 6 additions & 1 deletion core/block_crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace beam

using ECC::Key;

typedef ECC::uintBig ContractID;

namespace MasterKey
{
Key::IKdf::Ptr get_Child(Key::IKdf&, Key::Index);
Expand Down Expand Up @@ -174,18 +176,21 @@ namespace beam
void Reset();
void UpdateHash(); // called automatically during deserialization
void get_Owner(PeerID&, Key::IPKdf&) const;
void get_Owner(PeerID&, const ContractID&) const;
};

struct Info
{
AmountBig::Type m_Value = Zero;
PeerID m_Owner = Zero;
ContractID m_Cid = Zero;
Height m_LockHeight = 0; // last emitted/burned change height. if emitted atm - when was latest 1st emission. If burned atm - what was last burn.
Amount m_Deposit = 0;
Metadata m_Metadata;
static const uint32_t s_MetadataMaxSize = 1024 * 16; // 16K

void Reset();
void SetCid(const ContractID*);
bool IsEmpty() const;
bool IsValid() const;
bool Recognize(Key::IPKdf&) const;
Expand Down Expand Up @@ -1139,7 +1144,7 @@ namespace beam
struct TxKernelContractInvoke
:public TxKernelContractControl
{
ECC::uintBig m_Cid;
ContractID m_Cid;
uint32_t m_iMethod;

typedef std::unique_ptr<TxKernelContractInvoke> Ptr;
Expand Down
53 changes: 45 additions & 8 deletions core/fly_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,6 @@ bool FlyClient::NetworkStd::Connection::IsSupported(RequestTransaction& req)
return true;
}

bool FlyClient::NetworkStd::Connection::IsSupported(RequestAssetsListAt& req)
{
if (get_Ext() < 10)
return false;

return true;
}

void FlyClient::NetworkStd::Connection::OnRequestData(RequestProofShieldedInp& req)
{
if (!req.m_Res.m_Proof.empty())
Expand Down Expand Up @@ -1084,6 +1076,15 @@ bool FlyClient::NetworkStd::Connection::SendRequest(RequestBbsMsg& req)
return true;
}

bool FlyClient::NetworkStd::Connection::SendRequest(RequestAssetsListAt& req)
{
if (get_Ext() < 10)
return false;

Send(req.m_Msg);
return true;
}

void FlyClient::NetworkStd::Connection::OnMsg(proto::Pong&&)
{
if (!m_lst.empty())
Expand Down Expand Up @@ -1112,6 +1113,42 @@ void FlyClient::NetworkStd::Connection::OnMsg(proto::Pong&&)
}
}

void FlyClient::NetworkStd::Connection::OnMsg(proto::AssetsListAt&& msg)
{
auto& n = get_FirstRequest();
auto& r = n.m_pRequest->As<RequestAssetsListAt>();

if (msg.m_Assets.empty())
{
if (msg.m_bMore)
ThrowUnexpected();
}
else
{
Asset::ID aid0 = r.m_Msg.m_Aid0;
for (const auto& ai : msg.m_Assets)
{
if (aid0 > ai.m_ID)
ThrowUnexpected();

aid0 = ai.m_ID + 1;
}

if (r.m_Res.empty())
r.m_Res = std::move(msg.m_Assets);
else
r.m_Res.insert(r.m_Res.end(), msg.m_Assets.begin(), msg.m_Assets.end());


r.m_Msg.m_Aid0 = aid0;
}


if (msg.m_bMore)
Send(r.m_Msg);
else
OnDone(n);
}

void FlyClient::NetworkStd::Connection::OnDone(RequestNode& n, bool bMaybeRetry /* = true */)
{
Expand Down
7 changes: 5 additions & 2 deletions core/fly_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ namespace proto {
macro(ShieldedOutputsAt, GetShieldedOutputsAt, ShieldedOutputsAt) \
macro(BodyPack, GetBodyPack, BodyPack) \
macro(Body, GetBodyPack, Body) \
macro(AssetsListAt, GetAssetsListAt, AssetsListAt) \


class Request
Expand Down Expand Up @@ -140,6 +139,10 @@ namespace proto {
struct EnsureSync {
bool m_IsDependent;
};
struct AssetsListAt {
proto::GetAssetsListAt m_Msg;
std::vector<beam::Asset::Full> m_Res;
};
};

#define THE_MACRO(type) \
Expand Down Expand Up @@ -320,11 +323,11 @@ namespace proto {
void OnMsg(proto::HdrPack&& msg) override;
void OnMsg(proto::ContractVars&& msg) override;
void OnMsg(proto::ContractLogs&& msg) override;
void OnMsg(proto::AssetsListAt&& msg) override;

bool IsSupported(const Data::Std&) { return true; }
bool IsSupported(RequestEvents&);
bool IsSupported(RequestTransaction&);
bool IsSupported(RequestAssetsListAt&);

void OnRequestData(const Data::Std&) {}
void OnRequestData(RequestUtxo&);
Expand Down
6 changes: 4 additions & 2 deletions core/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,12 @@ namespace proto {
macro(TxoID, ShieldedOuts)

#define BeamNodeMsg_GetAssetsListAt(macro) \
macro(Height, Height)
macro(Height, Height) \
macro(Asset::ID, Aid0)

#define BeamNodeMsg_AssetsListAt(macro) \
macro(ByteBuffer, AssetsList)
macro(std::vector<Asset::Full>, Assets) \
macro(bool, bMore)

#define BeamNodeMsg_ContractVarsEnum(macro) \
macro(ByteBuffer, KeyMin) \
Expand Down
32 changes: 25 additions & 7 deletions core/serialization_adapters.h
Original file line number Diff line number Diff line change
Expand Up @@ -1970,21 +1970,32 @@ namespace detail
template<typename Archive>
Archive& save(Archive& ar, const beam::Asset::Info& v)
{
bool bDef = v.IsDefDeposit();
beam::Height h = bDef ? v.m_LockHeight : beam::MaxHeight;
uint32_t nFlags = 0;
if (!v.IsDefDeposit())
nFlags |= 1;

const ECC::uintBig* pOwner = &v.m_Owner;
if (v.m_Cid != beam::Zero)
{
pOwner = &v.m_Cid;
nFlags |= 2;
}

beam::Height h = nFlags ? beam::MaxHeight : v.m_LockHeight;
ar
& v.m_Owner
& (*pOwner)
& v.m_Value
& h
& v.m_Metadata;

if (!bDef)
if (nFlags)
{
uint32_t nFlags = 1; // reserve other flags for future use
ar
& nFlags
& v.m_LockHeight
& v.m_Deposit;
& v.m_LockHeight;

if (1 & nFlags)
ar & v.m_Deposit;
}

return ar;
Expand All @@ -2000,6 +2011,7 @@ namespace detail
& v.m_Metadata;

v.m_Deposit = beam::Rules::get().CA.DepositForList2;
v.m_Cid = beam::Zero;

if (beam::MaxHeight == v.m_LockHeight)
{
Expand All @@ -2010,6 +2022,12 @@ namespace detail

if (1 & nFlags)
ar & v.m_Deposit;

if (2 & nFlags)
{
v.m_Cid = Cast::Down<ECC::uintBig>(v.m_Owner);
v.m_Metadata.get_Owner(v.m_Owner, v.m_Cid);
}
}

return ar;
Expand Down
Loading

0 comments on commit af52e3c

Please sign in to comment.