Skip to content

Commit

Permalink
Merge branch 'main' into revert_change
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Apr 4, 2024
2 parents e61efa6 + 4516d0a commit 7a704ab
Show file tree
Hide file tree
Showing 17 changed files with 389 additions and 38 deletions.
4 changes: 2 additions & 2 deletions packages/blobstorage/.default.indexer.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RPC_URL=wss://l1ws.internal.taiko.xyz
BEACON_URL=https://l1beacon.internal.taiko.xyz
RPC_URL=wss://l1ws.hekla.taiko.xyz
BEACON_URL=https://l1beacon.hekla.taiko.xyz
TAIKO_L1_CONTRACT_ADDRESS=0xC069c3d2a9f2479F559AD34485698ad5199C555f
DATABASE_HOST=localhost
DATABASE_PORT=3306
Expand Down
2 changes: 0 additions & 2 deletions packages/blobstorage/blob_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package blobstorage
type BlobHash struct {
BlobHash string
KzgCommitment string
BlockTimestamp uint64
BlobData string
BlockID uint64
EmittedBlockID uint64
Expand All @@ -12,7 +11,6 @@ type BlobHash struct {
type SaveBlobHashOpts struct {
BlobHash string
KzgCommitment string
BlockTimestamp uint64
BlobData string
BlockID uint64
EmittedBlockID uint64
Expand Down
4 changes: 4 additions & 0 deletions packages/blobstorage/indexer/beaconclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net/http"
"strconv"
"time"

"golang.org/x/exp/slog"
)

var (
Expand Down Expand Up @@ -64,6 +66,8 @@ func NewBeaconClient(cfg *Config, timeout time.Duration) (*BeaconClient, error)
return nil, err
}

slog.Info("beaconClientInfo", "secondsPerSlot", secondsPerSlotUint64, "genesisTime", genesisTime)

return &BeaconClient{
beaconURL: cfg.BeaconURL,
genesisTime: genesisTime,
Expand Down
24 changes: 11 additions & 13 deletions packages/blobstorage/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,23 @@ func (i *Indexer) checkReorg(ctx context.Context, event *taikol1.TaikoL1BlockPro
}

func (i *Indexer) storeBlob(ctx context.Context, event *taikol1.TaikoL1BlockProposed) error {
blockID, err := i.beaconClient.timeToSlot(event.Meta.Timestamp)
slot, err := i.beaconClient.timeToSlot(event.Meta.Timestamp)
if err != nil {
return err
}

slog.Info("blockProposed event found", "blockID", blockID, "emittedIn", event.Raw.BlockNumber, "blobUsed", event.Meta.BlobUsed)
slog.Info("blockProposed event found",
"slot", slot,
"emittedIn", event.Raw.BlockNumber,
"blobUsed", event.Meta.BlobUsed,
"timesStamp", event.Meta.Timestamp,
)

if !event.Meta.BlobUsed {
return nil
}

blobsResponse, err := i.beaconClient.getBlobs(ctx, blockID)
blobsResponse, err := i.beaconClient.getBlobs(ctx, slot)
if err != nil {
return err
}
Expand All @@ -306,15 +311,9 @@ func (i *Indexer) storeBlob(ctx context.Context, event *taikol1.TaikoL1BlockProp
metaBlobHash := common.BytesToHash(event.Meta.BlobHash[:])
// Comparing the hex strings of meta.blobHash (blobHash)
if calculateBlobHash(data.KzgCommitment) == metaBlobHash {
blockTs, err := i.getBlockTimestamp(i.cfg.RPCURL, new(big.Int).SetUint64(blockID))
if err != nil {
slog.Error("error getting block timestamp", "error", err)
return err
}

slog.Info("blockHash", "blobHash", metaBlobHash.String())
slog.Info("storing blobHash in db", "blobHash", metaBlobHash.String())

err = i.storeBlobInDB(metaBlobHash.String(), data.KzgCommitment, data.Blob, blockTs, event.BlockId.Uint64(), event.Raw.BlockNumber)
err = i.storeBlobInDB(metaBlobHash.String(), data.KzgCommitment, data.Blob, event.BlockId.Uint64(), event.Raw.BlockNumber)
if err != nil {
slog.Error("Error storing blob in DB", "error", err)
return err
Expand All @@ -327,13 +326,12 @@ func (i *Indexer) storeBlob(ctx context.Context, event *taikol1.TaikoL1BlockProp
return errors.New("BLOB not found")
}

func (i *Indexer) storeBlobInDB(blobHashInMeta, kzgCommitment, blob string, blockTs uint64, blockID uint64, emittedBlockID uint64) error {
func (i *Indexer) storeBlobInDB(blobHashInMeta, kzgCommitment, blob string, blockID uint64, emittedBlockID uint64) error {
return i.blobHashRepo.Save(blobstorage.SaveBlobHashOpts{
BlobHash: blobHashInMeta,
KzgCommitment: kzgCommitment,
BlockID: blockID,
BlobData: blob,
BlockTimestamp: blockTs,
EmittedBlockID: emittedBlockID,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ CREATE TABLE IF NOT EXISTS blob_hashes (
emitted_block_id BIGINT NOT NULL,
blob_hash VARCHAR(100) NOT NULL,
kzg_commitment LONGTEXT NOT NULL,
block_timestamp BIGINT NOT NULL,
blob_data LONGTEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Expand Down
13 changes: 9 additions & 4 deletions packages/blobstorage/pkg/http/get_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ type getBlobResponse struct {
}

type blobData struct {
Blob string `bson:"blob_hash" json:"blob_hash"`
BlobHash string `bson:"blob_hash" json:"blob_hash"`
KzgCommitment string `bson:"kzg_commitment" json:"kzg_commitment"`
Blob string `bson:"blob" json:"blob"`
}

// GetBlob
Expand All @@ -37,6 +38,7 @@ func (srv *Server) GetBlob(c echo.Context) error {
}

data, err := srv.getBlobData(strings.Split(blobHashes, ","))

if err != nil {
return webutils.LogAndRenderErrors(c, http.StatusBadRequest, err)
}
Expand All @@ -48,8 +50,9 @@ func (srv *Server) GetBlob(c echo.Context) error {
// Convert data to the correct type
for _, d := range data {
response.Data = append(response.Data, blobData{
Blob: d.Blob,
BlobHash: d.BlobHash,
KzgCommitment: d.KzgCommitment,
Blob: d.Blob,
},
)
}
Expand All @@ -69,15 +72,17 @@ func (srv *Server) getBlobData(blobHashes []string) ([]blobData, error) {
if err != nil {
if err == gorm.ErrRecordNotFound {
// Handle case where blob hash is not found
result.Blob = "NOT_FOUND"
result.BlobHash = "NOT_FOUND"
result.KzgCommitment = "NOT_FOUND"
result.Blob = "NOT_FOUND"
} else {
// Return error for other types of errors
return nil, err
}
} else {
result.Blob = bh.BlobHash
result.BlobHash = bh.BlobHash
result.KzgCommitment = bh.KzgCommitment
result.Blob = bh.BlobData

results = append(results, result)
}
Expand Down
1 change: 0 additions & 1 deletion packages/blobstorage/pkg/repo/blob_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func (r *BlobHashRepository) Save(opts blobstorage.SaveBlobHashOpts) error {
b := &blobstorage.BlobHash{
BlobHash: opts.BlobHash,
KzgCommitment: opts.KzgCommitment,
BlockTimestamp: opts.BlockTimestamp,
BlobData: opts.BlobData,
BlockID: opts.BlockID,
EmittedBlockID: opts.EmittedBlockID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
{#if displayedRecipient}
{shortenAddress(displayedRecipient, 8, 10)}
{#if displayedRecipient !== $account?.address}
<span class="text-primary-link">| Customized</span>
<span class="text-primary-link">| {$t('common.customized')}</span>
{/if}
{:else}
{$t('recipient.placeholder')}
Expand Down
6 changes: 4 additions & 2 deletions packages/bridge-ui/src/components/Paginator/Paginator.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import { t } from 'svelte-i18n';
import { Icon } from '$components/Icon';
Expand Down Expand Up @@ -41,7 +42,7 @@
<!-- Button to go to previous page -->
<button class={btnClass} on:click={() => goToPage(currentPage - 1)}> <Icon type="chevron-left" /></button>
{/if}
Page
{$t('paginator.page')}
<input
type="number"
class="form-control mx-1 text-center rounded-md py-1 px-8"
Expand All @@ -50,7 +51,8 @@
max={totalPages}
on:keydown={handleKeydown}
on:blur={() => goToPage(currentPage)} />
of {totalPages}
{$t('paginator.of')}
{totalPages}
<!-- Button to go to next page -->
{#if !isLastPage}
<button class={btnClass} on:click={() => goToPage(currentPage + 1)}><Icon type="chevron-right" /></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</div>
<div class="h-sep mt-[20px] mb-0" />
<div class="w-full px-[24px] my-[20px]">
<ActionButton priority="primary" on:click={closeMenu}>See results</ActionButton>
<ActionButton priority="primary" on:click={closeMenu}>{$t('common.see_results')}</ActionButton>
</div>
</div>
<button class="overlay-backdrop" on:click={closeMenu} />
Expand Down
7 changes: 6 additions & 1 deletion packages/bridge-ui/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@
"symbol": "Symbol",
"to": "To",
"token_id": "Token ID",
"token_standard": "Token standard"
"token_standard": "Token standard",
"see_results": "See results"
},
"custom_recipient": {
"placeholder": "Add custom recipient"
Expand Down Expand Up @@ -564,5 +565,9 @@
"connecting": "Connecting",
"disconnected": "Disconnected"
}
},
"paginator": {
"page": "Page",
"of": "of"
}
}
17 changes: 12 additions & 5 deletions packages/bridge-ui/src/libs/token/fetchNFTImageUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { get } from 'svelte/store';

import { destNetwork } from '$components/Bridge/state';
import { fetchNFTMetadata } from '$libs/token/fetchNFTMetadata';
import { decodeBase64ToJson } from '$libs/util/decodeBase64ToJson';
import { getLogger } from '$libs/util/logger';
import { resolveIPFSUri } from '$libs/util/resolveIPFSUri';
import { addMetadataToCache, isMetadataCached } from '$stores/metadata';
Expand Down Expand Up @@ -62,12 +63,18 @@ const fetchImageUrl = async (url: string): Promise<string> => {
return url;
} else {
log('fetchImageUrl failed to load image');
const newUrl = await resolveIPFSUri(url);
if (newUrl) {
const gatewayImageLoaded = await testImageLoad(newUrl);
if (gatewayImageLoaded) {
return newUrl;
if (url.startsWith('ipfs://')) {
const newUrl = await resolveIPFSUri(url);
if (newUrl) {
const gatewayImageLoaded = await testImageLoad(newUrl);
if (gatewayImageLoaded) {
return newUrl;
}
}
} else if (url.startsWith('data:image/svg+xml;base64,')) {
const base64 = url.replace('data:image/svg+xml;base64,', '');
const decodedImage = decodeBase64ToJson(base64);
return decodedImage;
}
}
throw new Error(`No image found for ${url}`);
Expand Down
Loading

0 comments on commit 7a704ab

Please sign in to comment.