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

Basic :: Network Package :: Driver #176

Closed
wants to merge 18 commits into from

Conversation

fabiorigam
Copy link
Member

@fabiorigam fabiorigam commented Oct 30, 2023

I still have to work on tests and improve code, but meanwhile I would like a feedback.

@fabiorigam fabiorigam self-assigned this Oct 30, 2023
@fabiorigam fabiorigam linked an issue Oct 30, 2023 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Oct 30, 2023

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 98%
98.13% (893/910) 94.23% (245/260) 98.82% (168/170)
Title Tests Skipped Failures Errors Time
core 218 0 💤 0 ❌ 0 🔥 59.672s ⏱️
network 12 0 💤 0 ❌ 0 🔥 6.285s ⏱️
errors 25 0 💤 0 ❌ 0 🔥 13.323s ⏱️

Comment on lines 18 to 25
type Slot = ThorStatus['head'] & {
bloom?: ReturnType<typeof bloomUtil.distribute>; // Bloom filter for the block.
block?: Block; // Holds a reference to a blockchain block if available.
accounts: Map<string, Account>; // Map of accounts.
txs: Map<string, Transaction>; // Map of transactions.
receipts: Map<string, TransactionReceipt>; // Map of transaction receipts.
tied: Map<string, unknown>; // Map of tied objects.
};
Copy link
Member

Choose a reason for hiding this comment

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

Define for each driver file a dedicated folder (e.g., for cache.ts a folder named cache).

Inside that folder you'll have cache.ts, types.d.ts & index.ts.

Define types respectively

In the types folder keep shared types between components

Let's keep our codebase structuring 🎖️

/**
* Constant that defines the window length used for determining irreversibility.
*/
const WINDOW_LEN = 12;
Copy link
Member

Choose a reason for hiding this comment

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

I would work with a dedicated consts folder like core package

* Represents a Slot in the cache, combining information about a block, accounts, transactions, receipts, and a tied map.
*/
type Slot = ThorStatus['head'] & {
bloom?: ReturnType<typeof bloomUtil.distribute>; // Bloom filter for the block.
Copy link
Member

Choose a reason for hiding this comment

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

bloom?: bloom.Filter

Comment on lines 69 to 79
bloom:
bloom != null
? bloomUtil.distribute(
bloomUtil.hash(
Buffer.from(bloom.bits.slice(2), 'hex')
),
bloom.k,
2, // ??
(index, bit) => bit === index
)
: undefined,
Copy link
Member

Choose a reason for hiding this comment

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

This is how we generate a bloom filter given bloom and k:

const bloomBuffer = Buffer.from(dataUtils.removePrefix(bloom), 'hex');
const bloomFilter = new bloomInstance.Filter(bloomBuffer, k);

For more details check bloom utils

Copy link
Member

Choose a reason for hiding this comment

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

In this case no need to removePrefix as you are getting the bloom bits. Convert to hex and create the filter

packages/core/src/bloom/bloom.ts Show resolved Hide resolved
/** Wallet interface manages private keys */
interface Wallet {
/** list all keys */
readonly list: WalletKey[];
Copy link
Member

Choose a reason for hiding this comment

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

wording is not clear

Copy link
Member

Choose a reason for hiding this comment

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

WalletKey sounds like an access key.

@@ -46,7 +48,7 @@ class SimpleNet implements Net {
method: 'GET' | 'POST',
path: string,
params?: NetParams
): Promise<unknown> {
): Promise<Block | undefined> {
Copy link
Member

Choose a reason for hiding this comment

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

Why is http now constrained to only returning a Block?

* Retrieves the block based on the provided revision.
* @returns A promise that resolves to the requested block or null if not found.
*/
get: () => Promise<Block | null | undefined>;
Copy link
Member

Choose a reason for hiding this comment

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

same

Comment on lines +13 to +14
sign: ((kind: 'tx', msg: VendorTxMessage) => VendorTxSigningService) &
((kind: 'cert', msg: VendorCertMessage) => VendorCertSigningService);
Copy link
Member

Choose a reason for hiding this comment

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

Same here, extract the function signatures. Let's keep things as simple as possible for readability and maintenance

Comment on lines +50 to +54
interface VMClause {
to: string | null; // Recipient address (or null).
value: string | number; // Value in hex string or number.
data?: string; // Transaction data in hex string (optional).
}
Copy link
Member

Choose a reason for hiding this comment

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

This data type is being duplicated around the codebase. It refers to TransactionClause. Due to the independent nature of packages, I would create a new type in network for the transaction clause but we must keep it with same naming otherwise we create confusion

@@ -44,12 +44,17 @@ class DriverNoVendor {
* @returns A promise that resolves to the requested block.
*/
public async getBlock(
revision: string | number
revision: string | number,
useCache?: boolean
Copy link
Member

Choose a reason for hiding this comment

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

@fabiorigam may be better to put this in at the constructor level, and reference that across all functions

Copy link
Member Author

@fabiorigam fabiorigam Nov 2, 2023

Choose a reason for hiding this comment

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

Thanks for the feedback. We decided we won't implement cache in the first release. And we're thinking another way to better implement driver from scratch.

@fabiorigam fabiorigam closed this Nov 3, 2023
@fabiorigam
Copy link
Member Author

We decided to implement driver from scratch in another way

@rodolfopietro97 rodolfopietro97 deleted the 119-basic-network-package-driver branch November 8, 2023 12:54
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.

Basic :: Network Package :: Driver
3 participants