github.com/prysmaticlabs/prysm@v1.4.4/proto/ssz_proto_library.bzl (about) 1 """ 2 SSZ proto templating rules. 3 4 These rules allow for variable substitution for hardcoded tag values like ssz-size and ssz-max. 5 6 """ 7 8 ####### Configuration ####### 9 10 mainnet = { 11 "block_roots.size": "8192,32", # SLOTS_PER_HISTORICAL_ROOT, [32]byte 12 "state_roots.size": "8192,32", # SLOTS_PER_HISTORICAL_ROOT, [32]byte 13 "eth1_data_votes.size": "2048", # SLOTS_PER_ETH1_VOTING_PERIOD 14 "randao_mixes.size": "65536,32", # EPOCHS_PER_HISTORICAL_VECTOR, [32]byte 15 "previous_epoch_attestations.max": "4096", # MAX_ATTESTATIONS * SLOTS_PER_EPOCH 16 "current_epoch_attestations.max": "4096", # MAX_ATTESTATIONS * SLOTS_PER_EPOCH 17 "slashings.size": "8192", # EPOCHS_PER_SLASHINGS_VECTOR 18 "sync_committee_bits.size": "512", #SYNC_COMMITTEE_SIZE 19 "sync_committee_bytes.size": "64", 20 "sync_committee_bits.type": "github.com/prysmaticlabs/go-bitfield.Bitvector512", 21 "sync_committee_aggregate_bytes.size": "16", 22 "sync_committee_aggregate_bits.type": "github.com/prysmaticlabs/go-bitfield.Bitvector128", 23 } 24 25 minimal = { 26 "block_roots.size": "64,32", 27 "state_roots.size": "64,32", 28 "eth1_data_votes.size": "32", 29 "randao_mixes.size": "64,32", 30 "previous_epoch_attestations.max": "1024", 31 "current_epoch_attestations.max": "1024", 32 "slashings.size": "64", 33 "sync_committee_bits.size": "32", 34 "sync_committee_bytes.size": "4", 35 "sync_committee_bits.type": "github.com/prysmaticlabs/go-bitfield.Bitvector32", 36 "sync_committee_aggregate_bytes.size": "1", 37 "sync_committee_aggregate_bits.type": "github.com/prysmaticlabs/go-bitfield.Bitvector8", 38 } 39 40 ###### Rules definitions ####### 41 42 def _ssz_proto_files_impl(ctx): 43 """ 44 ssz_proto_files implementation performs expand_template based on the value of "config". 45 """ 46 outputs = [] 47 if (ctx.attr.config.lower() == "mainnet"): 48 subs = mainnet 49 elif (ctx.attr.config.lower() == "minimal"): 50 subs = minimal 51 else: 52 fail("%s is an unknown configuration" % ctx.attr.config) 53 54 for src in ctx.attr.srcs: 55 output = ctx.actions.declare_file(src.files.to_list()[0].basename) 56 outputs.append(output) 57 ctx.actions.expand_template( 58 template = src.files.to_list()[0], 59 output = output, 60 substitutions = subs, 61 ) 62 63 return [DefaultInfo(files = depset(outputs))] 64 65 ssz_proto_files = rule( 66 implementation = _ssz_proto_files_impl, 67 attrs = { 68 "srcs": attr.label_list(mandatory = True, allow_files = [".proto"]), 69 "config": attr.string(mandatory = True), 70 }, 71 )