In substrate-node-template, are there any available ways to execute a task or provide a callback to be executed just before the block gets gossiped to other validators, right after it has produced the block?

  • First you say before it gets gossiped and then before it gets produced. These are different stages. Could you also give more examples on what you want to do with this callback?
    – bkchr
    Apr 2, 2023 at 21:41
  • @bkchr oh sorry i meant right after i produce the block which is supposedly exactly before gossiping, but yeah just before gossiping is what i meant, i want to put a value(a bunch of signatures Vec<Vec<u8>> in the dht, (i raised some concerns about the dht here
    – dadzerlaze
    Apr 3, 2023 at 9:40
  • What kind of extra information?
    – bkchr
    Apr 4, 2023 at 19:26
  • @bkchr i want to add the author multiaddr, so just a string
    – dadzerlaze
    Apr 5, 2023 at 8:39
  • You could use authority discovery to lookup the multiaddr of the validator?
    – bkchr
    Apr 5, 2023 at 14:10

1 Answer 1


If you want to do some work before announcing a block to the network, you can do it the following way. You will need to change this code to something like this:

   // Don't let the internals announce the block automatically
   config.announce_block = false;
   // Start the network etc.
   let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
        sc_service::build_network(sc_service::BuildNetworkParams {
            config: &config,
            client: client.clone(),
            transaction_pool: transaction_pool.clone(),
            spawn_handle: task_manager.spawn_handle(),
            block_announce_validator_builder: None,
            warp_sync_params: Some(WarpSyncParams::WithProvider(warp_sync)),
    let block_import = client.import_notification_stream();
    let custom_block_announce = async move {
        while let Some(import) = block_import.next().await {
            // If the local node produced the block
            if import.origin == BlockOrigin::Own {
                // Insert your special logic here

            // Announce the block to the network
            sync_service.announce_block(import.hash, None);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.