/*
 * This file is part of Bisq.
 *
 * Bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * Bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package bisq.core.dao.node.messages;

import bisq.core.dao.node.full.RawBlock;

import bisq.network.p2p.storage.messages.BroadcastMessage;
import bisq.network.p2p.storage.payload.CapabilityRequiringPayload;

import bisq.common.app.Capabilities;
import bisq.common.app.Capability;
import bisq.common.app.Version;
import bisq.common.proto.network.NetworkEnvelope;

import lombok.EqualsAndHashCode;
import lombok.Getter;

// This message is sent only to lite DAO nodes (full nodes get block from their local bitcoind)
@EqualsAndHashCode(callSuper = true)
@Getter
public final class NewBlockBroadcastMessage extends BroadcastMessage implements CapabilityRequiringPayload {
    private final RawBlock block;

    public NewBlockBroadcastMessage(RawBlock block) {
        this(block, Version.getP2PMessageVersion());
    }


    ///////////////////////////////////////////////////////////////////////////////////////////
    // PROTO BUFFER
    ///////////////////////////////////////////////////////////////////////////////////////////

    private NewBlockBroadcastMessage(RawBlock block, int messageVersion) {
        super(messageVersion);
        this.block = block;
    }

    @Override
    public protobuf.NetworkEnvelope toProtoNetworkEnvelope() {
        return getNetworkEnvelopeBuilder()
                .setNewBlockBroadcastMessage(protobuf.NewBlockBroadcastMessage.newBuilder()
                        .setRawBlock(block.toProtoMessage()))
                .build();
    }

    public static NetworkEnvelope fromProto(protobuf.NewBlockBroadcastMessage proto, int messageVersion) {
        return new NewBlockBroadcastMessage(RawBlock.fromProto(proto.getRawBlock()),
                messageVersion);
    }

    @Override
    public Capabilities getRequiredCapabilities() {
        return new Capabilities(Capability.RECEIVE_BSQ_BLOCK);
    }
}

@@ -818,286 +818,459 @@
 ge;%0A
-import bisq.network.p2p.storage.payload.CapabilityRequiringPayload;%0A%0Aimport bisq.common.app.Capabilities;%0Aimport bisq.common.app.Capability;%0Aimport bisq.common.app.Version;%0Aimport bisq.common.proto.network.NetworkEnvelope;%0A%0Aimport lombok.EqualsAndHashCode;%0Aimport lombok.Getter;
+%0Aimport bisq.common.app.Version;%0Aimport bisq.common.proto.network.NetworkEnvelope;%0A%0Aimport lombok.EqualsAndHashCode;%0Aimport lombok.Getter;%0A%0A// We remove the CapabilityRequiringPayload interface to avoid risks that new BSQ blocks are not well distributed in%0A// case the capability is not exchanged at the time when the message is sent. We need to improve the capability handling%0A// so that we can be sure that we know the actual capability of the peer.
 %0A%0A//
@@ -1477,16 +1477,18 @@
 Message 
+/*
 implemen
@@ -1516,16 +1516,18 @@
 gPayload
+*/
  %7B%0A    p
@@ -2556,32 +2556,34 @@
 ersion);%0A    %7D%0A%0A
+//
     @Override%0A  
@@ -2572,32 +2572,34 @@
 //    @Override%0A
+//
     public Capab
@@ -2630,24 +2630,26 @@
 ilities() %7B%0A
+//
         retu
@@ -2699,16 +2699,18 @@
 BLOCK);%0A
+//
     %7D%0A%7D%0A

Remove CapabilityRequiringPayload from NewBlockBroadcastMessage