Skip to content

Commit fe23f73

Browse files
merge master: fix bad block generation for too many new accounts in full blocks
2 parents 4018a2c + 95c5b79 commit fe23f73

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

src/node/block/body/generator.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,30 @@ BodyContainer BlockGenerator::gen_block(NonzeroHeight height,
134134
throw std::runtime_error("Too many payments");
135135
}
136136

137-
// filter valid payments to survive self send
138-
std::vector<TransferTxExchangeMessage> validTransfers;
139-
for (auto& pmsg : transfers) {
140-
if (nas.getId(pmsg.toAddr, true).value() == pmsg.from_id()) {
141-
// This should not be possible because self sending transactions
142-
// are detected on entering mempool.
143-
spdlog::warn("Impossible self send detected.");
144-
continue;
145-
}
146-
validTransfers.push_back(pmsg);
147-
}
148137

149138
TransferSection trs;
150-
for (auto& pmsg : validTransfers) {
139+
for (auto& pmsg : transfers) {
151140
size_t size { 10 + nas.binarysize() + RewardSection::binary_size + trs.binarysize() };
152141
assert(size <= MAXBLOCKSIZE);
153142
size_t remaining = MAXBLOCKSIZE - size;
154143
if (remaining < 99)
155144
break;
156145
bool allowNewAddress { remaining >= 99 + 20 };
157146
auto toId = nas.getId(pmsg.toAddr, allowNewAddress);
147+
148+
// filter out invalid self send
149+
if (toId == pmsg.from_id()) {
150+
// This should not be possible because self sending transactions
151+
// are detected on entering mempool.
152+
spdlog::warn("Impossible self send detected.");
153+
// we can continue because nas.getId only assigns a new id to an address if that address
154+
// has not existed before and this cannot happen for toId == pmsg.from_id() because in this case
155+
// the sender must have positive balance (there are no zero value transactions) and therefore
156+
// has existed in the chain before.
157+
// => we know that nas.getId did not assign a new account id to pmsg.toAddr so we can continue without
158+
// violating block policy that every account Id must be referred.
159+
continue;
160+
}
158161
if (!toId)
159162
break;
160163

src/node/chainserver/state/transactions/block_applier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ Preparation BlockApplier::Preparer::prepare(const BodyView& bv, const NonzeroHei
298298
for (size_t i = 0; i < newAccounts.size(); ++i) {
299299
auto& acc = newAccounts[i];
300300
if (acc.in().is_zero()) {
301-
throw Error(EIDPOLICY); // id was not referred
301+
throw Error(EIDNOTREFERENCED); // id was not referred
302302
}
303303
if (acc.out() > Funds::zero()) // Not (acc.out() > acc.in()) because we do not like chains of new accounts
304304
throw Error(EBALANCE); // insufficient balance

src/shared/src/general/errors.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
XX(17, EMROOT, "merkle root mismatch") \
4141
XX(18, ENOBLOCK, "peer did not provide block") \
4242
XX(19, EUNREQUESTED, "received unrequested message") \
43-
XX(20, EIDPOLICY, "block transaction id policy violated") \
43+
XX(20, EIDNOTREFERENCED, "account id not referenced") \
4444
XX(21, EADDRPOLICY, "new address policy violated") \
4545
XX(22, EBALANCE, "insufficient balance") \
4646
XX(23, ECORRUPTEDSIG, "corrupted signature") \
@@ -128,6 +128,7 @@
128128
XX(128, EFROZENACC, "account is frozen and can't send") \
129129
XX(129, EHEADERRANGE, "invalid header range") \
130130
XX(130, ERTCDISABLED, "WebRTC disabled, cannot receive message") \
131+
XX(131, EIDPOLICY, "block transaction id policy violated") \
131132
XX(198, EBATCHSIZE2, "invalid batch size") \
132133
XX(199, EBATCHSIZE3, "invalid batch size") \
133134
/*200 - 299: Errors not leading to ban*/ \

0 commit comments

Comments
 (0)