Skip to content

Commit

Permalink
remove tendermint-rpc from config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferret-san committed Dec 10, 2024
1 parent ee8b28c commit fda2c93
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 36 deletions.
43 changes: 15 additions & 28 deletions das/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

node "github.com/celestiaorg/celestia-node/api/rpc/client"
"github.com/celestiaorg/celestia-node/blob"
eds "github.com/celestiaorg/celestia-node/share/eds"
"github.com/celestiaorg/celestia-node/state"
libshare "github.com/celestiaorg/go-square/v2/share"
"github.com/celestiaorg/nitro-das-celestia/celestiagen"
Expand All @@ -25,7 +26,6 @@ import (
"github.com/spf13/pflag"

blobstreamx "github.com/succinctlabs/blobstreamx/bindings"
"github.com/tendermint/tendermint/rpc/client/http"
)

type DAConfig struct {
Expand All @@ -44,7 +44,6 @@ type DAConfig struct {
}

type ValidatorConfig struct {
TendermintRPC string `koanf:"tendermint-rpc" reload:"hot"`
EthClient string `koanf:"eth-rpc" reload:"hot"`
BlobstreamAddr string `koanf:"blobstream"`
}
Expand Down Expand Up @@ -96,7 +95,6 @@ type CelestiaDA struct {
}

type CelestiaProver struct {
Trpc *http.HTTP
EthClient *ethclient.Client
BlobstreamX *blobstreamx.BlobstreamX
}
Expand All @@ -112,7 +110,6 @@ func CelestiaDAConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.String(prefix+".read-auth-token", "", "Auth token for Celestia Node")
f.String(prefix+".keyname", "", "Keyring keyname for Celestia Node for blobs submission")
f.Bool(prefix+".noop-writer", false, "Noop writer (disable posting to celestia)")
f.String(prefix+".validator-config"+".tendermint-rpc", "", "Tendermint RPC endpoint, only used for validation")
f.String(prefix+".validator-config"+".eth-rpc", "", "L1 Websocket connection, only used for validation")
f.String(prefix+".validator-config"+".blobstream", "", "Blobstream address, only used for validation")
f.Bool(prefix+".dangerous-reorg-on-read-failure", false, "DANGEROUS: reorg if any error during reads from celestia node")
Expand Down Expand Up @@ -158,15 +155,6 @@ func NewCelestiaDA(cfg *DAConfig, ethClient *ethclient.Client) (*CelestiaDA, err
}

if cfg.ValidatorConfig != nil {
trpc, err := http.New(cfg.ValidatorConfig.TendermintRPC, "/websocket")
if err != nil {
log.Error("Unable to establish connection with celestia-core tendermint rpc")
return nil, err
}
err = trpc.Start()
if err != nil {
return nil, err
}

var ethRpc *ethclient.Client
if ethClient != nil {
Expand All @@ -190,7 +178,6 @@ func NewCelestiaDA(cfg *DAConfig, ethClient *ethclient.Client) (*CelestiaDA, err
Namespace: &namespace,
KeyName: cfg.KeyName,
Prover: &CelestiaProver{
Trpc: trpc,
EthClient: ethRpc,
BlobstreamX: blobstreamx,
},
Expand All @@ -207,11 +194,6 @@ func NewCelestiaDA(cfg *DAConfig, ethClient *ethclient.Client) (*CelestiaDA, err
}

func (c *CelestiaDA) Stop() error {
err := c.Prover.Trpc.Stop()
if err != nil {
log.Warn("Error stoping tendermint rpc client", "err", err)
return err
}
c.Prover.EthClient.Close()
c.Client.Close()
return nil
Expand Down Expand Up @@ -443,7 +425,7 @@ BlobLoop:
}
}

eds, err := c.ReadClient.Share.GetEDS(ctx, blobPointer.BlockHeight)
extendedSquare, err := c.ReadClient.Share.GetEDS(ctx, blobPointer.BlockHeight)
if err != nil {
return c.returnErrorHelper(fmt.Errorf("failed to get EDS, height=%v, err=%v", blobPointer.BlockHeight, err))
}
Expand Down Expand Up @@ -486,7 +468,7 @@ BlobLoop:

rows := [][][]byte{}
for i := startRow; i <= endRow; i++ {
rows = append(rows, eds.Row(uint(i)))
rows = append(rows, extendedSquare.Row(uint(i)))
}

return &ReadResult{
Expand Down Expand Up @@ -566,16 +548,15 @@ func (c *CelestiaDA) GetProof(ctx context.Context, msg []byte) ([]byte, error) {
}

// get the block data root inclusion proof to the data root tuple root
dataRootProof, err := c.Prover.Trpc.DataRootInclusionProof(ctx, blobPointer.BlockHeight, event.StartBlock, event.EndBlock)
dataRootProof, err := c.ReadClient.Blobstream.GetDataRootTupleInclusionProof(ctx, blobPointer.BlockHeight, event.StartBlock, event.EndBlock)
if err != nil {
log.Warn("could not get data root proof", "err", err)
celestiaValidationFailureCounter.Inc(1)
return nil, err
}

// verify that the data root was committed to by the BlobstreamX contract
sideNodes := make([][32]byte, len(dataRootProof.Proof.Aunts))
for i, aunt := range dataRootProof.Proof.Aunts {
sideNodes := make([][32]byte, len((*dataRootProof).Aunts))
for i, aunt := range (*dataRootProof).Aunts {
sideNodes[i] = *(*[32]byte)(aunt)
}

Expand All @@ -586,8 +567,8 @@ func (c *CelestiaDA) GetProof(ctx context.Context, msg []byte) ([]byte, error) {

proof := blobstreamx.BinaryMerkleProof{
SideNodes: sideNodes,
Key: big.NewInt(dataRootProof.Proof.Index),
NumLeaves: big.NewInt(dataRootProof.Proof.Total),
Key: big.NewInt((*dataRootProof).Index),
NumLeaves: big.NewInt((*dataRootProof).Total),
}

valid, err := c.Prover.BlobstreamX.VerifyAttestation(
Expand All @@ -605,7 +586,13 @@ func (c *CelestiaDA) GetProof(ctx context.Context, msg []byte) ([]byte, error) {
log.Info("Verified Celestia Attestation", "height", blobPointer.BlockHeight, "valid", valid)

if valid {
sharesProof, err := c.Prover.Trpc.ProveShares(ctx, blobPointer.BlockHeight, blobPointer.Start, blobPointer.Start+blobPointer.SharesLength)
extendedSquare, err := c.Client.Share.GetEDS(ctx, blobPointer.BlockHeight)
if err != nil {
celestiaValidationFailureCounter.Inc(1)
log.Error("Unable to get ShareProof", "err", err)
return nil, err
}
sharesProof, err := eds.ProveShares(extendedSquare, int(blobPointer.Start), int(blobPointer.Start+blobPointer.SharesLength))
if err != nil {
celestiaValidationFailureCounter.Inc(1)
log.Error("Unable to get ShareProof", "err", err)
Expand Down
12 changes: 6 additions & 6 deletions das/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package das
import (
"math/big"

"github.com/celestiaorg/celestia-node/nodebuilder/blobstream"
"github.com/tendermint/tendermint/crypto/merkle"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
)

type Namespace struct {
Expand Down Expand Up @@ -86,10 +86,10 @@ func toAttestationProof(
nonce uint64,
height uint64,
blockDataRoot [32]byte,
dataRootInclusionProof *coretypes.ResultDataRootInclusionProof,
dataRootInclusionProof *blobstream.DataRootTupleInclusionProof,
) AttestationProof {
sideNodes := make([][32]byte, len(dataRootInclusionProof.Proof.Aunts))
for i, sideNode := range dataRootInclusionProof.Proof.Aunts {
sideNodes := make([][32]byte, len((*dataRootInclusionProof).Aunts))
for i, sideNode := range (*dataRootInclusionProof).Aunts {
var bzSideNode [32]byte
copy(bzSideNode[:], sideNode)
sideNodes[i] = bzSideNode
Expand All @@ -103,8 +103,8 @@ func toAttestationProof(
},
Proof: BinaryMerkleProof{
SideNodes: sideNodes,
Key: big.NewInt(dataRootInclusionProof.Proof.Index),
NumLeaves: big.NewInt(dataRootInclusionProof.Proof.Total),
Key: big.NewInt((*dataRootInclusionProof).Index),
NumLeaves: big.NewInt((*dataRootInclusionProof).Total),
},
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,5 @@ replace (
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.43.0-tm-v0.34.35
)

replace github.com/ipfs/boxo => github.com/celestiaorg/boxo v0.0.0-20241118122411-70a650316c3b
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7N
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZIuyASInj1a9ExI8xOsTOw=
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ=
github.com/celestiaorg/boxo v0.0.0-20241118122411-70a650316c3b h1:M9X7s1WJ/7Ju84ZUbO/6/8XlODkFsj/ln85AE0F6pj8=
github.com/celestiaorg/boxo v0.0.0-20241118122411-70a650316c3b/go.mod h1:OpUrJtGmZZktUqJvPOtmP8wSfEFcdF/55d3PNCcYLwc=
github.com/celestiaorg/celestia-app/v3 v3.0.2 h1:N9KOGcedhbQpK4XfDZ/OG5za/bV94N4QE72o4gSZ+EA=
github.com/celestiaorg/celestia-app/v3 v3.0.2/go.mod h1:Ut3ytZG2+RcmeCxrYyJ5KOGaFoGnVcShIN+IufyDDSY=
github.com/celestiaorg/celestia-core v1.43.0-tm-v0.34.35 h1:L4GTm+JUXhB0a/nGPMq6jEqqe6THuYSQ8m2kUCtZYqw=
Expand Down Expand Up @@ -1070,8 +1072,6 @@ github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c/go.mod
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.24.0 h1:D9gTU3QdxyjPMlJ6QfqhHTG3TIJPplKzjXLO2J30h9U=
github.com/ipfs/boxo v0.24.0/go.mod h1:iP7xUPpHq2QAmVAjwtQvsNBTxTwLpFuy6ZpiRFwmzDA=
github.com/ipfs/go-block-format v0.2.0 h1:ZqrkxBA2ICbDRbK8KJs/u0O3dlp6gmAuuXUJNiW1Ycs=
github.com/ipfs/go-block-format v0.2.0/go.mod h1:+jpL11nFx5A/SPpsoBn6Bzkra/zaArfSmsknbPMYgzM=
github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
Expand Down

0 comments on commit fda2c93

Please sign in to comment.