Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beds 526/Raw DB sdk #947

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open

Conversation

Tangui-Bitfly
Copy link
Contributor

@Tangui-Bitfly Tangui-Bitfly commented Oct 14, 2024

  • add db2.BigTableEthRaw which only purpose is reading from the raw bigtable store
  • db2.BigTableEthRaw is a http.RoundTriper, this allow the caller to use when creating a new ethclient.Client
  • introduce the db2.RawStore to handle all interaction with bigtable satore. There are some duplications here, the aim of this pr is not to refactor everything, it's just to provide an easy to use way of retrieving eth data from bigtable
  • it is used as follow
bt, err := store.NewBigTableWithClient(context.Background(), client, admin, raw)
if err != nil {
	t.Fatal(err)
}

rawStore := NewRawStore(store.Wrap(bt, BlocRawTable, ""))

rpcClient, err := rpc.DialOptions(context.Background(), "http://foo.bar", rpc.WithHTTPClient(&http.Client{
	Transport: NewBigTableEthRaw(rawStore, chainID),
}))
ethClient := ethclient.NewClient(rpcClient)

@Tangui-Bitfly Tangui-Bitfly force-pushed the BEDS-526/fix-internal-tx branch 3 times, most recently from e0b6374 to 1fdf888 Compare October 17, 2024 07:18
@Tangui-Bitfly Tangui-Bitfly force-pushed the BEDS-526/fix-internal-tx branch 7 times, most recently from 86d3841 to cd8bbcb Compare November 6, 2024 14:01
@Tangui-Bitfly Tangui-Bitfly force-pushed the BEDS-526/fix-internal-tx branch 4 times, most recently from c0ec2bc to 2657fae Compare November 18, 2024 08:10
@Tangui-Bitfly Tangui-Bitfly changed the title Beds 526/fix internal tx Beds 526/Raw DB sdk Nov 19, 2024
if err != nil {
t.Fatal(err)
}
ctx := context.Background()

Choose a reason for hiding this comment

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

Suggested change
ctx := context.Background()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's databasetest/bigtable.go is the sim bigtable but controlled through go. I don't really see the need for the context with timeout in that case.

}

func (s *SenderFromDBSigner) ChainID() *big.Int {
panic("can't sign with SenderFromDBSigner")

Choose a reason for hiding this comment

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

Suggested change
panic("can't sign with SenderFromDBSigner")
panic("can't sign with SenderFromDBSigner: ChainID method not supported")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer to modify as little as possible when we "copy" code from somewhere.
The reasoning behind that is: let say in the future the source is update, we propagate this update, but we loose the local change.
So we may introduce a behavior that is prone to change.

panic("can't sign with SenderFromDBSigner")
}
func (s *SenderFromDBSigner) Hash(tx *types.Transaction) common.Hash {
panic("can't sign with SenderFromDBSigner")

Choose a reason for hiding this comment

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

Suggested change
panic("can't sign with SenderFromDBSigner")
panic("can't sign with SenderFromDBSigner: Hash method not supported")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

panic("can't sign with SenderFromDBSigner")
}
func (s *SenderFromDBSigner) SignatureValues(tx *types.Transaction, sig []byte) (R, S, V *big.Int, err error) {
panic("can't sign with SenderFromDBSigner")

Choose a reason for hiding this comment

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

Suggested change
panic("can't sign with SenderFromDBSigner")
panic("can't sign with SenderFromDBSigner: SignatureValues method not supported")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

// copy of senderFromServer
// https://github.com/ethereum/go-ethereum/blob/v1.14.11/ethclient/signer.go#L30
type SenderFromDBSigner struct {
addr common.Address

Choose a reason for hiding this comment

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

Suggested change
addr common.Address
Address common.Address

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

// https://github.com/ethereum/go-ethereum/blob/v1.14.11/ethclient/signer.go#L30
type SenderFromDBSigner struct {
addr common.Address
Blockhash common.Hash

Choose a reason for hiding this comment

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

Suggested change
Blockhash common.Hash
BlockHash common.Hash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

Input string
Output string
Error string
RevertReason string // todo have a look at this, it could improve revert message

Choose a reason for hiding this comment

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

Suggested change
RevertReason string // todo have a look at this, it could improve revert message
RevertReason string // todo have a look at this, it could improve revert message

Is this comment still needed or can we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it for future use. That field provide more context but is not present everywhere. If we change the indexer I want us to think about parsing this field.

@Monika-Bitfly
Copy link

@Tangui-Bitfly Can you update the PR title to align with the template and to reflect the issue being addressed? Thanks! ^^

}
// TODO make warning not found in cache
block, err := c.store.ReadBlockByNumber(chainID, number)
if block != nil {
Copy link

@Monika-Bitfly Monika-Bitfly Nov 20, 2024

Choose a reason for hiding this comment

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

Suggested change
if block != nil {
if err != nil {
return nil, fmt.Errorf("block not found in cache: error %v", err)
}
if block != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No you missed the point here. We don't want to handle the err, it's a cache layer, a passthrough. But we want to save the block in cache if it's not nil.

go c.unCacheBlockAfter(key, "", oneBlockTTL)
return v.(*FullBlockData), nil
}
// TODO make warning not found in cache

Choose a reason for hiding this comment

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

Suggested change
// TODO make warning not found in cache

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No once we have a proper logger I want to log something here

block int64
}{
{
name: "test block",

Choose a reason for hiding this comment

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

The test names could be more descriptive - eg this one we can consider renaming to "Test Block Retrieval" or something similar for better clarity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer to keep it simple.
TestBigTableClient.test_block provide the same amount of info than TestBigTableClient.Test_Block_Retrieval
Or we could rename the test itself rather than the case.
But TestBigTableClient is describing what the test does, so I don't really how to improve it

db2/BigTableEthRaw: add chainID
db2/BigTableEthRaw: handle index for get uncle
db2/BigTableEthRaw: fix with empty tx
db2/BigTableEthRaw: add real condition test
db2/BigTableEthRaw: add WithFallback
db2/BigTableEthRaw: fallback for unsupported method
db2: add cache to raw store (#966)
db2: better cache + client + update store bigtable + clean up
db2/raw: add EthParse
@Tangui-Bitfly
Copy link
Contributor Author

@Tangui-Bitfly Can you update the PR title to align with the template and to reflect the issue being addressed? Thanks! ^^

I'm not sure by what you want me to replace it with. There is no rule on PR name.

@Monika-Bitfly
Copy link

Monika-Bitfly commented Nov 20, 2024

@Tangui-Bitfly Could you please update the PR title to better reflect what this PR is implementing? If you're unsure, you can refer to the doc created by @peterbitfly or other open PRs in this repo eg. PR #1144 for guidance on how to name it. Thanks!

@Tangui-Bitfly
Copy link
Contributor Author

@Tangui-Bitfly Could you please update the PR title to better reflect what this PR is implementing? If you're unsure, you can refer to the doc created by @peterbitfly or other open PRs in this repo eg. PR #1144 for guidance on how to name it. Thanks!

There is no guidance about PR name. Moreover PR are mostly irrelevant now because we don't have merge commit.

@Monika-Bitfly
Copy link

@Tangui-Bitfly Could you please update the PR title to better reflect what this PR is implementing? If you're unsure, you can refer to the doc created by @peterbitfly or other open PRs in this repo eg. PR #1144 for guidance on how to name it. Thanks!

There is no guidance about PR name. Moreover PR are mostly irrelevant now because we don't have merge commit.

I’m not quite sure I understand how PRs are irrelevant now. A good PR title should clearly reflect the changes whether it’s a new feature or a fix. Right now the title doesn’t quite capture what this PR implements or addresses so it would be helpful if you could update it. This will make things clearer for everyone. Here are a couple of articles that can help guide you:
https://graphite.dev/blog/the-best-pr-title-of-all-time
https://blog.montrealanalytics.com/4-tips-for-effective-pull-request-naming-f60793998f04

Let me know if you have any questions, thanks!

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