Fix and enforce BIP 2 & 3 field ordering #1893

pull nothingmuch wants to merge 3 commits into bitcoin:master from nothingmuch:field-ordering changing 10 files +43 −14
  1. nothingmuch commented at 0:32 am on July 10, 2025: contributor

    The first commit is a scripted diff that corrects field ordering in a number of BIPs which are not consistent with the specified in BIP 2.

    The second commit enforces that fields are ordered consistently with both BIP 2 and BIP 3. It does not strictly depend on #1820.

  2. nothingmuch renamed this:
    Field ordering
    [WIP] Correct and enforce field ordering
    on Jul 10, 2025
  3. nothingmuch force-pushed on Jul 10, 2025
  4. scripted-diff: fix BIP 2 field order violations
    -BEGIN VERIFY SCRIPT-
    set -e
    perl <<'-END PERL-'
    use strict;
    use warnings;
    
    my $topbip = 9999;
    
    my @FieldOrder = qw(
    	BIP
    	Layer
    	Title
    	Author
    	Authors
    	Editor
    	Deputies
    	Discussions-To
    	Comments-Summary
    	Comments-URI
    	Status
    	Type
    	Created
    	License
    	License-Code
    	Discussion
    	Post-History
    	Version
    	Requires
    	Replaces
    	Proposed-Replacement
    	Superseded-By
    );
    
    my $bipnum = 0;
    while (++$bipnum <= $topbip) {
    	my $fn = sprintf "bip-%04d.mediawiki", $bipnum;
    	my $is_markdown = 0;
    	if (!-e $fn) {
    		$fn = sprintf "bip-%04d.md", $bipnum;
    		$is_markdown = 1;
    	}
    	-e $fn || next;
    	open my $F, "<", $fn or die "$!";
    
    	my (@before, %preamble, @after);
    
    	if ($is_markdown) {
    		while (<$F>) {
    			push @before, $_;
    			last if m[^(?:\xef\xbb\xbf)?```$]
    		}
    		die "No ``` in $fn" if eof $F;
    	} else {
    		while (<$F>) {
    			push @before, $_;
    			last if m[^(?:\xef\xbb\xbf)?<pre>$];
    		}
    		die "No <pre> in $fn" if eof $F;
    	}
    	my %found;
    	my ($title, $author, $status, $type, $layer);
    	my ($field, $val, @field_order);
    	while (<$F>) {
    		push @after, $_ and last if ($is_markdown && m[^```$]);
    		push @after, $_ and last if (!$is_markdown && m[^</pre>$]);
    
    		if (m[^  ([\w-]+)\: (.*\S)$]) {
    			$field = $1;
    			$val = $2;
    		} elsif (m[^  ( +)(.*\S)$]) {
    			$val = $2;
    		} else {
    			die "Bad line in $fn preamble";
    		}
    
    		push @{$preamble{$field} ||= []}, $_;
    	}
    	push @after, <$F>;
    	close $F or die $!;
    
    	open my $W, ">", "$fn" or die "$!";
    
    	print $W @before;
    	print $W map { @$_ } grep { defined } delete @preamble{@FieldOrder};
    	die "Unknown fields: @{[ keys %preamble ]}" if %preamble;
    	print $W @after;
    
    	close $W or die $!;
    }
    -END PERL-
    -END VERIFY SCRIPT-
    cfd5d59653
  5. nothingmuch force-pushed on Jul 10, 2025
  6. nothingmuch renamed this:
    [WIP] Correct and enforce field ordering
    Fix and enforce BIP 2 & 3 field ordering
    on Jul 10, 2025
  7. CI: Enforce BIP 2 & 3 field ordering requirements
    The specified field order is consistent with both BIPs 2 and 3. The
    ordering of fields which are only present in one or the other is
    ambiguous, e.g. as in `Proposed-Replacement` and `Superseded-By` but
    only one of these applies to a given BIP.
    
    The `Editor` field is spurious, only being used in BIP 69, and appears
    after Author.
    2bcf4207f1
  8. nothingmuch force-pushed on Jul 10, 2025
  9. nothingmuch marked this as ready for review on Jul 10, 2025
  10. murchandamus requested review from jonatack on Jul 16, 2025
  11. murchandamus added the label Process on Jul 16, 2025
  12. in scripts/buildtable.pl:209 in 2bcf4207f1 outdated
    205@@ -182,13 +206,18 @@
    206 			die "Unknown field $field in $fn";
    207 		}
    208 		++$found{$field};
    209+		push @field_order, $field if $field_order[-1] ne $field;
    


    jonatack commented at 9:31 pm on July 17, 2025:

    Running ./scripts/buildtable.pl on this branch, I am seeing the following messages on each iteration that were not present on master:

    Use of uninitialized value in string ne at ./scripts/buildtable.pl line 209, <$F> line 2.


    jonatack commented at 9:33 pm on July 17, 2025:
     0$ ./scripts/buildtable.pl
     1Use of uninitialized value in string ne at ./scripts/buildtable.pl line 209, <$F> line 2.
     2|- style="background-color: #ffcfcf"
     3| [[bip-0001.mediawiki|1]]
     4|
     5| BIP Purpose and Guidelines
     6| Amir Taaki
     7| Process
     8| Replaced
     9Use of uninitialized value in string ne at ./scripts/buildtable.pl line 209, <$F> line 2.
    10|- style="background-color: #cfffcf"
    11| [[bip-0002.mediawiki|2]]
    12|
    13| BIP process, revised
    14| Luke Dashjr
    15| Process
    16| Active
    17Use of uninitialized value in string ne at ./scripts/buildtable.pl line 209, <$F> line 2.
    18|- style="background-color: #ffffcf"
    19| [[bip-0003.md|3]]
    20|
    21| Updated BIP Process
    22| Murch
    23| Process
    24| Proposed
    25Use of uninitialized value in string ne at ./scripts/buildtable.pl line 209, <$F> line 2.
    

    …/…


    nothingmuch commented at 1:08 pm on July 19, 2025:
    sorry, that was sloppy… i pushed a fixup commit, should i squash it already or would reviewing that on its own be easier?

    jonatack commented at 8:33 pm on July 20, 2025:
    Thanks – rebased the fixup and merged the pull manually.
  13. jonatack commented at 9:32 pm on July 17, 2025: member
    LGTM modulo comment
  14. jonatack added the label PR Author action required on Jul 18, 2025
  15. fixup! CI: Enforce BIP 2 & 3 field ordering requirements b1b024e304
  16. jonatack removed the label PR Author action required on Jul 19, 2025
  17. jonatack commented at 8:34 pm on July 20, 2025: member
    ACK (thanks!), ran and verified the scripted diff and build table change locally. This has been merged with https://github.com/bitcoin/bips/commit/0f8a2269c21ea16bce6e8669a74e71ea03bf28c7.
  18. jonatack closed this on Jul 20, 2025

  19. murchandamus commented at 5:10 pm on July 21, 2025: contributor
    Thanks @nothingmuch and @jonatack for landing this.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bips. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-07-29 16:10 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me