Skip to content

constants.proto to define protocol constants - #542

Open
vrypan wants to merge 1 commit into
farcasterxyz:mainfrom
vrypan:main
Open

constants.proto to define protocol constants#542
vrypan wants to merge 1 commit into
farcasterxyz:mainfrom
vrypan:main

Conversation

@vrypan

@vrypan vrypan commented Jun 16, 2025

Copy link
Copy Markdown

When using protocol messages, I always have to check and redefine FARCASTER_EPOCH, sometimes in multiple modules in my code.

This PR introduces an idiomatic way to define such constants and make them available to any protobuf consumer (CONST_FARCASTER_EPOCH in this case).

Other constants, such as cast size, longcast size, etc could be added to make it easy for developer to access them.

FARCASTER_EPOCH = 1609459200
@vercel

vercel Bot commented Jun 16, 2025

Copy link
Copy Markdown

@vrypan is attempting to deploy a commit to the farcaster Team on Vercel.

A member of the Team first needs to authorize it.

@vrypan

vrypan commented Jun 16, 2025

Copy link
Copy Markdown
Author

Defining these values at the protobuf level allows easier upgrades to the protocol, if developers use them. For example, changing the size of casts, the max number of embeds, etc, will be automatic when developers upgrade to the newer version, if instead of defining their own constants (up to two embeds per cast, for example), they use the protocol constants.

@sanjayprabhu

Copy link
Copy Markdown
Contributor

Hmm, I like the idea, but not sure protobuf enums are the right fit. Maybe it can be a config file. Let me think about this.

@vrypan

vrypan commented Jun 28, 2025

Copy link
Copy Markdown
Author

Since we define the protocol in protobufs, this is the protobuff-native hack :-) to define constants... A config file will have to be fetched and parsed, etc, ie one more dependency and possible point of failure.

the only problem I see is that you can't have two constants in the same group, with the same value (I think so).

@vrypan

vrypan commented Jun 28, 2025

Copy link
Copy Markdown
Author

How about this.

syntax = "proto3";

message Constants {
    map<string, uint32> values = 1;
}

/*
Defaults: ChcKD0ZBUkNBU1RFUl9FUE9DSBCAzLn/BQ==
*/

The comment is a serialized version of a populated instance of Constants.

A cleaner way would be to have a GetConstants() endpoint return these.

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