As a workaround, you could preload a js file that looks for a pattern in certain transactions and start to mine only when all fours are present. For example, if you know all the transaction are from the same address:
var mining_threads = 4;
var txBlock = 0;
var target_address = "0x83c88dbd0059edb45a3e57b9cc50e9ee0fda7190";
var batch = [];
var target_batch = 4;
function waitBatch() {
if ( eth.getBlock( "pending" ).transactions.length > 0 ) {
txBlock = eth.getBlock( "pending" ).number
if ( eth.mining ) return;
console.log( " Transactions pending. Search for target" );
for ( var i = 0; i < eth.getBlock( "pending" ).transactions.length; i++ ) {
if ( eth.getBlock( "pending" ).transactions[ i ].from == target_address ) {
batch.push( eth.getBlock( "pending" ).transactions[ i ] );
}
}
if ( batch.length == target_batch ) {
batch = [];
miner.start( mining_threads )
}
while ( eth.getBlock( "latest" ).number < txBlock + 1 ) {
if ( eth.getBlock( "pending" ).transactions.length > 0 ) txBlock = eth.getBlock( "pending" ).number;
}
console.log( "1 confirmations achieved; mining stopped." );
miner.stop()
} else {
miner.stop()
}
}
waitBatch();
This is not tested and sure has problems, but that's the idea.
Alternatively, you could edit your sealer in your geth if running a private blockchain, but it's almost always a bad idea.
EDIT
I note you want to keep them in order. You can't.
For the vanilla Geth implementation, the commitNewWork() function in worker.go orders in the following way:
//approach 2
transactions := self.eth.TxPool().GetTransactions() <--- fetch from pool
types.SortByPriceAndNonce(transactions) <---------- order
i.e. Sorts by gas price and nonce value
There are two other approaches in the code which are both commented out, but may give a clue as to previous ideas (or give examples to miners who want to use their own implementation). They are:
approach 1: sort by nonce only
approach 3: sort by owner (treating single- and multi-owner transactions differently), then by price and nonce.
You could edit these approaches, if running a private network