Skip to content

Commit

Permalink
Merge branch 'testnet' into mainnet
Browse files Browse the repository at this point in the history
# Conflicts:
#	.travis.yml
#	Dockerfile
#	appveyor.yml
#	core/block_crypt.cpp
  • Loading branch information
valdok committed Jun 17, 2020
2 parents c47244c + 347d4e5 commit ba21247
Show file tree
Hide file tree
Showing 38 changed files with 925 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public enum State

public enum Type // used to point Notification::Type in Wallet::switchOnOffNotifications()
{
SoftwareUpdateAvailable, // 0
Unused, // 0
AddressStatusChanged,
Unused,
WalletImplUpdateAvailable,
BeamNews,
TransactionFailed,
TransactionCompleted
Expand Down
23 changes: 7 additions & 16 deletions android/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ namespace
{
static auto logger = Logger::create(LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG, "wallet_", (fs::path(appData) / fs::path("logs")).string());

Rules::get().pForks[1].m_Height = 10;
Rules::get().pForks[2].m_Height = 20;
Rules::get().MaxRollback = 10;
Rules::get().CA.LockPeriod = 10;
Rules::get().Shielded.m_ProofMax.n = 4;
Rules::get().Shielded.m_ProofMax.M = 3;
Rules::get().Shielded.m_ProofMin.n = 4;
Rules::get().Shielded.m_ProofMin.M = 2;
Rules::get().Shielded.MaxWindowBacklog = 150;
Rules::get().UpdateChecksum();
LOG_INFO() << "Beam Mobile Wallet " << appVersion << " (" << BRANCH_NAME << ") library: " << PROJECT_VERSION;
LOG_INFO() << "Rules signature: " << Rules::get().get_SignatureStr();
Expand All @@ -73,12 +64,12 @@ namespace
std::map<Notification::Type,bool> initNotifications(bool initialValue)
{
return std::map<Notification::Type,bool> {
{ Notification::Type::SoftwareUpdateAvailable, initialValue },
{ Notification::Type::BeamNews, initialValue },
{ Notification::Type::WalletImplUpdateAvailable, false },
{ Notification::Type::TransactionCompleted, initialValue },
{ Notification::Type::TransactionFailed, initialValue },
{ Notification::Type::AddressStatusChanged, initialValue }
{ Notification::Type::SoftwareUpdateAvailable, false },
{ Notification::Type::BeamNews, initialValue },
{ Notification::Type::WalletImplUpdateAvailable, initialValue },
{ Notification::Type::TransactionCompleted, initialValue },
{ Notification::Type::TransactionFailed, initialValue },
{ Notification::Type::AddressStatusChanged, initialValue }
};
}

Expand Down Expand Up @@ -601,7 +592,7 @@ JNIEXPORT void JNICALL BEAM_JAVA_WALLET_INTERFACE(switchOnOffExchangeRates)(JNIE
JNIEXPORT void JNICALL BEAM_JAVA_WALLET_INTERFACE(switchOnOffNotifications)(JNIEnv *env, jobject thiz,
jint notificationTypeEnum, jboolean isActive)
{
if (notificationTypeEnum < static_cast<int>(Notification::Type::SoftwareUpdateAvailable)
if (notificationTypeEnum <= static_cast<int>(Notification::Type::SoftwareUpdateAvailable)
|| notificationTypeEnum > static_cast<int>(Notification::Type::TransactionCompleted))
{
LOG_ERROR() << "Notification type is not valid!!!";
Expand Down
25 changes: 15 additions & 10 deletions android/wallet_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,26 @@ namespace

void callSoftwareUpdateNotification(JNIEnv* env, const Notification& notification, ChangeAction action)
{
VersionInfo versionInfo;
WalletImplVerInfo walletVersionInfo;

if (fromByteBuffer(notification.m_content, versionInfo))
if (fromByteBuffer(notification.m_content, walletVersionInfo))
{
jobject jNotificationInfo = fillNotificationInfo(env, notification);

jobject jVersionInfo = env->AllocObject(VersionInfoClass);
{
setIntField(env, VersionInfoClass, jVersionInfo, "application", beam::underlying_cast(versionInfo.m_application));
setLongField(env, VersionInfoClass, jVersionInfo, "versionMajor", versionInfo.m_version.m_major);
setLongField(env, VersionInfoClass, jVersionInfo, "versionMinor", versionInfo.m_version.m_minor);
setLongField(env, VersionInfoClass, jVersionInfo, "versionRevision", versionInfo.m_version.m_revision);
setIntField(env, VersionInfoClass, jVersionInfo, "application", beam::underlying_cast(walletVersionInfo.m_application));
setLongField(env, VersionInfoClass, jVersionInfo, "versionMajor", walletVersionInfo.m_version.m_major);
setLongField(env, VersionInfoClass, jVersionInfo, "versionMinor", walletVersionInfo.m_version.m_minor);
setLongField(env, VersionInfoClass, jVersionInfo, "versionRevision", walletVersionInfo.m_UIrevision);
}

jmethodID callback = env->GetStaticMethodID(WalletListenerClass, "onNewVersionNotification", "(IL" BEAM_JAVA_PATH "/entities/dto/NotificationDTO;L" BEAM_JAVA_PATH "/entities/dto/VersionInfoDTO;)V");
if (walletVersionInfo.m_application == VersionInfo::Application::AndroidWallet)
{
jmethodID callback = env->GetStaticMethodID(WalletListenerClass, "onNewVersionNotification", "(IL" BEAM_JAVA_PATH "/entities/dto/NotificationDTO;L" BEAM_JAVA_PATH "/entities/dto/VersionInfoDTO;)V");

env->CallStaticVoidMethod(WalletListenerClass, callback, action, jNotificationInfo, jVersionInfo);
env->CallStaticVoidMethod(WalletListenerClass, callback, action, jNotificationInfo, jVersionInfo);
}

env->DeleteLocalRef(jNotificationInfo);
env->DeleteLocalRef(jVersionInfo);
Expand Down Expand Up @@ -569,8 +572,10 @@ void WalletModel::onNotificationsChanged(ChangeAction action, const std::vector<
switch(notification.m_type)
{
case Notification::Type::SoftwareUpdateAvailable:
callSoftwareUpdateNotification(env, notification, action);
break;
break;
case Notification::Type::WalletImplUpdateAvailable:
callSoftwareUpdateNotification(env, notification, action);
break;
case Notification::Type::AddressStatusChanged:
callAddressStatusNotification(env, notification, action);
break;
Expand Down
11 changes: 11 additions & 0 deletions beam/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,17 @@ int main_impl(int argc, char* argv[])
});
}

if (vm.count(cli::MANUAL_ROLLBACK))
{
Height h = vm[cli::MANUAL_ROLLBACK].as<Height>();
if (h >= Rules::HeightGenesis)
node.get_Processor().ManualRollbackTo(h);
else
node.get_Processor().ForbidActiveAt(0);

node.RefreshCongestions();
}

reactor->run();
}
}
Expand Down
31 changes: 15 additions & 16 deletions core/block_crypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2612,26 +2612,25 @@ namespace beam
uint32_t N = Rules::get().CA.m_ProofCfg.get_N();
assert(N);

ECC::Hash::Value hv;
ECC::Hash::Processor() << skGen >> hv;
if (aid > N / 2)
{
ECC::Hash::Value hv;
ECC::Hash::Processor() << skGen >> hv;

uint32_t nPos;
hv.ExportWord<0>(nPos);
nPos %= N; // the position of this element in the list
uint32_t nPos;
hv.ExportWord<0>(nPos);
nPos %= N; // the position of this element in the list

if (aid > nPos)
{
// TODO: don't exceed the max current asset count, for this we must query it
m_Begin = aid - nPos;
}
else
{
m_Begin = 0;
nPos = aid;
if (aid > nPos)
{
// TODO: don't exceed the max current asset count, for this we must query it
m_Begin = aid - nPos;
return nPos;
}
}

assert(m_Begin + nPos == aid);
return nPos;
m_Begin = 0;
return aid;
}

bool Asset::Proof::IsValid(ECC::Point::Native& hGen, ECC::InnerProduct::BatchContext& bc, ECC::Scalar::Native* pKs) const
Expand Down
13 changes: 13 additions & 0 deletions core/fly_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,10 @@ bool FlyClient::NetworkStd::Connection::IsSupported(RequestEvents& req)

void FlyClient::NetworkStd::Connection::OnRequestData(RequestEvents& req)
{
req.m_Max = (LoginFlags::Extension::get(m_LoginFlags) >= 5) ?
proto::Event::s_Max :
proto::Event::s_Max0;

}

bool FlyClient::NetworkStd::Connection::IsSupported(RequestTransaction& req)
Expand Down Expand Up @@ -915,5 +919,14 @@ void FlyClient::NetworkStd::Connection::OnMsg(BbsMsg&& msg)
}
}

void FlyClient::NetworkStd::Connection::OnMsg(EventsSerif&& msg)
{
if (!(Flags::Owned & m_Flags))
ThrowUnexpected();

// TODO: handle complex situation, where multiple owned nodes are connected
m_This.m_Client.OnEventsSerif(msg.m_Value, msg.m_Height);
}

} // namespace proto
} // namespace beam
17 changes: 16 additions & 1 deletion core/fly_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
namespace beam {
namespace proto {

namespace details {

template <typename T> struct ExtraData {
};

template <> struct ExtraData<proto::Events> {
uint32_t m_Max = proto::Event::s_Max;
};
}

struct FlyClient
{
#define REQUEST_TYPES_All(macro) \
Expand Down Expand Up @@ -67,7 +77,10 @@ namespace proto {
};

#define THE_MACRO(type, msgOut, msgIn) \
struct Request##type :public Request { \
struct Request##type \
:public Request \
,public details::ExtraData<msgIn> \
{ \
typedef boost::intrusive_ptr<Request##type> Ptr; \
Request##type() :m_Msg(Zero), m_Res(Zero) {} \
virtual ~Request##type() {} \
Expand All @@ -87,6 +100,7 @@ namespace proto {
virtual void get_OwnerKdf(Key::IPKdf::Ptr&) {} // get the owner kdf. Optional
virtual Block::SystemState::IHistory& get_History() = 0;
virtual void OnOwnedNode(const PeerID&, bool bUp) {}
virtual void OnEventsSerif(const ECC::Hash::Value&, Height) {}

struct IBbsReceiver
{
Expand Down Expand Up @@ -216,6 +230,7 @@ namespace proto {
virtual void OnMsg(proto::ProofCommonState&& msg) override;
virtual void OnMsg(proto::ProofChainWork&& msg) override;
virtual void OnMsg(proto::BbsMsg&& msg) override;
virtual void OnMsg(proto::EventsSerif&& msg) override;
#define THE_MACRO(type, msgOut, msgIn) \
virtual void OnMsg(proto::msgIn&&) override; \
bool IsSupported(Request##type&); \
Expand Down
55 changes: 38 additions & 17 deletions core/proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,39 @@ void NodeConnection::OnMsg(SChannelInitiate&& msg)
OnConnectedSecure();
}

void LoginFlags::Extension::set(uint32_t& nFlags, uint32_t nExt)
{
assert(!(nFlags & Msk));

if (nExt < nBitsLegacy)
nExt = (1 << nExt) - 1;
else
nExt = ((nExt - nBitsLegacy + 1) << nBitsLegacy) - 1;

nFlags |= nExt << nShift;
}

uint32_t LoginFlags::Extension::get(uint32_t nFlags)
{
uint32_t val = (Msk & nFlags) >> nShift;

const uint32_t nLegacyVal = (1 << nBitsLegacy) - 1;
if (nLegacyVal == (val & nLegacyVal))
return ((val - nLegacyVal) >> nBitsLegacy) + nBitsLegacy;

// find 1st zero bit
uint32_t iBit = 0;
for (; iBit < nBitsLegacy - 1; iBit++)
if (!(1 & (val >> iBit)))
break;

return iBit;
}

void NodeConnection::SendLogin()
{
Login msg;
msg.m_Flags = LoginFlags::ExtensionsAll;
LoginFlags::Extension::set(msg.m_Flags, LoginFlags::Extension::Maximum);
SetupLogin(msg);

const Rules& r = Rules::get();
Expand Down Expand Up @@ -730,23 +759,15 @@ void NodeConnection::OnMsg(Login&& msg)

void NodeConnection::OnLoginInternal(Login&& msg)
{
if (LoginFlags::ExtensionsBeforeHF1 != (LoginFlags::ExtensionsBeforeHF1 & msg.m_Flags))
{
LOG_WARNING() << "Peer " << m_Connection->peer_address() << " uses legacy protocol";
ThrowUnexpected("Legacy", NodeProcessingException::Type::Incompatible);
}
uint32_t nExt = LoginFlags::Extension::get(msg.m_Flags);
if (LoginFlags::Extension::Maximum != nExt)
{
bool bNewer = (nExt > LoginFlags::Extension::Maximum);
LOG_WARNING() << "Peer " << m_Connection->peer_address() << " uses " << (bNewer ? "newer" : "older") << " ext: " << nExt;

if ((~LoginFlags::Recognized) & msg.m_Flags) {
LOG_WARNING() << "Peer " << m_Connection->peer_address() << " Uses newer protocol.";
}
else
{
const uint32_t nMask = LoginFlags::ExtensionsAll;
uint32_t nFlags2 = nMask & msg.m_Flags;
if (nFlags2 != nMask) {
LOG_WARNING() << "Peer " << m_Connection->peer_address() << " Uses older protocol: " << nFlags2;
}
}
if (nExt < LoginFlags::Extension::Minimum)
ThrowUnexpected("Legacy", NodeProcessingException::Type::Incompatible);
}

OnLogin(std::move(msg));
}
Expand Down
38 changes: 25 additions & 13 deletions core/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ namespace proto {
#define BeamNodeMsg_Events(macro) \
macro(ByteBuffer, Events)

#define BeamNodeMsg_EventsSerif(macro) \
macro(ECC::Hash::Value, Value) \
macro(Height, Height) \

#define BeamNodeMsg_GetBlockFinalization(macro) \
macro(Height, Height) \
macro(Amount, Fees)
Expand Down Expand Up @@ -293,6 +297,7 @@ namespace proto {
macro(0x2c, GetEvents) \
macro(0x2d, EventsLegacy) \
macro(0x34, Events) \
macro(0x37, EventsSerif) \
macro(0x2e, GetBlockFinalization) \
macro(0x2f, BlockFinalization) \
/* tx broadcast and replication */ \
Expand All @@ -317,21 +322,27 @@ namespace proto {
static const uint32_t Bbs = 0x2; // I'm spreading bbs messages
static const uint32_t SendPeers = 0x4; // Please send me periodically peers recommendations
static const uint32_t MiningFinalization = 0x8; // I want to finalize block construction for my owned node
static const uint32_t Extension1 = 0x10; // Supports Bbs with POW, more advanced proof/disproof scheme for SPV clients (?)
static const uint32_t Extension2 = 0x20; // Supports large HdrPack, BlockPack with parameters
static const uint32_t Extension3 = 0x40; // Supports Login1, Status (former Boolean) for NewTransaction result, compatible with Fork H1
static const uint32_t Extension4 = 0x80; // Supports proto::Events (replaces proto::EventsLegacy)
static const uint32_t Recognized = 0xff;

struct Extension
{
static const uint32_t nShift = 4; // 1st 4 bits are occupied by flags specified above
static const uint32_t nBitsLegacy = 4; // 1st 4 bits are set consequently for each new version
static const uint32_t nBitsExtra = 8;

static const uint32_t Msk = ((1 << (nBitsLegacy + nBitsExtra)) - 1) << nShift;

// 1 - Supports Bbs with POW, more advanced proof/disproof scheme for SPV clients (?)
// 2 - Supports large HdrPack, BlockPack with parameters
// 3 - Supports Login1, Status (former Boolean) for NewTransaction result, compatible with Fork H1
// 4 - Supports proto::Events (replaces proto::EventsLegacy)
// 5 - Supports Events serif, max num of events per message increased from 64 to 1024

static const uint32_t ExtensionsBeforeHF1 =
Extension1 |
Extension2 |
Extension3;
static const uint32_t Minimum = 3;
static const uint32_t Maximum = 5;

static const uint32_t ExtensionsAll =
ExtensionsBeforeHF1 |
Extension4;
static void set(uint32_t& nFlags, uint32_t nExt);
static uint32_t get(uint32_t nFlags);
};
};

struct IDType
Expand All @@ -345,7 +356,8 @@ namespace proto {

struct Event
{
static const uint32_t s_Max = 64; // will send more, if the remaining events are on the same height
static const uint32_t s_Max0 = 64;
static const uint32_t s_Max = 1024; // will send more, if the remaining events are on the same height

#define BeamEventsAll(macro) \
macro(1, Utxo) \
Expand Down
Loading

0 comments on commit ba21247

Please sign in to comment.