def strip_unneeded(bkts, sufficient_funds):
    """Remove buckets that are unnecessary in achieving the spend amount"""
    if sufficient_funds([], bucket_value_sum=0):
        return []
    bkts = sorted(bkts, key=lambda bkt: bkt.value, reverse=True)
    bucket_value_sum = 0
    for i in range(len(bkts)):
        bucket_value_sum += bkts[i].value
        if sufficient_funds(bkts[:i + 1], bucket_value_sum=bucket_value_sum):
            return bkts[:i + 1]
    raise Exception('keeping all buckets is still not enough')
