fabric区块链 共识算法

fabric V2.4,在configtx.yaml配置文件中配置smart BFT共识报错
在生成创世区块时,报错‘Profiles[BFTTwoOrgsApplicationGenesis].Orderer' has invalid keys: ConsenterMapping, SmartBFT
我的配置文件具体如下
Organizations:
    - &OrdererOrg
        Name: OrdererOrg
        ID: OrdererMSP
        MSPDir: ./crypto-config/ordererOrganizations/example.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Writers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Admins:
                Type: Signature
                Rule: "OR('OrdererMSP.admin')"

    - &Org1
        Name: Org1MSP
        ID: Org1MSP
        MSPDir: ./crypto-config/peerOrganizations/org1.example.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org1MSP.member')"
            Writers:
                Type: Signature
                Rule: "OR('Org1MSP.member')"
            Admins:
                Type: Signature
                Rule: "OR('Org1MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org1MSP.member')"

        AnchorPeers:
            - Host: peer0.org1.example.com
              Port: 7051

    - &Org2
        Name: Org2MSP
        ID: Org2MSP
        MSPDir: ./crypto-config/peerOrganizations/org2.example.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org2MSP.member')"
            Writers:
                Type: Signature
                Rule: "OR('Org2MSP.member')"
            Admins:
                Type: Signature
                Rule: "OR('Org2MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org2MSP.member')"

        AnchorPeers:
            - Host: peer0.org2.example.com
              Port: 8051


Capabilities:
    Channel: &ChannelCapabilities
        V2_0: true
    Orderer: &OrdererCapabilities
        V2_0: true
    Application: &ApplicationCapabilities
        V2_5: true

Application: &ApplicationDefaults

    Organizations:

    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        LifecycleEndorsement:
            Type: ImplicitMeta
            Rule: "MAJORITY Endorsement"
        Endorsement:
            Type: ImplicitMeta
            Rule: "MAJORITY Endorsement"

    Capabilities:
        <<: *ApplicationCapabilities

Orderer: &OrdererDefaults

    BatchTimeout: 20s

    # Batch Size: Controls the number of messages batched into a block
    BatchSize:

        MaxMessageCount: 10

        AbsoluteMaxBytes: 99 MB

        PreferredMaxBytes: 512 KB

    Organizations:

    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        # BlockValidation specifies what signatures must be included in the block
        # from the orderer for the peer to validate it.
        BlockValidation:
            Type: ImplicitMeta
            Rule: "ANY Writers"

Channel: &ChannelDefaults

    Policies:
        # Who may invoke the 'Deliver' API
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        # Who may invoke the 'Broadcast' API
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        # By default, who may modify elements at this config level
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"

    Capabilities:
        <<: *ChannelCapabilities

Profiles:
    TwoOrgsChannel:
        Consortium: SampleConsortium
        <<: *ChannelDefaults
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
            Capabilities:
                <<: *ApplicationCapabilities
    
    TwoOrgsOrdererGenesis:
        <<: *ChannelDefaults
        Capabilities:
            <<: *ChannelCapabilities
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1
                    - *Org2

    BFTTwoOrgsApplicationGenesis:
        <<: *ChannelDefaults
        Orderer:
            <<: *OrdererDefaults
            Addresses:
                - orderer.example.com:7050
                - orderer1.example.com:8050
                - orderer2.example.com:9050
            Organizations:
                - *OrdererOrg
            Capabilities: *OrdererCapabilities
            OrdererType: BFT
            SmartBFT:
                RequestBatchMaxCount: 100
                RequestBatchMaxInterval: 50ms
                RequestForwardTimeout: 2s
                RequestComplainTimeout: 20s
                RequestAutoRemoveTimeout: 3m0s
                ViewChangeResendInterval: 5s
                ViewChangeTimeout: 20s
                LeaderHeartbeatTimeout: 1m0s
                CollectTimeout: 1s
                RequestBatchMaxBytes: 10485760
                IncomingMessageBufferSize: 200
                RequestPoolSize: 400
                LeaderHeartbeatCount: 10
            ConsenterMapping:
            - ID: 1
              Host: orderer.example.com
              Port: 7050
              MSPID: OrdererMSP
              Identity: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/signcerts/orderer.example.com-cert.pem
              ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
              ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
            - ID: 2
              Host: orderer1.example.com
              Port: 8050
              MSPID: OrdererMSP
              Identity: ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/signcerts/orderer1.example.com-cert.pem
              ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt
              ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt
            - ID: 3
              Host: orderer2.example.com
              Port: 9050
              MSPID: OrdererMSP
              Identity: ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/msp/signcerts/orderer2.example.com-cert.pem
              ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
              ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
            Capabilities: *ApplicationCapabilities
具体报错信息如下所示

img

我的https://img-mid.csdnimg.cn/release/static/image/mid/ask/520643329486144.png "#left")

该怎么改错

如何修改配置文件?

根据您提供的配置文件和报错信息,可以看出问题出在BFTTwoOrgsApplicationGenesis配置中的Orderer部分。报错信息指出SmartBFT和ConsenterMapping是无效的键。这是因为在Fabric v2.4中,SmartBFT和ConsenterMapping不应该在Orderer部分中出现,而应该在Orderer的子部分EtcdRaft中定义。

所以,您需要将SmartBFT和ConsenterMapping移动到Orderer.EtcdRaft的子部分中。以下是您的配置文件进行修改后的示例:

BFTTwoOrgsApplicationGenesis:
  <<: *ChannelDefaults
  Orderer:
    <<: *OrdererDefaults
    OrdererType: etcdraft
    EtcdRaft:
      Consenters:
        - Host: orderer.example.com
          Port: 7050
          ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
          ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
        - Host: orderer1.example.com
          Port: 8050
          ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt
          ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt
        - Host: orderer2.example.com
          Port: 9050
          ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
          ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
      Options:
        RequestTimeout: 2s
        ElectionTick: 10
        HeartbeatTick: 1
        MaxInflightBlocks: 5
        SnapshotIntervalSize: 20 MB
        TickInterval: 500ms
        BatchSize:
          MaxCount: 100
          AbsoluteMaxBytes: 99 MB
          PreferredMaxBytes: 512 KB
        Consenters:
          - Host: orderer.example.com
            Port: 7050
            ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
            ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
          - Host: orderer1.example.com
            Port: 8050
            ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt
            ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt
          - Host: orderer2.example.com
            Port: 9050
            ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
            ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
          - RequestTimeout: 2s
            ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
            ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
            Host: orderer.example.com
            Port: 7050
            Cert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/signcerts/orderer.example.com-cert.pem
            ID: myid
    Capabilities:
      <<: *OrdererCapabilities
    Organizations:
      - *OrdererOrg
  Application:
    <<: *ApplicationDefaults
    Organizations:
      - *Org1
      - *Org2
    Capabilities:
      <<: *ApplicationCapabilities

在上述配置中,Orderer.EtcdRaft子部分中包含了Consenters和Options。Consenters定义了所有的共识节点,包括orderer.example.com、orderer1.example.com和orderer2.example.com,以及它们的TLS证书。Options定义了一些共识相关的选项,例如RequestTimeout、ElectionTick等等。

在Orderer.EtcdRaft的子部分中,您还可以看到ConsenterMapping和SmartBFT被删除了。ConsenterMapping现在是不需要的,因为我们已经在Consenters中显式地定义了所有的共识节点。而SmartBFT则不应该在这里出现,因为它是与etcdraft共识类型无关的。

修改后的配置文件应该可以解决您的问题。如果还有其他问题,请随时问我。

区块链Fabric 之共识机制

可以借鉴下


https://blog.csdn.net/leaning_java/article/details/122837209

1.编写一个插件程序,这个插件程序将添加 Smart BFT 共识协议的实现

2.在 configtx.yaml 文件中声明你的插件,指定 Smart BFT 共识的名称和版本

3.编写并配置你的 orderer.yaml 文件,启用共识插件

答案参考ChatGPT Plus版,整理汇总。希望能帮助你解决问题
根据你提供的配置文件,发现在BFTTwoOrgsApplicationGenesis的配置部分出现了问题。具体报错信息是Profiles[BFTTwoOrgsApplicationGenesis].Orderer的键包含了无效的ConsenterMappingSmartBFT

问题出在以下这段代码:

Orderer:
    <<: *OrdererDefaults
    Addresses:
        - orderer.example.com:7050
        - orderer1.example.com:8050
        - orderer2.example.com:9050
    Organizations:
        - *OrdererOrg
    Capabilities: *OrdererCapabilities
    OrdererType: BFT
    SmartBFT:
        RequestBatchMaxCount: 100
        RequestBatchMaxInterval: 50ms
        RequestForwardTimeout: 2s
        RequestComplainTimeout: 20s
        RequestAutoRemoveTimeout: 3m0s
        ViewChangeResendInterval: 5s
        ViewChangeTimeout: 20s
        LeaderHeartbeatTimeout: 1m0s
        CollectTimeout: 1s
        RequestBatchMaxBytes: 10485760
        IncomingMessageBufferSize: 200
        RequestPoolSize: 400
        LeaderHeartbeatCount: 10
    ConsenterMapping:
    - ID: 1
      Host: orderer.example.com
      Port: 7050
      MSPID: OrdererMSP
      Identity: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/signcerts/orderer.example.com-cert.pem
      ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
      ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
    - ID: 2
      Host: orderer1.example.com
      Port: 8050
      MSPID: OrdererMSP
      Identity: ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/signcerts/orderer1.example.com-cert.pem
      ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt
      ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt
    - ID: 3
      Host: orderer2.example.com
      Port: 9050
      MSPID: OrdererMSP
      Identity: ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/msp/signcerts/orderer2.example.com-cert.pem
      ClientTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
      ServerTLSCert: ./crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt

报错提示了ConsenterMappingSmartBFT这两个键是无效的。原因是在Fabric V2.4中,不再使用ConsenterMappingSmartBFT这样的配置键来定义Smart BFT共识。取而代之的是使用新的配置方式。

如果你想使用Smart BFT共识,可以参考Fabric V2.4的文档,了解新的配置方式,并根据文档进行相应的修改。

希望这可以

帮助你解决问题!

该回答引用GPT与博主@晓码自在合作编写:

根据报错信息,配置文件中Orderer部分的SmartBFT和ConsenterMapping配置错误。SmartBFT为选用的共识算法,ConsenterMapping为共识节点信息。

修改建议如下:

  1. SmartBFT部分,正确配置如下:
yaml
OrdererType: BFT 
SmartBFT:
    RequestBatchMaxCount: 100
    RequestBatchMaxInterval: 50ms
    ......

  1. ConsenterMapping部分,正确配置3个共识节点如下:
yaml
ConsenterMapping:
- ID: 1
  Host: orderer.example.com
  Port: 7050 
  ......
- ID: 2
  Host: orderer1.example.com
  Port: 8050
  ......  
- ID: 3
  Host: orderer2.example.com 
  Port: 9050
  ......

  1. 确保SmartBFT下的参数设置合理。RequestBatchMaxBytes建议设置在10M左右,其他参数默认即可。
  2. 三个orderer的ID、Host、Port和相应cert文件路径设置正确。

修改完成后重新生成创世区块,应该可以成功。SmartBFT共识机制对配置文件要求较高,上面的错误也比较常见。

具体修改见configtx.yaml文件中Profiles下BFTTwoOrgsApplicationGenesis部分。