Post

Oracle Module in Cross Chain of BNB chain

Byzantine Fault Tolerance (BFT) ensures reliable consensus in distributed systems, even with faulty or malicious nodes, by leveraging algorithms that involve node selection, proposal, voting, and decision phases to achieve agreement on a consistent state.

Oracle relayer

? Tại sao set key manager is nil? → keyword defer

Khá impact. có thể update db! Nhưng giả sử mình là 1 node trong đó thì sao? thao túng được tất cả hay không? có cơ chế nào tránh sự thao túng này không? ← check oracle module

Query seq:

  • Gen key: prefix 1 byte, chain id 2 byte, channel id 1 byte
  • ABCI query store: /store/sc/key + key

Claim cross chain package log:

  • where oracle_sequence = ? and chain_id = ? and status = ?

Get prophecy:

  • Gen key: GetClaimId(chainId, channelId, sequence)
  • ABCI query: /store/oracle/key + key

append package

claim execute. → broadcast

Oracle module

  • route.go

  • handler.go

    handleClaimMsg:

    New claim include:

    • claim id (msg.chainid, channelID, msg.Sequence)
    • validator address
    • msg.payload

    Get seq ← key value store in keeper

    REQUIRE: msg.seq == seq

    ProccessClaim ← keeper.go

    fail → delete

    not success → return

    decode payload from string to packages[]

    handlePackage(ctx, oracleKeeper, chainID, &pack)

    ….

    handlePackage:

    executeClaim:

  • keeper.go

    ProcessClaim:

    Check valid oracle validator

    REQUIRE: claim≠”” && len(claim.Payload)≠0

    GetProphecy(ctx, claim.ID) ← claim was controlled by oracle relayer

    • Prophecy is not found → create new Prophecy

    REQUIRE: prophecy status is pending

    Add claim (validator address, claim.payload)

    Proccess Completion ← important

    return Prophecy

    processCompletion:

    call highest claim ← highest claim, highest power, total claims power, total power

    why do highestConsensusRatio and highestPossibleConsensusRatio equal 0?

    (!) The precision-adjusted value of the quo() function is 8. Except when highestClaimPower is 0, the result is always 0.

    get consensusNeeded ← kv store

    if highestConsensusRatioconsensusNeeded → set status success, set claim

    else highestPossibleConsensusRatioconsensusNeeded → fail

    return prophecy

  • prophecy.go

    Addclaim:

    Add claimPayload to map ValidatorClaims[valAddr]

    Add addr to map ClaimValidators[claimPayload][]

    FindHighestClaim:

    Get Power of oracle relayer

    for each validators of map claimValidators:

    • accure claim power of this claim to find highest claim
    • total all claims power

    total power ← all power of validators

    return highestClaim, highestClaimPower, totalClaimsPower, totalPower

Oracle module Flow Oracle module Flow

This post is licensed under CC BY 4.0 by the author.