private Map<Address, Long> maxNonceBySender(final List<Transaction> confirmedTransactions) {
    record SenderNonce(Address sender, long nonce) {}

    return confirmedTransactions.stream()
        .<SenderNonce>mapMulti(
            (transaction, consumer) -> {
              // always consider the sender
              consumer.accept(new SenderNonce(transaction.getSender(), transaction.getNonce()));

              // and if a code delegation tx also the authorities
              if (transaction.getType().supportsDelegateCode()) {
                transaction.getCodeDelegationList().get().stream()
                    .map(cd -> cd.authorizer().map(address -> new SenderNonce(address, cd.nonce())))
                    .filter(Optional::isPresent)
                    .map(Optional::get)
                    .forEach(consumer);
              }
            })
        .collect(
            groupingBy(SenderNonce::sender, mapping(SenderNonce::nonce, reducing(0L, Math::max))));
  }
Rebuild the txpool for a sender according to the specified nonce. This is used in case the
account nonce has seen by the txpool is not the correct one (see {@link
LayeredPendingTransactions#hasAccountNonceDisparity(PendingTransaction, long)} for when this
could happen). It works by removing all the txs for the sender and re-adding them using the
passed nonce.

@param sender the sender for which rebuild the txpool
@param stateSenderNonce the world state account nonce to use in the txpool for the sender
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactions.java