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