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

Maximise reusability of APIs #1997

Open
Tracked by #769
Wodann opened this issue Jan 14, 2025 · 2 comments
Open
Tracked by #769

Maximise reusability of APIs #1997

Wodann opened this issue Jan 14, 2025 · 2 comments

Comments

@Wodann
Copy link
Contributor

Wodann commented Jan 14, 2025

While upgrading I ran into a lot of problems using prior APIs because a lot of APIs no longer expect individual pieces of data but rather receive the "wrapping" CTX type.

To increase reusability, I believe that - where possible - APIs should use the low-level types, rather than the Context generic type. E.g.

pub fn validate_initial_tx_gas<CTX, Error>(
	context: CTX,
	spec_id: SpecId,
) -> Result<InitialAndFloorGas, Error>
where
	CTX: TransactionGetter + CfgGetter,
	Error: From<InvalidTransaction>,
{
	// implementation
}

limits the reusability for locations where you don't have a context. By changing to:

pub fn validate_initial_tx_gas<ConfigT, ErrorT, TransactionT>(
	config: &ConfigT,
	transaction: &TransactionT,
) -> Result<InitialAndFloorGas, ErrorT>
where
	ConfigT: Cfg,
	TransactionT: Transaction,

we can call it when we have a context (validate_initial_tx_gas(context.cfg(), context.tx()) while also being able to call it when we just have a transaction and config type.

For convenience, you can provide helper methods that receive the context and internally call the low-level API that's more reusable.

@rakita
Copy link
Member

rakita commented Jan 14, 2025

We could use even simpler fields:

pub fn validate_initial_tx_gas<Error>(
	tx: &impl Transaction,
	spec_id: SpecId,
) -> Result<InitialAndFloorGas, Error>
	Error: From<InvalidTransaction>,
{
	// implementation
}

@Wodann
Copy link
Contributor Author

Wodann commented Jan 15, 2025

I have a local commit that does this for that function. I'll submit a PR

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

No branches or pull requests

2 participants