Skip to content

Commit 95c5b79

Browse files
fix bad block generation for too many new accounts in full blocks
1 parent 73e14b7 commit 95c5b79

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/node/block/body/generator.cpp

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

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

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

src/shared/src/general/errors.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@
9898
XX(100, EMSGINTEGRITY, "message integrity check failed") \
9999
XX(101, EADDRNOTFOUND, "address not found") \
100100
XX(102, EADDRIDNOTFOUND, "address id not found") \
101-
XX(103, EIDPOLICY2, "block transaction id policy violated") \
102-
XX(104, EIDPOLICY3, "block transaction id policy violated") \
103-
XX(105, EIDPOLICY4, "block transaction id policy violated") \
101+
XX(103, EIDPOLICY2, "block transaction id policy violated 2") \
102+
XX(104, EIDPOLICY3, "block transaction id policy violated 3") \
103+
XX(105, EIDPOLICY4, "block transaction id policy violated 4") \
104104
XX(198, EBATCHSIZE2, "invalid batch size") \
105105
XX(199, EBATCHSIZE3, "invalid batch size") \
106106
XX(200, EINV_HEX, "cannot parse hexadecimal input") \

0 commit comments

Comments
 (0)