Skip to content

Commit ba21247

Browse files
committed
Merge branch 'testnet' into mainnet
# Conflicts: # .travis.yml # Dockerfile # appveyor.yml # core/block_crypt.cpp
2 parents c47244c + 347d4e5 commit ba21247

38 files changed

+925
-263
lines changed

android/com/mw/beam/beamwallet/core/entities/dto/NotificationDTO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public enum State
2929

3030
public enum Type // used to point Notification::Type in Wallet::switchOnOffNotifications()
3131
{
32-
SoftwareUpdateAvailable, // 0
32+
Unused, // 0
3333
AddressStatusChanged,
34-
Unused,
34+
WalletImplUpdateAvailable,
3535
BeamNews,
3636
TransactionFailed,
3737
TransactionCompleted

android/jni.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ namespace
5656
{
5757
static auto logger = Logger::create(LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG, "wallet_", (fs::path(appData) / fs::path("logs")).string());
5858

59-
Rules::get().pForks[1].m_Height = 10;
60-
Rules::get().pForks[2].m_Height = 20;
61-
Rules::get().MaxRollback = 10;
62-
Rules::get().CA.LockPeriod = 10;
63-
Rules::get().Shielded.m_ProofMax.n = 4;
64-
Rules::get().Shielded.m_ProofMax.M = 3;
65-
Rules::get().Shielded.m_ProofMin.n = 4;
66-
Rules::get().Shielded.m_ProofMin.M = 2;
67-
Rules::get().Shielded.MaxWindowBacklog = 150;
6859
Rules::get().UpdateChecksum();
6960
LOG_INFO() << "Beam Mobile Wallet " << appVersion << " (" << BRANCH_NAME << ") library: " << PROJECT_VERSION;
7061
LOG_INFO() << "Rules signature: " << Rules::get().get_SignatureStr();
@@ -73,12 +64,12 @@ namespace
7364
std::map<Notification::Type,bool> initNotifications(bool initialValue)
7465
{
7566
return std::map<Notification::Type,bool> {
76-
{ Notification::Type::SoftwareUpdateAvailable, initialValue },
77-
{ Notification::Type::BeamNews, initialValue },
78-
{ Notification::Type::WalletImplUpdateAvailable, false },
79-
{ Notification::Type::TransactionCompleted, initialValue },
80-
{ Notification::Type::TransactionFailed, initialValue },
81-
{ Notification::Type::AddressStatusChanged, initialValue }
67+
{ Notification::Type::SoftwareUpdateAvailable, false },
68+
{ Notification::Type::BeamNews, initialValue },
69+
{ Notification::Type::WalletImplUpdateAvailable, initialValue },
70+
{ Notification::Type::TransactionCompleted, initialValue },
71+
{ Notification::Type::TransactionFailed, initialValue },
72+
{ Notification::Type::AddressStatusChanged, initialValue }
8273
};
8374
}
8475

@@ -601,7 +592,7 @@ JNIEXPORT void JNICALL BEAM_JAVA_WALLET_INTERFACE(switchOnOffExchangeRates)(JNIE
601592
JNIEXPORT void JNICALL BEAM_JAVA_WALLET_INTERFACE(switchOnOffNotifications)(JNIEnv *env, jobject thiz,
602593
jint notificationTypeEnum, jboolean isActive)
603594
{
604-
if (notificationTypeEnum < static_cast<int>(Notification::Type::SoftwareUpdateAvailable)
595+
if (notificationTypeEnum <= static_cast<int>(Notification::Type::SoftwareUpdateAvailable)
605596
|| notificationTypeEnum > static_cast<int>(Notification::Type::TransactionCompleted))
606597
{
607598
LOG_ERROR() << "Notification type is not valid!!!";

android/wallet_model.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,26 @@ namespace
163163

164164
void callSoftwareUpdateNotification(JNIEnv* env, const Notification& notification, ChangeAction action)
165165
{
166-
VersionInfo versionInfo;
166+
WalletImplVerInfo walletVersionInfo;
167167

168-
if (fromByteBuffer(notification.m_content, versionInfo))
168+
if (fromByteBuffer(notification.m_content, walletVersionInfo))
169169
{
170170
jobject jNotificationInfo = fillNotificationInfo(env, notification);
171171

172172
jobject jVersionInfo = env->AllocObject(VersionInfoClass);
173173
{
174-
setIntField(env, VersionInfoClass, jVersionInfo, "application", beam::underlying_cast(versionInfo.m_application));
175-
setLongField(env, VersionInfoClass, jVersionInfo, "versionMajor", versionInfo.m_version.m_major);
176-
setLongField(env, VersionInfoClass, jVersionInfo, "versionMinor", versionInfo.m_version.m_minor);
177-
setLongField(env, VersionInfoClass, jVersionInfo, "versionRevision", versionInfo.m_version.m_revision);
174+
setIntField(env, VersionInfoClass, jVersionInfo, "application", beam::underlying_cast(walletVersionInfo.m_application));
175+
setLongField(env, VersionInfoClass, jVersionInfo, "versionMajor", walletVersionInfo.m_version.m_major);
176+
setLongField(env, VersionInfoClass, jVersionInfo, "versionMinor", walletVersionInfo.m_version.m_minor);
177+
setLongField(env, VersionInfoClass, jVersionInfo, "versionRevision", walletVersionInfo.m_UIrevision);
178178
}
179179

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

182-
env->CallStaticVoidMethod(WalletListenerClass, callback, action, jNotificationInfo, jVersionInfo);
184+
env->CallStaticVoidMethod(WalletListenerClass, callback, action, jNotificationInfo, jVersionInfo);
185+
}
183186

184187
env->DeleteLocalRef(jNotificationInfo);
185188
env->DeleteLocalRef(jVersionInfo);
@@ -569,8 +572,10 @@ void WalletModel::onNotificationsChanged(ChangeAction action, const std::vector<
569572
switch(notification.m_type)
570573
{
571574
case Notification::Type::SoftwareUpdateAvailable:
572-
callSoftwareUpdateNotification(env, notification, action);
573-
break;
575+
break;
576+
case Notification::Type::WalletImplUpdateAvailable:
577+
callSoftwareUpdateNotification(env, notification, action);
578+
break;
574579
case Notification::Type::AddressStatusChanged:
575580
callAddressStatusNotification(env, notification, action);
576581
break;

beam/cli.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,17 @@ int main_impl(int argc, char* argv[])
383383
});
384384
}
385385

386+
if (vm.count(cli::MANUAL_ROLLBACK))
387+
{
388+
Height h = vm[cli::MANUAL_ROLLBACK].as<Height>();
389+
if (h >= Rules::HeightGenesis)
390+
node.get_Processor().ManualRollbackTo(h);
391+
else
392+
node.get_Processor().ForbidActiveAt(0);
393+
394+
node.RefreshCongestions();
395+
}
396+
386397
reactor->run();
387398
}
388399
}

core/block_crypt.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,26 +2612,25 @@ namespace beam
26122612
uint32_t N = Rules::get().CA.m_ProofCfg.get_N();
26132613
assert(N);
26142614

2615-
ECC::Hash::Value hv;
2616-
ECC::Hash::Processor() << skGen >> hv;
2615+
if (aid > N / 2)
2616+
{
2617+
ECC::Hash::Value hv;
2618+
ECC::Hash::Processor() << skGen >> hv;
26172619

2618-
uint32_t nPos;
2619-
hv.ExportWord<0>(nPos);
2620-
nPos %= N; // the position of this element in the list
2620+
uint32_t nPos;
2621+
hv.ExportWord<0>(nPos);
2622+
nPos %= N; // the position of this element in the list
26212623

2622-
if (aid > nPos)
2623-
{
2624-
// TODO: don't exceed the max current asset count, for this we must query it
2625-
m_Begin = aid - nPos;
2626-
}
2627-
else
2628-
{
2629-
m_Begin = 0;
2630-
nPos = aid;
2624+
if (aid > nPos)
2625+
{
2626+
// TODO: don't exceed the max current asset count, for this we must query it
2627+
m_Begin = aid - nPos;
2628+
return nPos;
2629+
}
26312630
}
26322631

2633-
assert(m_Begin + nPos == aid);
2634-
return nPos;
2632+
m_Begin = 0;
2633+
return aid;
26352634
}
26362635

26372636
bool Asset::Proof::IsValid(ECC::Point::Native& hGen, ECC::InnerProduct::BatchContext& bc, ECC::Scalar::Native* pKs) const

core/fly_client.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,10 @@ bool FlyClient::NetworkStd::Connection::IsSupported(RequestEvents& req)
756756

757757
void FlyClient::NetworkStd::Connection::OnRequestData(RequestEvents& req)
758758
{
759+
req.m_Max = (LoginFlags::Extension::get(m_LoginFlags) >= 5) ?
760+
proto::Event::s_Max :
761+
proto::Event::s_Max0;
762+
759763
}
760764

761765
bool FlyClient::NetworkStd::Connection::IsSupported(RequestTransaction& req)
@@ -915,5 +919,14 @@ void FlyClient::NetworkStd::Connection::OnMsg(BbsMsg&& msg)
915919
}
916920
}
917921

922+
void FlyClient::NetworkStd::Connection::OnMsg(EventsSerif&& msg)
923+
{
924+
if (!(Flags::Owned & m_Flags))
925+
ThrowUnexpected();
926+
927+
// TODO: handle complex situation, where multiple owned nodes are connected
928+
m_This.m_Client.OnEventsSerif(msg.m_Value, msg.m_Height);
929+
}
930+
918931
} // namespace proto
919932
} // namespace beam

core/fly_client.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
namespace beam {
2323
namespace proto {
2424

25+
namespace details {
26+
27+
template <typename T> struct ExtraData {
28+
};
29+
30+
template <> struct ExtraData<proto::Events> {
31+
uint32_t m_Max = proto::Event::s_Max;
32+
};
33+
}
34+
2535
struct FlyClient
2636
{
2737
#define REQUEST_TYPES_All(macro) \
@@ -67,7 +77,10 @@ namespace proto {
6777
};
6878

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

91105
struct IBbsReceiver
92106
{
@@ -216,6 +230,7 @@ namespace proto {
216230
virtual void OnMsg(proto::ProofCommonState&& msg) override;
217231
virtual void OnMsg(proto::ProofChainWork&& msg) override;
218232
virtual void OnMsg(proto::BbsMsg&& msg) override;
233+
virtual void OnMsg(proto::EventsSerif&& msg) override;
219234
#define THE_MACRO(type, msgOut, msgIn) \
220235
virtual void OnMsg(proto::msgIn&&) override; \
221236
bool IsSupported(Request##type&); \

core/proto.cpp

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,39 @@ void NodeConnection::OnMsg(SChannelInitiate&& msg)
608608
OnConnectedSecure();
609609
}
610610

611+
void LoginFlags::Extension::set(uint32_t& nFlags, uint32_t nExt)
612+
{
613+
assert(!(nFlags & Msk));
614+
615+
if (nExt < nBitsLegacy)
616+
nExt = (1 << nExt) - 1;
617+
else
618+
nExt = ((nExt - nBitsLegacy + 1) << nBitsLegacy) - 1;
619+
620+
nFlags |= nExt << nShift;
621+
}
622+
623+
uint32_t LoginFlags::Extension::get(uint32_t nFlags)
624+
{
625+
uint32_t val = (Msk & nFlags) >> nShift;
626+
627+
const uint32_t nLegacyVal = (1 << nBitsLegacy) - 1;
628+
if (nLegacyVal == (val & nLegacyVal))
629+
return ((val - nLegacyVal) >> nBitsLegacy) + nBitsLegacy;
630+
631+
// find 1st zero bit
632+
uint32_t iBit = 0;
633+
for (; iBit < nBitsLegacy - 1; iBit++)
634+
if (!(1 & (val >> iBit)))
635+
break;
636+
637+
return iBit;
638+
}
639+
611640
void NodeConnection::SendLogin()
612641
{
613642
Login msg;
614-
msg.m_Flags = LoginFlags::ExtensionsAll;
643+
LoginFlags::Extension::set(msg.m_Flags, LoginFlags::Extension::Maximum);
615644
SetupLogin(msg);
616645

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

731760
void NodeConnection::OnLoginInternal(Login&& msg)
732761
{
733-
if (LoginFlags::ExtensionsBeforeHF1 != (LoginFlags::ExtensionsBeforeHF1 & msg.m_Flags))
734-
{
735-
LOG_WARNING() << "Peer " << m_Connection->peer_address() << " uses legacy protocol";
736-
ThrowUnexpected("Legacy", NodeProcessingException::Type::Incompatible);
737-
}
762+
uint32_t nExt = LoginFlags::Extension::get(msg.m_Flags);
763+
if (LoginFlags::Extension::Maximum != nExt)
764+
{
765+
bool bNewer = (nExt > LoginFlags::Extension::Maximum);
766+
LOG_WARNING() << "Peer " << m_Connection->peer_address() << " uses " << (bNewer ? "newer" : "older") << " ext: " << nExt;
738767

739-
if ((~LoginFlags::Recognized) & msg.m_Flags) {
740-
LOG_WARNING() << "Peer " << m_Connection->peer_address() << " Uses newer protocol.";
741-
}
742-
else
743-
{
744-
const uint32_t nMask = LoginFlags::ExtensionsAll;
745-
uint32_t nFlags2 = nMask & msg.m_Flags;
746-
if (nFlags2 != nMask) {
747-
LOG_WARNING() << "Peer " << m_Connection->peer_address() << " Uses older protocol: " << nFlags2;
748-
}
749-
}
768+
if (nExt < LoginFlags::Extension::Minimum)
769+
ThrowUnexpected("Legacy", NodeProcessingException::Type::Incompatible);
770+
}
750771

751772
OnLogin(std::move(msg));
752773
}

core/proto.h

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ namespace proto {
220220
#define BeamNodeMsg_Events(macro) \
221221
macro(ByteBuffer, Events)
222222

223+
#define BeamNodeMsg_EventsSerif(macro) \
224+
macro(ECC::Hash::Value, Value) \
225+
macro(Height, Height) \
226+
223227
#define BeamNodeMsg_GetBlockFinalization(macro) \
224228
macro(Height, Height) \
225229
macro(Amount, Fees)
@@ -293,6 +297,7 @@ namespace proto {
293297
macro(0x2c, GetEvents) \
294298
macro(0x2d, EventsLegacy) \
295299
macro(0x34, Events) \
300+
macro(0x37, EventsSerif) \
296301
macro(0x2e, GetBlockFinalization) \
297302
macro(0x2f, BlockFinalization) \
298303
/* tx broadcast and replication */ \
@@ -317,21 +322,27 @@ namespace proto {
317322
static const uint32_t Bbs = 0x2; // I'm spreading bbs messages
318323
static const uint32_t SendPeers = 0x4; // Please send me periodically peers recommendations
319324
static const uint32_t MiningFinalization = 0x8; // I want to finalize block construction for my owned node
320-
static const uint32_t Extension1 = 0x10; // Supports Bbs with POW, more advanced proof/disproof scheme for SPV clients (?)
321-
static const uint32_t Extension2 = 0x20; // Supports large HdrPack, BlockPack with parameters
322-
static const uint32_t Extension3 = 0x40; // Supports Login1, Status (former Boolean) for NewTransaction result, compatible with Fork H1
323-
static const uint32_t Extension4 = 0x80; // Supports proto::Events (replaces proto::EventsLegacy)
324-
static const uint32_t Recognized = 0xff;
325325

326+
struct Extension
327+
{
328+
static const uint32_t nShift = 4; // 1st 4 bits are occupied by flags specified above
329+
static const uint32_t nBitsLegacy = 4; // 1st 4 bits are set consequently for each new version
330+
static const uint32_t nBitsExtra = 8;
331+
332+
static const uint32_t Msk = ((1 << (nBitsLegacy + nBitsExtra)) - 1) << nShift;
333+
334+
// 1 - Supports Bbs with POW, more advanced proof/disproof scheme for SPV clients (?)
335+
// 2 - Supports large HdrPack, BlockPack with parameters
336+
// 3 - Supports Login1, Status (former Boolean) for NewTransaction result, compatible with Fork H1
337+
// 4 - Supports proto::Events (replaces proto::EventsLegacy)
338+
// 5 - Supports Events serif, max num of events per message increased from 64 to 1024
326339

327-
static const uint32_t ExtensionsBeforeHF1 =
328-
Extension1 |
329-
Extension2 |
330-
Extension3;
340+
static const uint32_t Minimum = 3;
341+
static const uint32_t Maximum = 5;
331342

332-
static const uint32_t ExtensionsAll =
333-
ExtensionsBeforeHF1 |
334-
Extension4;
343+
static void set(uint32_t& nFlags, uint32_t nExt);
344+
static uint32_t get(uint32_t nFlags);
345+
};
335346
};
336347

337348
struct IDType
@@ -345,7 +356,8 @@ namespace proto {
345356

346357
struct Event
347358
{
348-
static const uint32_t s_Max = 64; // will send more, if the remaining events are on the same height
359+
static const uint32_t s_Max0 = 64;
360+
static const uint32_t s_Max = 1024; // will send more, if the remaining events are on the same height
349361

350362
#define BeamEventsAll(macro) \
351363
macro(1, Utxo) \

0 commit comments

Comments
 (0)