Blockchain 停止在geth ethrereum上的私有网络上挖掘

Blockchain 停止在geth ethrereum上的私有网络上挖掘,blockchain,ethereum,mining,Blockchain,Ethereum,Mining,我已经使用下面的客户端启动了一个geth客户端(我已经创建了两个帐户): geth --datadir datadir --networkid 123 --rpc --rpcaddr="localhost" --rpccorsdomain="*" --unlock <my account> --minerthreads="1" --maxpeers=0 --mine console geth--datadir-datadir--networkid 123--rpcaddr=“loc

我已经使用下面的客户端启动了一个geth客户端(我已经创建了两个帐户):

geth --datadir datadir --networkid 123 --rpc --rpcaddr="localhost" --rpccorsdomain="*" --unlock <my account> --minerthreads="1" --maxpeers=0 --mine console
geth--datadir-datadir--networkid 123--rpcaddr=“localhost”--rpccorsdomain=“*”--unlock--minerthreads=“1”--maxpeers=0--mine控制台
我打开以太坊钱包并从那里部署智能合约。交易ID和合约地址在我的
geth
控制台上接收

然后我启动了我的Dapp并创建了契约的实例,我通过Web3API调用契约函数来调用契约。 合同函数被调用,但除非我开始挖掘,否则事务不会在块中提交。 因此,我启动了
miner.start()
这就开始开采许多区块

我的问题是,如果我有自己的私人网络,并且只提交了一笔交易,那么这些区块从何而来。 这会添加太多的块,并且我的块大小会不必要地增加。
如何仅挖掘我已提交的事务?

将以下代码另存为startmine.js文件

var mining_threads = 1

function checkWork() {
    if (eth.getBlock("pending").transactions.length > 0) {
        if (eth.mining) return;
        console.log("== Pending transactions! Mining...");
        miner.start(mining_threads);
    } else {
        miner.stop(0);  // This param means nothing
        console.log("== No transactions! Mining stopped.");
    }
}

eth.filter("latest", function(err, block) { checkWork(); });
eth.filter("pending", function(err, block) { checkWork(); });

checkWork();
并使用以下选项启动geth专用网络

geth .......... . . . . . . .   --rpcapi="web3,eth,miner" --preload "startmine.js" console

当您有任何挂起的事务时,将自动运行miner.start()。

如果您使用的是POA,则使用较新版本的
geth
(至少
1.9.25
),将
期间设置为
0
将停止挖掘,并使节点在挖掘新块之前等待事务。这对于专用网络或实验环境很好

genesis.json:

....
"clique": {
  "period": 0,
  "epoch": 30000
},
....

通过

我认为这不会起作用。即使回调正在发生并且else块正在执行(停止矿工),空块仍然会mined@redeemed在空块中不会有任何挂起的事务,因此挖掘将停止挖掘将停止,但空块将在后台排队,并且除非启动miner,否则不会触发回调。因此,当我启动miner以手动进行回调时,之前排队的空块将立即得到mined@redeemed上面的代码我已经为我的专用网络进行了测试。如果不使用此代码,我的数据块数将达到10万以上,现在低于10万。我已经测试了几天。请不要争辩。看起来这已经得到了回答