Skip to content

Tenscan contract listing#2791

Open
badgersrus wants to merge 30 commits intomainfrom
will/verify-contracts
Open

Tenscan contract listing#2791
badgersrus wants to merge 30 commits intomainfrom
will/verify-contracts

Conversation

@badgersrus
Copy link
Copy Markdown
Contributor

@badgersrus badgersrus commented Dec 17, 2025

Why this change is needed

https://github.com/ten-protocol/ten-internal/issues/6043

This is just the first part of dev, second part will add balances and event logs

What changes were made as part of this PR

  • Add a new goroutine enclave service that periodically fetches the contract data from the enclave. We store the last fetched batch as metadata in the host and each fetch is done from the last fetched batch
  • New table in the host to store the data so we dont jam up the edglessDB
  • Contract listing test is local only because indexing on CI is slow and we don't want to add ~1min to every PR build

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link
Copy Markdown
Contributor

@zkokelj zkokelj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments/questions. Otherwise it looks good to me.

Comment thread go/common/rpc/generated/enclave.proto
Comment thread go/enclave/storage/enclavedb/batch.go Outdated
@badgersrus
Copy link
Copy Markdown
Contributor Author

@zkokelj made a few important changes:

  • Added the limit and sync interval as config so we can easily tweak in a live environment
  • Use the primary key of the contract table to check where we last fetched from as the old version would miss batches if we have an instance where we had more than fetch limit number of contracts in a batch
  • Added a local only sim test to check the new behaviour
  • All the config params are added in this PR

@badgersrus badgersrus requested a review from zkokelj January 16, 2026 15:46
Copy link
Copy Markdown
Contributor

@zkokelj zkokelj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a few minor comments:

  • INT -> BIGINT
  • query optimisation (if possible? otherwise you can keep it as it is)
  • if we decided to not use ID then we can remove it in some places, but also happy if we want to keep that

creator BYTEA NOT NULL,
transparent BOOLEAN NOT NULL,
custom_config BOOLEAN NOT NULL,
batch_seq INT NOT NULL,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those two (batch_seq, height) should be BIGINT to be consistent with uint64 (potential overflow).
just like time (which is ok)

}

var total uint64
reboundCountQuery := db.GetSQLDB().Rebind(selectContractCount)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why are we not using "SELECT total FROM contract_count WHERE id = 1" like we do in GetTotalContractCount?

Comment thread go/common/query_types.go
}

type PublicContract struct {
ID uint64 `json:"id"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ID needed if we decided to remove it?


const (
insertContract = "INSERT INTO contract_host (address, creator, transparent, custom_config, batch_seq, height, time) VALUES (?, ?, ?, ?, ?, ?, ?)"
selectContract = "SELECT id, address, creator, transparent, custom_config, batch_seq, height, time FROM contract_host"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is id here still needed?

var addressBytes, creatorBytes []byte

err = rows.Scan(
&contract.ID,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this ID still needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants