@@ -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
0 commit comments