/* Test local modifications to gossmap */
#include "config.h"
#include "../amount.c"
#include "../fp16.c"
#include "../gossmap.c"
#include "../node_id.c"
#include "../pseudorand.c"
#include <ccan/read_write_all/read_write_all.h>
#include <common/channel_type.h>
#include <common/setup.h>
#include <common/utils.h>
#include <stdio.h>

/* AUTOGENERATED MOCKS START */
/* Generated stub for fromwire_bigsize */
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
/* Generated stub for fromwire_channel_id */
bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
			 struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
/* Generated stub for sciddir_or_pubkey_from_node_id */
bool sciddir_or_pubkey_from_node_id(struct sciddir_or_pubkey *sciddpk UNNEEDED,
				    const struct node_id *node_id UNNEEDED)
{ fprintf(stderr, "sciddir_or_pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for towire_bigsize */
void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
{ fprintf(stderr, "towire_bigsize called!\n"); abort(); }
/* Generated stub for towire_channel_id */
void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED)
{ fprintf(stderr, "towire_channel_id called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

/* Canned gossmap, taken from tests/test_gossip.py, with channels mined.
 * $> od -tx1 -Anone -v < /tmp/ltests-rtchpzh1/test_gossip_store_compact_noappend_1/lightning-2/regtest/gossip_store  | sed 's/ / 0x/g'| cut -c2- | sed -e 's/ /,/g' -e 's/$/,/'
 */
static u8 canned_map[] = {
	0x0f,0x20,0x00,0x01,0xb0,0x6e,0x30,0x94,0x60,0x65,0x55,0xb3,0x60,0x01,0x00,0x00,
	0x33,0x57,0x33,0xf5,0x94,0x2d,0xf5,0xd9,0x50,0xeb,0x87,0x66,0xde,0xe3,0xa9,0xd6,
	0x62,0x69,0x22,0x84,0x4e,0xd6,0xae,0x7a,0x11,0x0d,0xd7,0xe7,0xed,0xc3,0x2e,0x3f,
	0x6f,0x3d,0x9a,0xc5,0xcd,0xea,0x23,0xce,0x25,0xbb,0x8d,0xbf,0x76,0x1f,0xd3,0xd5,
	0xfc,0x56,0xc0,0x5b,0x68,0x56,0x31,0x6d,0x12,0xe9,0xd3,0x2c,0xa0,0xf0,0x8c,0x69,
	0xca,0x03,0x06,0xfe,0x71,0x6e,0x7b,0x51,0x51,0x31,0x7d,0x64,0x40,0xb7,0x37,0x3d,
	0x9f,0xbc,0x64,0x6e,0xad,0x48,0xf2,0x16,0x3f,0x2b,0x6d,0x51,0x1a,0xfe,0x6a,0x79,
	0xc7,0x55,0x51,0xc2,0x62,0x0f,0xc8,0x09,0x74,0xf2,0xf8,0x64,0x32,0x9d,0x97,0x78,
	0xa0,0x8c,0xdf,0xbc,0x9f,0x2c,0x9c,0x13,0x44,0xc4,0x32,0x70,0x2c,0x66,0x80,0x7c,
	0xfb,0x4d,0xb6,0x9b,0x80,0xfa,0xe8,0xc3,0x3c,0x70,0x14,0x3d,0x94,0x8b,0x36,0x61,
	0x4d,0x62,0x08,0x91,0xbe,0xe2,0xdf,0x99,0xc8,0x6b,0xc6,0x22,0x07,0xc1,0x7e,0x3b,
	0x91,0x86,0x21,0x4c,0x0c,0xcf,0xf2,0xde,0xd5,0x59,0x8a,0xcc,0xc9,0x0e,0xb1,0xd5,
	0xb2,0xf7,0xa8,0x3c,0xd7,0xf6,0x8d,0x71,0x2e,0xa0,0x47,0xd8,0x01,0x9f,0x34,0x30,
	0x63,0xb0,0xa2,0x36,0x35,0x6a,0x38,0x71,0x46,0xf5,0x8f,0xa8,0x32,0xdd,0xc1,0x3c,
	0x47,0x14,0x52,0x2c,0xbb,0x50,0x3f,0x5f,0x3c,0xa8,0xfc,0xec,0x66,0x02,0xbe,0x24,
	0x38,0xad,0x3f,0x98,0xfa,0x0c,0xee,0xd5,0x8f,0xe3,0xa0,0x66,0xd3,0x85,0xfc,0xac,
	0xd9,0x8c,0x70,0x4b,0x2a,0x8e,0x98,0xa3,0xe2,0x0b,0xf7,0x6b,0x35,0xb7,0x36,0x00,
	0x00,0x06,0x22,0x6e,0x46,0x11,0x1a,0x0b,0x59,0xca,0xaf,0x12,0x60,0x43,0xeb,0x5b,
	0xbf,0x28,0xc3,0x4f,0x3a,0x5e,0x33,0x2a,0x1f,0xc7,0xb2,0xb7,0x3c,0xf1,0x88,0x91,
	0x0f,0x00,0x00,0x67,0x00,0x00,0x01,0x00,0x00,0x02,0x2d,0x22,0x36,0x20,0xa3,0x59,
	0xa4,0x7f,0xf7,0xf7,0xac,0x44,0x7c,0x85,0xc4,0x6c,0x92,0x3d,0xa5,0x33,0x89,0x22,
	0x1a,0x00,0x54,0xc1,0x1c,0x1e,0x3c,0xa3,0x1d,0x59,0x03,0x5d,0x2b,0x11,0x92,0xdf,
	0xba,0x13,0x4e,0x10,0xe5,0x40,0x87,0x5d,0x36,0x6e,0xbc,0x8b,0xc3,0x53,0xd5,0xaa,
	0x76,0x6b,0x80,0xc0,0x90,0xb3,0x9c,0x3a,0x5d,0x88,0x5d,0x02,0x90,0x53,0x52,0x1d,
	0x6e,0xa7,0xa5,0x2c,0xdd,0x55,0xf7,0x33,0xd0,0xfb,0x2d,0x07,0x7c,0x03,0x73,0xb0,
	0x05,0x3b,0x5b,0x81,0x0d,0x92,0x72,0x44,0x06,0x1b,0x75,0x73,0x02,0xd6,0x06,0x3d,
	0x02,0x26,0x91,0xb2,0x49,0x0a,0xb4,0x54,0xde,0xe7,0x3a,0x57,0xc6,0xff,0x5d,0x30,
	0x83,0x52,0xb4,0x61,0xec,0xe6,0x9f,0x3c,0x28,0x4f,0x2c,0x24,0x12,0x20,0x00,0x00,
	0x0a,0x91,0x11,0x83,0xf6,0x00,0x00,0x00,0x00,0x10,0x05,0x00,0x00,0x00,0x00,0x00,
	0x0f,0x42,0x40,0xa0,0x00,0x00,0x8a,0xc5,0x33,0xff,0x38,0x65,0x55,0xb3,0x60,0x01,
	0x02,0x2f,0xd9,0x23,0x60,0x1e,0x1c,0xa0,0xac,0xe5,0x06,0x8c,0xe4,0x8e,0x14,0xf3,
	0xcd,0x31,0x44,0x16,0xc4,0x0d,0x2e,0x14,0x8c,0xa1,0xc8,0x4f,0xa6,0xa8,0xe4,0x64,
	0x9b,0x45,0x79,0xd1,0xb5,0x2f,0x04,0x19,0x86,0xe5,0x5c,0x99,0x43,0xf1,0xd0,0xf3,
	0x6f,0x52,0xd6,0x88,0xf0,0x9b,0x9c,0x58,0x98,0x69,0x0d,0x4e,0x76,0x3e,0xbd,0x6e,
	0x95,0x06,0x22,0x6e,0x46,0x11,0x1a,0x0b,0x59,0xca,0xaf,0x12,0x60,0x43,0xeb,0x5b,
	0xbf,0x28,0xc3,0x4f,0x3a,0x5e,0x33,0x2a,0x1f,0xc7,0xb2,0xb7,0x3c,0xf1,0x88,0x91,
	0x0f,0x00,0x00,0x67,0x00,0x00,0x01,0x00,0x00,0x65,0x55,0xb3,0x60,0x01,0x00,0x00,
	0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
	0x0a,0x00,0x00,0x00,0x00,0x3b,0x02,0x33,0x80,0x20,0x00,0x00,0x95,0x97,0xd7,0xa4,
	0x39,0x65,0x55,0xb3,0x65,0x01,0x01,0x36,0x59,0x20,0x77,0x0e,0xf4,0x73,0x10,0xd7,
	0xb6,0x59,0x5a,0x7c,0xbe,0xd0,0x56,0x51,0x3d,0x97,0xbe,0x84,0xb7,0x02,0xb5,0x89,
	0x72,0xbd,0xb3,0x19,0x2a,0x54,0x5f,0x57,0x52,0x09,0x1d,0xff,0x0f,0xe6,0x70,0x1e,
	0x71,0x23,0xaa,0x3f,0x98,0x89,0x86,0x35,0x87,0xc2,0x66,0xd9,0x99,0xbd,0xa2,0x7e,
	0x16,0x12,0xd9,0x6b,0xc4,0xd3,0x0c,0x00,0x07,0x88,0xa0,0x00,0x0a,0x0a,0x69,0xa2,
	0x65,0x55,0xb3,0x65,0x02,0x2d,0x22,0x36,0x20,0xa3,0x59,0xa4,0x7f,0xf7,0xf7,0xac,
	0x44,0x7c,0x85,0xc4,0x6c,0x92,0x3d,0xa5,0x33,0x89,0x22,0x1a,0x00,0x54,0xc1,0x1c,
	0x1e,0x3c,0xa3,0x1d,0x59,0x02,0x2d,0x22,0x53,0x49,0x4c,0x45,0x4e,0x54,0x41,0x52,
	0x54,0x49,0x53,0x54,0x2d,0x31,0x2d,0x31,0x2d,0x67,0x63,0x63,0x65,0x34,0x66,0x36,
	0x38,0x2d,0x6d,0x6f,0x64,0x64,0x65,0x64,0x00,0x00,0xa0,0x00,0x00,0x8a,0xd0,0xde,
	0x20,0xc6,0x65,0x55,0xb3,0x60,0x01,0x02,0x11,0xd6,0x4b,0xc5,0x88,0x33,0x4b,0x6c,
	0x1e,0x0c,0x4c,0x5c,0x65,0x69,0x35,0x66,0x45,0x80,0xbc,0x4b,0x56,0x3d,0x98,0x2c,
	0xb3,0x45,0xef,0x22,0x44,0x6e,0xca,0x6c,0x1f,0xe9,0x2a,0xf2,0x4a,0xe1,0x26,0xdb,
	0x15,0x6f,0x7e,0x3b,0xdd,0xd3,0x40,0x54,0xb2,0xc7,0x07,0xfe,0x67,0xb0,0xf3,0x35,
	0x56,0x25,0xc6,0x53,0xfd,0x54,0x56,0x5e,0x06,0x22,0x6e,0x46,0x11,0x1a,0x0b,0x59,
	0xca,0xaf,0x12,0x60,0x43,0xeb,0x5b,0xbf,0x28,0xc3,0x4f,0x3a,0x5e,0x33,0x2a,0x1f,
	0xc7,0xb2,0xb7,0x3c,0xf1,0x88,0x91,0x0f,0x00,0x00,0x67,0x00,0x00,0x01,0x00,0x00,
	0x65,0x55,0xb3,0x60,0x01,0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x3b,0x02,0x33,0x80,
	0x20,0x00,0x00,0x95,0x87,0xf8,0x92,0xf3,0x65,0x55,0xb3,0x65,0x01,0x01,0x32,0x6c,
	0xde,0x4a,0xc5,0xe8,0xd4,0xa0,0xed,0xbc,0x2c,0x13,0x5e,0xb9,0x1e,0xc3,0xc3,0x86,
	0xcb,0x75,0xeb,0x6f,0xce,0xc5,0xc5,0x57,0x01,0x1c,0x9c,0xb7,0x32,0x17,0x01,0x10,
	0x8c,0xdd,0x04,0x31,0x78,0xae,0xb4,0x88,0x8d,0xf8,0xe8,0x35,0x90,0x69,0x91,0x84,
	0xd0,0x16,0xd8,0x44,0xbc,0xde,0x37,0xe8,0x4e,0x1a,0x95,0xb6,0xa6,0x73,0x00,0x07,
	0x88,0xa0,0x00,0x0a,0x0a,0x69,0xa2,0x65,0x55,0xb3,0x65,0x03,0x5d,0x2b,0x11,0x92,
	0xdf,0xba,0x13,0x4e,0x10,0xe5,0x40,0x87,0x5d,0x36,0x6e,0xbc,0x8b,0xc3,0x53,0xd5,
	0xaa,0x76,0x6b,0x80,0xc0,0x90,0xb3,0x9c,0x3a,0x5d,0x88,0x5d,0x03,0x5d,0x2b,0x48,
	0x4f,0x50,0x50,0x49,0x4e,0x47,0x46,0x49,0x52,0x45,0x2d,0x63,0x31,0x2d,0x31,0x2d,
	0x67,0x63,0x63,0x65,0x34,0x66,0x36,0x38,0x2d,0x6d,0x6f,0x64,0x64,0x65,0x64,0x00,
	0x00,0x20,0x00,0x00,0x8a,0xcb,0xd4,0xc7,0xa1,0x65,0x55,0xb3,0x65,0x01,0x02,0x1d,
	0x3f,0x42,0x7f,0x3d,0xdb,0x58,0x2b,0xcb,0x78,0x5d,0x24,0xf1,0x67,0xc6,0xc7,0xd8,
	0x6e,0x6c,0x5b,0xf8,0xfb,0x27,0x17,0x58,0xaa,0x7e,0x46,0x86,0x49,0x66,0x21,0x47,
	0x76,0xbd,0xf2,0x2d,0xae,0x29,0xf0,0x6f,0x17,0x6e,0xf2,0x7f,0x01,0xda,0x16,0xa9,
	0x1d,0x6a,0x61,0x4c,0x41,0x71,0x19,0x4d,0x37,0xac,0x8a,0x28,0xd8,0x62,0xfb,0x06,
	0x22,0x6e,0x46,0x11,0x1a,0x0b,0x59,0xca,0xaf,0x12,0x60,0x43,0xeb,0x5b,0xbf,0x28,
	0xc3,0x4f,0x3a,0x5e,0x33,0x2a,0x1f,0xc7,0xb2,0xb7,0x3c,0xf1,0x88,0x91,0x0f,0x00,
	0x00,0x67,0x00,0x00,0x01,0x00,0x00,0x65,0x55,0xb3,0x65,0x01,0x00,0x00,0x06,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x03,0xe8,0x00,
	0x00,0x00,0x00,0x3b,0x02,0x33,0x80,0x20,0x00,0x00,0x8a,0xbf,0x0d,0x7a,0xbc,0x65,
	0x55,0xb3,0x6f,0x01,0x02,0x59,0xc9,0x36,0x84,0xaa,0x13,0x70,0x73,0x7d,0xa7,0xe6,
	0x8a,0x72,0x05,0x15,0xa9,0x06,0x69,0xe0,0xc0,0x0d,0x15,0x6d,0x22,0x5c,0xd6,0x1a,
	0x3e,0x56,0xaa,0x9d,0x98,0x68,0x5a,0x3c,0xdc,0x38,0x71,0xee,0x0d,0x02,0x3e,0x2f,
	0xd0,0x97,0xd7,0xab,0xe2,0x0d,0xdf,0xf5,0xa6,0xd1,0x9c,0xb6,0xb9,0x30,0xd6,0xdd,
	0x10,0xa7,0xa3,0xce,0x5e,0x06,0x22,0x6e,0x46,0x11,0x1a,0x0b,0x59,0xca,0xaf,0x12,
	0x60,0x43,0xeb,0x5b,0xbf,0x28,0xc3,0x4f,0x3a,0x5e,0x33,0x2a,0x1f,0xc7,0xb2,0xb7,
	0x3c,0xf1,0x88,0x91,0x0f,0x00,0x00,0x67,0x00,0x00,0x01,0x00,0x00,0x65,0x55,0xb3,
	0x6f,0x01,0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x14,0x00,0x00,0x03,0xe8,0x00,0x00,0x00,0x00,0x3b,0x02,0x33,0x80,0x20,0x00,0x01,
	0xb0,0xb8,0x17,0x71,0xe9,0x65,0x55,0xb3,0x71,0x01,0x00,0x0d,0xef,0xc0,0x12,0x4f,
	0xd4,0xe4,0x1c,0xce,0xc3,0xf4,0x83,0x17,0x21,0x7e,0x33,0x11,0x5a,0x8f,0x8c,0x39,
	0xae,0xbb,0x06,0x2b,0x4e,0x73,0xa6,0x52,0xee,0x0e,0x61,0x03,0xf9,0xf1,0x16,0x7b,
	0x22,0xbd,0xcb,0x92,0xcf,0x82,0x2d,0x0f,0xcc,0x26,0xcb,0x11,0x9f,0x0a,0xf5,0x23,
	0xf4,0x26,0x97,0x86,0x7e,0x21,0x51,0x85,0x16,0x3a,0x0e,0x4b,0x1f,0x64,0xf3,0x62,
	0xf4,0x2f,0x13,0x54,0x5c,0x9a,0xed,0xd6,0x9d,0x5d,0xf5,0x17,0x85,0xcc,0x5d,0x53,
	0xa4,0x84,0x36,0x9b,0xe9,0xa7,0x4a,0x04,0x1f,0x8c,0x1c,0x28,0xc7,0x1e,0xab,0xb3,
	0xf2,0x53,0x3d,0xf8,0xb6,0xcd,0xd8,0x45,0x6e,0xc3,0x77,0xdb,0xb1,0x2b,0xa5,0xdd,
	0xc9,0xbf,0x69,0xa7,0xdf,0x98,0x2c,0x54,0xa7,0xa8,0xf5,0x4f,0xc3,0xd1,0x57,0x81,
	0x98,0x60,0xa0,0xb6,0x32,0x83,0x08,0x65,0x1e,0x79,0x24,0xf4,0xbe,0xfe,0x14,0xa6,
	0xfd,0x31,0x9b,0xfa,0x15,0x6f,0x1b,0xab,0x64,0x8b,0x69,0x48,0xb4,0x2e,0x99,0xca,
	0xd7,0x46,0x97,0x57,0x17,0x1d,0x5d,0x53,0xe5,0xde,0xae,0xbb,0x2d,0x74,0x86,0xa5,
	0xe5,0x8e,0x02,0x5c,0x2c,0x8d,0x0d,0x78,0xdc,0xf1,0xa0,0x05,0xb8,0xbd,0x64,0x7d,
	0x51,0x47,0x5e,0x39,0xaa,0x08,0x2d,0xf2,0xd0,0x1a,0x96,0x59,0xab,0x88,0x94,0xa2,
	0xf7,0x2e,0x09,0x3b,0xd0,0xed,0xfc,0xb4,0x1b,0xaa,0xba,0x34,0xf8,0x7b,0x11,0x51,
	0x36,0x7b,0x13,0x84,0x6f,0xc9,0x4a,0x58,0x92,0x3c,0x0c,0xa2,0x4c,0x8f,0xc5,0x78,
	0xb4,0x4a,0xad,0x98,0x08,0x4e,0x4a,0xf3,0x7a,0x28,0x80,0x00,0x00,0x06,0x22,0x6e,
	0x46,0x11,0x1a,0x0b,0x59,0xca,0xaf,0x12,0x60,0x43,0xeb,0x5b,0xbf,0x28,0xc3,0x4f,
	0x3a,0x5e,0x33,0x2a,0x1f,0xc7,0xb2,0xb7,0x3c,0xf1,0x88,0x91,0x0f,0x00,0x00,0x6e,
	0x00,0x00,0x01,0x00,0x00,0x02,0x2d,0x22,0x36,0x20,0xa3,0x59,0xa4,0x7f,0xf7,0xf7,
	0xac,0x44,0x7c,0x85,0xc4,0x6c,0x92,0x3d,0xa5,0x33,0x89,0x22,0x1a,0x00,0x54,0xc1,
	0x1c,0x1e,0x3c,0xa3,0x1d,0x59,0x02,0x66,0xe4,0x59,0x8d,0x1d,0x3c,0x41,0x5f,0x57,
	0x2a,0x84,0x88,0x83,0x0b,0x60,0xf7,0xe7,0x44,0xed,0x92,0x35,0xeb,0x0b,0x1b,0xa9,
	0x32,0x83,0xb3,0x15,0xc0,0x35,0x18,0x03,0xbb,0xee,0x60,0xc3,0x95,0x05,0x6b,0x8a,
	0x12,0x01,0xe0,0x6e,0xd7,0x9e,0x29,0x14,0xc1,0x1a,0x61,0xd7,0xb1,0xaa,0x78,0x18,
	0x46,0x46,0x8d,0x02,0x48,0x9d,0xba,0x69,0x02,0x32,0x42,0x66,0xde,0x84,0x03,0xb3,
	0xab,0x15,0x7a,0x09,0xf1,0xf7,0x84,0xd5,0x87,0xaf,0x61,0x83,0x1c,0x99,0x8c,0x15,
	0x1b,0xcc,0x21,0xbb,0x74,0xc2,0xb2,0x31,0x4b,0x20,0x00,0x00,0x0a,0x91,0x11,0x83,
	0xf6,0x00,0x00,0x00,0x00,0x10,0x05,0x00,0x00,0x00,0x00,0x00,0x0f,0x42,0x40,0x20,
	0x00,0x00,0x8a,0xe1,0x31,0x6b,0x76,0x65,0x55,0xb3,0x71,0x01,0x02,0x5d,0xf9,0x14,
	0xa0,0xd1,0x46,0x69,0x9a,0x2a,0x97,0xf7,0xb3,0x83,0xf0,0x30,0x73,0x48,0x5e,0x7b,
	0x3e,0x6c,0x45,0xd3,0xf1,0x51,0xf8,0xbc,0x4b,0xd7,0xae,0x02,0xd9,0x57,0x51,0x73,
	0x8f,0x0f,0xd0,0xdd,0x38,0x36,0x48,0xcd,0xda,0xea,0x01,0x24,0x16,0x3d,0x14,0x7e,
	0x5a,0x9e,0xac,0xcd,0x81,0xd1,0x96,0x30,0xd9,0xbc,0xa6,0xe4,0xe8,0x06,0x22,0x6e,
	0x46,0x11,0x1a,0x0b,0x59,0xca,0xaf,0x12,0x60,0x43,0xeb,0x5b,0xbf,0x28,0xc3,0x4f,
	0x3a,0x5e,0x33,0x2a,0x1f,0xc7,0xb2,0xb7,0x3c,0xf1,0x88,0x91,0x0f,0x00,0x00,0x6e,
	0x00,0x00,0x01,0x00,0x00,0x65,0x55,0xb3,0x71,0x01,0x00,0x00,0x06,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x03,0xe8,0x00,0x00,0x00,
	0x00,0x3b,0x02,0x33,0x80,0x20,0x00,0x00,0x8a,0xbd,0x6f,0x26,0xdf,0x65,0x55,0xb3,
	0x71,0x01,0x02,0x26,0x62,0x25,0x68,0x2d,0x27,0x06,0x9a,0x3b,0xaa,0x1a,0x43,0x93,
	0xac,0xb5,0x05,0x14,0x1c,0x09,0x22,0x8d,0xfb,0x54,0x43,0x73,0x3a,0x88,0xaa,0xa3,
	0x18,0xc8,0xd8,0x0d,0x36,0xd4,0x26,0x10,0xe9,0x82,0xa6,0x3c,0xb4,0x38,0x24,0xaf,
	0xdc,0x06,0xd5,0x3d,0xe3,0x7a,0xe8,0x39,0xdd,0xd4,0x5f,0xd8,0x92,0xf5,0x4b,0xe7,
	0x8d,0xf7,0xab,0x06,0x22,0x6e,0x46,0x11,0x1a,0x0b,0x59,0xca,0xaf,0x12,0x60,0x43,
	0xeb,0x5b,0xbf,0x28,0xc3,0x4f,0x3a,0x5e,0x33,0x2a,0x1f,0xc7,0xb2,0xb7,0x3c,0xf1,
	0x88,0x91,0x0f,0x00,0x00,0x6e,0x00,0x00,0x01,0x00,0x00,0x65,0x55,0xb3,0x71,0x01,
	0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,
	0x00,0x03,0xe8,0x00,0x00,0x00,0x00,0x3b,0x02,0x33,0x80,0x20,0x00,0x00,0x95,0xf6,
	0xd7,0x24,0x69,0x65,0x55,0xb3,0x79,0x01,0x01,0x42,0x62,0x2b,0xf0,0x0a,0x44,0xc3,
	0xe0,0x78,0x3c,0xa7,0x08,0x5a,0xa0,0xaa,0x9d,0xb2,0xdc,0x2e,0xa7,0x29,0x0a,0x39,
	0x3d,0x01,0x57,0xbf,0x34,0x23,0x0f,0xb9,0x19,0x33,0x6f,0xc2,0xfb,0x9f,0x25,0xac,
	0xc4,0xc9,0x47,0xb7,0x41,0x92,0xdb,0x2f,0xd5,0xf0,0x1f,0x24,0x32,0xdf,0x38,0x30,
	0x89,0x93,0xeb,0xc9,0xec,0xf1,0x09,0x51,0xbb,0x00,0x07,0x88,0xa0,0x00,0x0a,0x0a,
	0x69,0xa2,0x65,0x55,0xb3,0x79,0x02,0x66,0xe4,0x59,0x8d,0x1d,0x3c,0x41,0x5f,0x57,
	0x2a,0x84,0x88,0x83,0x0b,0x60,0xf7,0xe7,0x44,0xed,0x92,0x35,0xeb,0x0b,0x1b,0xa9,
	0x32,0x83,0xb3,0x15,0xc0,0x35,0x18,0x02,0x66,0xe4,0x4a,0x55,0x4e,0x49,0x4f,0x52,
	0x42,0x45,0x41,0x4d,0x2d,0x72,0x63,0x31,0x2d,0x31,0x2d,0x67,0x63,0x63,0x65,0x34,
	0x66,0x36,0x38,0x2d,0x6d,0x6f,0x64,0x64,0x65,0x64,0x00,0x00,
};

static void check_cannounce(const u8 *cannounce,
			    struct short_channel_id scid,
			    const struct node_id *n1,
			    const struct node_id *n2)
{
	secp256k1_ecdsa_signature sig;
	u8 *features;
	struct bitcoin_blkid chain_hash;
	struct short_channel_id actual_scid;
	struct node_id actual_n1, actual_n2;
	struct pubkey k;

	assert(fromwire_channel_announcement(cannounce, cannounce,
					     &sig, &sig, &sig, &sig,
					     &features, &chain_hash,
					     &actual_scid,
					     &actual_n1,
					     &actual_n2,
					     &k, &k));
	assert(short_channel_id_eq(actual_scid, scid));
	if (node_id_cmp(n1, n2) < 0) {
		assert(node_id_eq(&actual_n1, n1));
		assert(node_id_eq(&actual_n2, n2));
	} else {
		assert(node_id_eq(&actual_n1, n2));
		assert(node_id_eq(&actual_n2, n1));
	}
}

static void check_nannounce(const u8 *nannounce,
			    const struct node_id *n)
{
	secp256k1_ecdsa_signature sig;
	u8 *features, *addresses;
	u32 timestamp;
	u8 rgb_color[3], alias[32];
	struct node_id node_id;
	struct tlv_node_ann_tlvs *na_tlvs;
	assert(fromwire_node_announcement(nannounce, nannounce,
					  &sig, &features,
					  &timestamp,
					  &node_id,
					  rgb_color,
					  alias,
					  &addresses,
					  &na_tlvs));
	assert(node_id_eq(&node_id, n));
}

int main(int argc, char *argv[])
{
	int fd;
	char *gossfile;
	struct gossmap *map;
	struct node_id l1, l2, l3, l4;
	struct short_channel_id scid23, scid12, scid_local, scid_nonexisting;
	struct gossmap_chan *chan;
	struct gossmap_localmods *mods;
	struct amount_msat capacity;
	u32 timestamp, fee_base_msat, fee_proportional_millionths;
	u16 cltv_expiry_delta;
	u8 message_flags, channel_flags;
	struct amount_msat htlc_minimum_msat, htlc_maximum_msat;
	u8 *cann, *nann;

	common_setup(argv[0]);

	fd = tmpdir_mkstemp(tmpctx, "run-gossip_local.XXXXXX", &gossfile);
	assert(write_all(fd, canned_map, sizeof(canned_map)));

	map = gossmap_load(tmpctx, gossfile, NULL, NULL);
	assert(map);

	/* There is a public channel 2<->3 (103x1x0), and private
	 * 1<->2 (110x1x1). */
	assert(node_id_from_hexstr("0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518", 66, &l1));
	assert(node_id_from_hexstr("022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59", 66, &l2));
	assert(node_id_from_hexstr("035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d", 66, &l3));
	assert(gossmap_find_node(map, &l1));
	assert(gossmap_find_node(map, &l2));
	assert(gossmap_find_node(map, &l3));

	assert(short_channel_id_from_str("103x1x0", 7, &scid23));
	assert(short_channel_id_from_str("110x1x0", 7, &scid12));
	assert(gossmap_find_chan(map, &scid23));
	assert(!gossmap_chan_is_localmod(map, gossmap_find_chan(map, &scid23)));
	assert(gossmap_find_chan(map, &scid12));
	assert(!gossmap_chan_is_localmod(map, gossmap_find_chan(map, &scid12)));
	capacity = gossmap_chan_get_capacity(map, gossmap_find_chan(map, &scid23));
	assert(amount_msat_eq_sat(capacity, AMOUNT_SAT(1000000)));
	capacity = gossmap_chan_get_capacity(map, gossmap_find_chan(map, &scid12));
	assert(amount_msat_eq_sat(capacity, AMOUNT_SAT(1000000)));

	gossmap_chan_get_update_details(map, gossmap_find_chan(map, &scid23),
					0,
					&timestamp,
					&message_flags,
					&channel_flags,
					&cltv_expiry_delta,
					&fee_base_msat,
					&fee_proportional_millionths,
					&htlc_minimum_msat,
					&htlc_maximum_msat);
	assert(timestamp == 1700115301);
	assert(message_flags == 1);
	assert(channel_flags == 0);
	assert(cltv_expiry_delta == 6);
	assert(fee_base_msat == 20);
	assert(fee_proportional_millionths == 1000);
	assert(amount_msat_eq(htlc_minimum_msat, AMOUNT_MSAT(0)));
	assert(amount_msat_eq(htlc_maximum_msat, AMOUNT_MSAT(990000000)));

	gossmap_chan_get_update_details(map, gossmap_find_chan(map, &scid23),
					1,
					&timestamp,
					&message_flags,
					&channel_flags,
					&cltv_expiry_delta,
					&fee_base_msat,
					&fee_proportional_millionths,
					&htlc_minimum_msat,
					&htlc_maximum_msat);
	assert(timestamp == 1700115311);
	assert(message_flags == 1);
	assert(channel_flags == 1);
	assert(cltv_expiry_delta == 6);
	assert(fee_base_msat == 20);
	assert(fee_proportional_millionths == 1000);
	assert(amount_msat_eq(htlc_minimum_msat, AMOUNT_MSAT(0)));
	assert(amount_msat_eq(htlc_maximum_msat, AMOUNT_MSAT(990000000)));

	gossmap_chan_get_update_details(map, gossmap_find_chan(map, &scid12),
					0,
					&timestamp,
					&message_flags,
					&channel_flags,
					&cltv_expiry_delta,
					&fee_base_msat,
					&fee_proportional_millionths,
					&htlc_minimum_msat,
					&htlc_maximum_msat);
	assert(timestamp == 1700115313);
	assert(message_flags == 1);
	assert(channel_flags == 0);
	assert(cltv_expiry_delta == 6);
	assert(fee_base_msat == 20);
	assert(fee_proportional_millionths == 1000);
	assert(amount_msat_eq(htlc_minimum_msat, AMOUNT_MSAT(0)));
	assert(amount_msat_eq(htlc_maximum_msat, AMOUNT_MSAT(990000000)));

	gossmap_chan_get_update_details(map, gossmap_find_chan(map, &scid12),
					1,
					&timestamp,
					&message_flags,
					&channel_flags,
					&cltv_expiry_delta,
					&fee_base_msat,
					&fee_proportional_millionths,
					&htlc_minimum_msat,
					&htlc_maximum_msat);
	assert(timestamp == 1700115313);
	assert(message_flags == 1);
	assert(channel_flags == 1);
	assert(cltv_expiry_delta == 6);
	assert(fee_base_msat == 20);
	assert(fee_proportional_millionths == 1000);
	assert(amount_msat_eq(htlc_minimum_msat, AMOUNT_MSAT(0)));
	assert(amount_msat_eq(htlc_maximum_msat, AMOUNT_MSAT(990000000)));

	assert(tal_bytelen(gossmap_chan_get_features(tmpctx, map,
						     gossmap_find_chan(map, &scid12))) == 0);
	assert(tal_bytelen(gossmap_chan_get_features(tmpctx, map,
						     gossmap_find_chan(map, &scid23))) == 0);

	cann = gossmap_chan_get_announce(tmpctx, map,
					 gossmap_find_chan(map, &scid12));
	check_cannounce(cann, scid12, &l1, &l2);
	cann = gossmap_chan_get_announce(tmpctx, map,
					 gossmap_find_chan(map, &scid23));
	check_cannounce(cann, scid23, &l2, &l3);

	nann = gossmap_node_get_announce(tmpctx, map,
					 gossmap_find_node(map, &l1));
	assert(nann);
	nann = gossmap_node_get_announce(tmpctx, map,
					 gossmap_find_node(map, &l2));
	check_nannounce(nann, &l2);
	nann = gossmap_node_get_announce(tmpctx, map,
					 gossmap_find_node(map, &l3));
	check_nannounce(nann, &l3);

	/* Now, let's add a new channel l1 -> l4. */
	mods = gossmap_localmods_new(tmpctx);
	assert(node_id_from_hexstr("0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199", 66, &l4));
	assert(short_channel_id_from_str("111x1x1", 7, &scid_local));

	assert(gossmap_local_addchan(mods, &l1, &l4, scid_local, AMOUNT_MSAT(100000), NULL));

	/* Apply changes, check they work. */
	gossmap_apply_localmods(map, mods);
	assert(gossmap_find_node(map, &l4));
	chan = gossmap_find_chan(map, &scid_local);

	/* Exists, but no updates. */
	assert(!gossmap_chan_set(chan, 0));
	assert(!gossmap_chan_set(chan, 1));

	/* Capacity is correct */
	assert(amount_msat_eq(gossmap_chan_get_capacity(map, chan),
			      AMOUNT_MSAT(100000)));

	/* Remove, no longer can find. */
	gossmap_remove_localmods(map, mods);

	assert(!gossmap_find_chan(map, &scid_local));
	assert(!gossmap_find_node(map, &l4));

	/* Now update it both local, and an existing one. */
	gossmap_local_setchan(mods, scid_local,
			      AMOUNT_MSAT(1),
			      AMOUNT_MSAT(100000),
			      AMOUNT_MSAT(2), 3, 4, true, 0);

	/* Adding an existing channel is a noop. */
	assert(gossmap_local_addchan(mods, &l2, &l3, scid23, AMOUNT_MSAT(100000), NULL));

	gossmap_local_setchan(mods, scid23,
			      AMOUNT_MSAT(99),
			      AMOUNT_MSAT(100),
			      AMOUNT_MSAT(101), 102, 103, true, 0);

	/* We can "update" a channel which doesn't exist, and it's a noop */
	scid_nonexisting.u64 = 1;
	gossmap_local_setchan(mods, scid_nonexisting,
			      AMOUNT_MSAT(1),
			      AMOUNT_MSAT(100000),
			      AMOUNT_MSAT(2), 3, 4, false, 0);

	gossmap_apply_localmods(map, mods);
	chan = gossmap_find_chan(map, &scid_local);
	assert(gossmap_chan_set(chan, 0));
	assert(!gossmap_chan_set(chan, 1));

	assert(chan->half[0].enabled);
	assert(chan->half[0].htlc_min == u64_to_fp16(1, false));
	assert(chan->half[0].htlc_max == u64_to_fp16(100000, true));
	assert(chan->half[0].base_fee == 2);
	assert(chan->half[0].proportional_fee == 3);
	assert(chan->half[0].delay == 4);

	/* We can query update_details on locally-generated chans */
	gossmap_chan_get_update_details(map, chan,
					0,
					&timestamp,
					&message_flags,
					&channel_flags,
					&cltv_expiry_delta,
					&fee_base_msat,
					&fee_proportional_millionths,
					&htlc_minimum_msat,
					&htlc_maximum_msat);
	assert(timestamp == 0);
	assert(message_flags == ROUTING_OPT_HTLC_MAX_MSAT);
	assert(channel_flags == 0);
	assert(cltv_expiry_delta == 4);
	assert(fee_base_msat == 2);
	assert(fee_proportional_millionths == 3);
	assert(amount_msat_eq(htlc_minimum_msat, AMOUNT_MSAT(1)));
	assert(amount_msat_eq(htlc_maximum_msat, AMOUNT_MSAT(100000)));

	assert(!gossmap_find_chan(map, &scid_nonexisting));

	chan = gossmap_find_chan(map, &scid23);
	assert(chan->half[0].enabled);
	assert(chan->half[0].htlc_min == u64_to_fp16(99, false));
	assert(chan->half[0].htlc_max == u64_to_fp16(100, true));
	assert(chan->half[0].base_fee == 101);
	assert(chan->half[0].proportional_fee == 102);
	assert(chan->half[0].delay == 103);

	/* We can query update_details on locally-modified chans */
	gossmap_chan_get_update_details(map, chan,
					0,
					&timestamp,
					&message_flags,
					&channel_flags,
					&cltv_expiry_delta,
					&fee_base_msat,
					&fee_proportional_millionths,
					&htlc_minimum_msat,
					&htlc_maximum_msat);
	assert(timestamp == 1700115301);
	assert(message_flags == ROUTING_OPT_HTLC_MAX_MSAT);
	assert(channel_flags == 0);
	assert(cltv_expiry_delta == 103);
	assert(fee_base_msat == 101);
	assert(fee_proportional_millionths == 102);
	assert(amount_msat_eq(htlc_minimum_msat, AMOUNT_MSAT(99)));
	assert(amount_msat_eq(htlc_maximum_msat, AMOUNT_MSAT(100)));

	/* Cleanup leaves everything previous intact */
	gossmap_remove_localmods(map, mods);

	assert(!gossmap_find_node(map, &l4));
	assert(!gossmap_find_chan(map, &scid_local));
	assert(gossmap_find_node(map, &l1));
	assert(gossmap_find_node(map, &l2));
	assert(gossmap_find_node(map, &l3));
	assert(gossmap_find_chan(map, &scid23));
	assert(gossmap_find_chan(map, &scid12));

	chan = gossmap_find_chan(map, &scid23);
	assert(chan->half[0].enabled);
	assert(chan->half[0].htlc_min == u64_to_fp16(0, false));
	assert(chan->half[0].htlc_max == u64_to_fp16(990380000, true));
	assert(chan->half[0].base_fee == 20);
	assert(chan->half[0].proportional_fee == 1000);
	assert(chan->half[0].delay == 6);

	/* Now we can refresh. */
	assert(write(fd, "", 1) == 1);
	gossmap_refresh(map);
	common_shutdown();
}
