docs: def db_chainstate_append(cls, cur, **fields):
          """
          Insert a row into the chain state.
          Meant to be executed as part of a transaction.
  
          Return True on success
          Raise an exception if the fields are invalid
          Abort on db error.
          """
          missing = []
          extra = []
          for reqfield in CHAINSTATE_FIELDS:
              if reqfield not in fields:
                  missing.append(reqfield)
  
          for fieldname in fields:
              if fieldname not in CHAINSTATE_FIELDS:
                  extra.append(fieldname)
  
          if len(missing) > 0 or len(extra) > 0:
              raise ValueError("Invalid fields: missing: {}, extra: {}".format(','.join(missing), ','.join(extra)))
  
          query = 'INSERT INTO chainstate ({}) VALUES ({});'.format(
                  ','.join( CHAINSTATE_FIELDS ),
                  ','.join( ['?'] * len(CHAINSTATE_FIELDS)))
  
          args = tuple([fields[fieldname] for fieldname in CHAINSTATE_FIELDS])
          cls.db_query_execute(cur, query, args)
          return True